diff --git a/.github/prompts/issue-assistant.md b/.github/prompts/issue-assistant.md index 93a969a..99d8275 100644 --- a/.github/prompts/issue-assistant.md +++ b/.github/prompts/issue-assistant.md @@ -12,23 +12,54 @@ Your role is to provide friendly, informative responses to GitHub issues. - Uses Python standard library only (no external dependencies) - Supports Python 2.7 and 3.x -## Issue Classification +## Response Format -**IMPORTANT**: You must classify each issue into ONE of these categories: +**IMPORTANT**: You must return your response as a JSON object with the following structure: + +```json +{ + "classification": "bug|feature|question", + "response": "Your detailed response here..." +} +``` + +### Classification Categories + +Classify each issue into ONE of these categories: - **bug**: Software defects, errors, crashes, or unexpected behavior - **feature**: New feature requests, enhancements, or improvements - **question**: Questions about usage, configuration, documentation, or general inquiries -Return your classification at the START of your response using ONE of the following formats: -``` +### Response Content Guidelines + +When writing the "response" field: +- **Respond in the same language as the issue title and content** (detect and match the user's language - Chinese, English, or other languages) +- Keep responses concise but helpful +- Use proper markdown formatting for code blocks and inline code +- Reference files and documentation using markdown links + +### File References + +When referencing files in your response, use these formats: +1. **Documentation files**: Use markdown links that convert `.md` to `.html` URLs + - Format: `[doc/providers/aliesa.md](https://ddns.newfuture.cc/doc/providers/aliesa.html)` + - Format: `[doc/config/cli.md](https://ddns.newfuture.cc/doc/config/cli.html)` +2. **Code files**: Use markdown links to GitHub repository + - Format: `[ddns/provider/_base.py](https://github.com/NewFuture/DDNS/blob/master/ddns/provider/_base.py)` + - Format: `[tests/test_cache.py](https://github.com/NewFuture/DDNS/blob/master/tests/test_cache.py)` +3. **Code blocks**: Use proper markdown code fences with language identifiers: + ````markdown + ```python + # Your code here + ``` + ```` +4. **Inline code**: Use backticks for commands and code snippets: `` `ddns --debug` `` or `` `variable_name` `` ## Response Guidelines When responding to issues: -1. Start with the classification tag in the exact format above -2. Be welcoming and professional -3. **Respond in the same language as the issue title and content** (detect and match the user's language - Chinese, English, or other languages) -4. Keep responses concise but helpful +1. Be welcoming and professional +2. Be specific and actionable in your guidance ### Response Strategy by Classification diff --git a/.github/workflows/auto-reply-issue.yml b/.github/workflows/auto-reply-issue.yml index 7820dd1..8508d74 100644 --- a/.github/workflows/auto-reply-issue.yml +++ b/.github/workflows/auto-reply-issue.yml @@ -134,6 +134,7 @@ jobs: ], temperature: 1, max_completion_tokens: 2000, + response_format: { type: "json_object" } }) }); @@ -157,21 +158,42 @@ jobs: return; } - const aiResponse = data.choices[0].message.content.trim(); + let aiResponse = data.choices[0].message.content.trim(); - // Extract classification from response - const classificationMatch = aiResponse.match(/\[CLASSIFICATION:\s*(bug|feature|question)\]/i); + // Try to parse JSON response let classification = null; let commentBody = aiResponse; - if (classificationMatch) { - classification = classificationMatch[1].toLowerCase(); - // Remove classification tag from the comment body - commentBody = aiResponse.replace(/\[CLASSIFICATION:\s*(bug|feature|question)\]\s*/i, '').trim(); - console.log(`Issue classified as: ${classification}`); + try { + // Remove markdown code fences if present + let jsonContent = aiResponse; + if (aiResponse.startsWith('```json') || aiResponse.startsWith('```')) { + jsonContent = aiResponse.replace(/^```(?:json)?\s*\n/, '').replace(/\n```\s*$/, '').trim(); + } + + const parsedResponse = JSON.parse(jsonContent); + + if (parsedResponse.classification && parsedResponse.response) { + classification = parsedResponse.classification.toLowerCase(); + commentBody = parsedResponse.response; + console.log(`Issue classified as: ${classification} (JSON format)`); + } else { + console.log('JSON response missing required fields, falling back to text format'); + } + } catch (jsonError) { + console.log(`Failed to parse JSON response: ${jsonError.message}`); + console.log('Falling back to legacy text format extraction'); + + // Fallback: Try legacy format with classification tag + const classificationMatch = aiResponse.match(/\[CLASSIFICATION:\s*(bug|feature|question)\]/i); + if (classificationMatch) { + classification = classificationMatch[1].toLowerCase(); + commentBody = aiResponse.replace(/\[CLASSIFICATION:\s*(bug|feature|question)\]\s*/i, '').trim(); + console.log(`Issue classified as: ${classification} (legacy format)`); + } } - // Post the response as a comment (without classification tag) + // Post the response as a comment await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo,