Skip to content

Commit 5fdc9fa

Browse files
committed
feat: Switch to the custom chat bot feature and improve the suggestions
1 parent 98afb25 commit 5fdc9fa

File tree

2 files changed

+58
-12
lines changed

2 files changed

+58
-12
lines changed

action.yml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,24 @@ inputs:
1111
description: Issue title.
1212
required: false
1313
default: ''
14+
bot_behavior_setup:
15+
required: false
16+
description: Sets the behavior of the bot who should know where it is being deployed.
17+
default: >
18+
You are an Engineer tasked to solve Github issues. You are professional, knowledgeable, helpful and always
19+
friendly. You try to understand the given issue (bug report, feature request) and provide several ideas which
20+
the customer can try until an Espressif Engineer handles the issue.
1421
bot_query_prefix:
15-
description: The issue message can be prefixed with this string before evaluation.
22+
description: Instructions to the bot how to respond to issues.
1623
required: false
1724
default: >
18-
The customer opened a Github issue with the following information. Please help and I'll post your answer there.
25+
Write a detailed reaction to the Github issue. Please warn the customer if you suggest to try something which
26+
can do irreversible damage (e.g. writing eFuses, enabling security features). Check if the bug report have
27+
enough information for reproducing the issue. Feature requests should give detailed justification of the request
28+
including why existing solutions are insufficient. Ask the customer to provide more information if needed.
29+
Try to provide links to documentation, troubleshooting guides or other Espressif documents if you used
30+
knowledge from them. If possible then link related and similar issues. Suggest to open a new Github issue only
31+
in the case the customer is opened it for the wrong Github repository.
1932
github_comments:
2033
description: If set to false, the bot will not post a reply to the issue.
2134
default: true
@@ -69,13 +82,19 @@ runs:
6982
run: |
7083
source venv/bin/activate
7184
cat << 'EOF' > input.txt
85+
The issue posted in the Github repository: ${{ inputs.github_repository }}
86+
Github issue title: ${{ inputs.title }}
87+
Github issue text: ${{ inputs.in_msg }}
88+
EOF
89+
cat << 'EOF' > bot_instructions.txt
7290
${{ inputs.bot_query_prefix }}
73-
${{ inputs.title }}
74-
${{ inputs.in_msg }}
91+
EOF
92+
cat << 'EOF' > bot_behavior.txt
93+
${{ inputs.bot_behavior_setup }}
7594
EOF
7695
printf "%s\n" "${{ inputs.prefix_out_msg }}" > output.txt
7796
printf "\n---\n" >> output.txt
78-
python bot_action/bot_action.py input.txt >> output.txt || exit 1
97+
python bot_action/bot_action.py --behavior bot_behavior.txt --instructions bot_instructions.txt input.txt >> output.txt || exit 1
7998
8099
- name: Archive artifacts
81100
uses: actions/upload-artifact@v4
@@ -85,6 +104,8 @@ runs:
85104
path: |
86105
output.txt
87106
input.txt
107+
bot_instructions.txt
108+
bot_behavior.txt
88109
89110
- name: Comment
90111
if: ${{ inputs.github_comments == 'true' }}

bot_action/bot_action.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,31 @@
1010
import requests
1111

1212

13-
def get_suggestion(issue_body: str) -> str:
14-
payload = json.dumps({'integration_id': os.environ['BOT_INTEGRATION_ID'], 'query': issue_body})
13+
def get_suggestion(query: str, instructions: str, behavior: str) -> str:
14+
payload = json.dumps(
15+
{
16+
'integration_id': os.environ['BOT_INTEGRATION_ID'],
17+
'messages': [
18+
{'role': 'system', 'content': behavior},
19+
{'role': 'context'},
20+
{'role': 'user', 'content': instructions},
21+
{'role': 'query', 'content': query},
22+
{
23+
'role': 'user',
24+
'content': 'Output your response in Github markdown. Do not use e-mail template and do not sign the output.',
25+
},
26+
],
27+
}
28+
)
29+
30+
endpoint = os.environ['BOT_API_ENDPOINT']
31+
32+
if endpoint.endswith('chat/'):
33+
# Switch to "custom chat" feature if the URL is for simple chat
34+
endpoint = f'{endpoint}custom/'
1535

1636
headers = {'content-type': 'application/json', 'X-API-KEY': os.environ['BOT_API_KEY']}
17-
r = requests.post(os.environ['BOT_API_ENDPOINT'], data=payload, headers=headers)
37+
r = requests.post(endpoint, data=payload, headers=headers)
1838

1939
r.raise_for_status()
2040
j = r.json()
@@ -30,12 +50,17 @@ def get_suggestion(issue_body: str) -> str:
3050

3151
def main():
3252
parser = argparse.ArgumentParser()
33-
parser.add_argument('input_file', type=str, default=None)
53+
parser.add_argument('query_file', type=str, default=None)
54+
parser.add_argument('--instructions', type=str, required=True)
55+
parser.add_argument('--behavior', type=str, required=True)
3456
args = parser.parse_args()
3557

36-
if args.input_file:
37-
with open(args.input_file, 'r', encoding='utf-8') as f:
38-
print(get_suggestion(f.read()))
58+
with (
59+
open(args.query_file, 'r', encoding='utf-8') as q,
60+
open(args.instructions, 'r', encoding='utf-8') as inst,
61+
open(args.behavior, 'r', encoding='utf-8') as behav,
62+
):
63+
print(get_suggestion(q.read(), inst.read(), behav.read()))
3964

4065

4166
if __name__ == '__main__':

0 commit comments

Comments
 (0)