name: Issue Management on: issues: types: [opened, edited] issue_comment: types: [created] jobs: check_issue_template: runs-on: ubuntu-latest steps: - name: Check Issue Template uses: actions/github-script@v6 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | const issue = context.payload.issue; const requiredSections = [ '**Bug Description**', '**Steps to Reproduce**', '**Desktop Details:**', ]; const body = issue.body; const missingFields = requiredSections.filter(section => !body.includes(section)); if (missingFields.length > 0) { const message = `Thank you for your issue report. However, it appears that your issue description is missing the following required sections:\n${missingFields.map(field => `- ${field}`).join('\n')}\n\nPlease edit your issue to include all required information using our issue template. This helps us address your concern more effectively.\nIf you need assistance with the template or have any questions, please join our Discord server for support.\n\nThis issue will be closed automatically. Feel free to reopen it once you've updated it with the required information.`; await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issue.number, body: message }); await github.rest.issues.update({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issue.number, state: 'closed' }); } auto_reply: runs-on: ubuntu-latest needs: check_issue_template steps: - name: Generate Response and Post Comment uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const issue = context.payload.issue; const comment = context.payload.comment; const repo = context.repo.repo; const issueNumber = issue.number; const issueBody = issue.body; const groqApiKey = process.env.GROQ_API_KEY; const issueAuthor = issue.user.login; const commentAuthor = comment ? comment.user.login : null; const systemPrompt = `You are an assistant for a GitHub repository called Applio (https://github.com/IAHispano/Applio), a Python project focused on voice cloning. Your job is to assist users with any issues or bugs they report, providing clear, helpful and short guidance. You can troubleshoot various technical problems and offer solutions, code snippets, or documentation references as needed. Be concise, efficient, and to the point when responding to the following GitHub issue. Try to answer in a paragraph whenever possible and if you are not sure of the answer ask the user for more details. If relevant, refer users to the official documentation at https://docs.applio.org, just share that link, do not add any extension to it. Issue content: ${issueBody}`; async function getAIResponse(prompt) { const response = await fetch('https://api.groq.com/openai/v1/chat/completions', { method: 'POST', headers: { 'Authorization': `Bearer ${groqApiKey}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ messages: [ { role: 'system', content: prompt }, { role: 'user', content: issueBody }, ], model: 'llama-3.1-70b-versatile', temperature: 0.6, }), }); if (!response.ok) { throw new Error('Failed to fetch response from LLM'); } const data = await response.json(); return data.choices[0].message.content; } const comments = await github.rest.issues.listComments({ owner: context.repo.owner, repo: repo, issue_number: issueNumber, }); const discordRecommendation = 'consider joining our support community on [Discord](https://discord.gg/iahispano)'; const hasDiscordRecommendation = comments.data.some(comment => comment.body.includes(discordRecommendation)); if (hasDiscordRecommendation) { console.log("Discord recommendation already posted. No further responses."); return; } if (comment) { if (commentAuthor === issueAuthor) { const followUpPrompt = `The user has sent another comment. Try to get him to provide more information about his error and try to help him as much as possible precisely and concisely, whenever possible in a paragraph.`; const aiResponse = await getAIResponse(followUpPrompt); const commentMessage = `${aiResponse}\n\nIf you're looking for faster assistance, consider joining our support community on [Discord](https://discord.gg/iahispano), or please wait for a staff member to assist.`; await github.rest.issues.createComment({ owner: context.repo.owner, repo: repo, issue_number: issueNumber, body: commentMessage, }); } } else { const initialResponse = await getAIResponse(systemPrompt); await github.rest.issues.createComment({ owner: context.repo.owner, repo: repo, issue_number: issueNumber, body: initialResponse, }); const followUpMessage = ` If this issue persists or you need further assistance, please visit our support community at [discord.gg/iahispano](https://discord.gg/iahispano). Our community is available to help with any additional questions or concerns. `; const hasFollowUpComment = comments.data.some(comment => comment.body.includes('If this issue persists or you need further assistance') ); if (!hasFollowUpComment) { setTimeout(async () => { await github.rest.issues.createComment({ owner: context.repo.owner, repo: repo, issue_number: issueNumber, body: followUpMessage, }); }, 72 * 60 * 60 * 1000); } } env: GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}