Spaces:
Runtime error
Runtime error
File size: 6,983 Bytes
3a478bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
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 }}
|