Skip to content

Commit 2ed66c1

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

File tree

2 files changed

+53
-11
lines changed

2 files changed

+53
-11
lines changed

action.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,25 @@ 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 notify 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. Provide the output in Github Markdown
32+
format.
1933
github_comments:
2034
description: If set to false, the bot will not post a reply to the issue.
2135
default: true
@@ -69,13 +83,19 @@ runs:
6983
run: |
7084
source venv/bin/activate
7185
cat << 'EOF' > input.txt
86+
The issue posted in the Github repository: ${{ inputs.github_repository }}
87+
Github issue title: ${{ inputs.title }}
88+
Github issue text: ${{ inputs.in_msg }}
89+
EOF
90+
cat << 'EOF' > bot_instructions.txt
7291
${{ inputs.bot_query_prefix }}
73-
${{ inputs.title }}
74-
${{ inputs.in_msg }}
92+
EOF
93+
cat << 'EOF' > bot_behavior.txt
94+
${{ inputs.bot_behavior_setup }}
7595
EOF
7696
printf "%s\n" "${{ inputs.prefix_out_msg }}" > output.txt
7797
printf "\n---\n" >> output.txt
78-
python bot_action/bot_action.py input.txt >> output.txt || exit 1
98+
python bot_action/bot_action.py --behavior bot_behavior.txt --instructions bot_instructions.txt input.txt >> output.txt || exit 1
7999
80100
- name: Archive artifacts
81101
uses: actions/upload-artifact@v4
@@ -85,6 +105,8 @@ runs:
85105
path: |
86106
output.txt
87107
input.txt
108+
bot_instructions.txt
109+
bot_behavior.txt
88110
89111
- name: Comment
90112
if: ${{ inputs.github_comments == 'true' }}

bot_action/bot_action.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@
88
import json
99
import os
1010
import requests
11+
import sys
1112

13+
from pprint import pprint
1214

13-
def get_suggestion(issue_body: str) -> str:
14-
payload = json.dumps({'integration_id': os.environ['BOT_INTEGRATION_ID'], 'query': issue_body})
15+
16+
def get_suggestion(query: str, instructions: str, behavior: str) -> str:
17+
payload = json.dumps(
18+
{
19+
'integration_id': os.environ['BOT_INTEGRATION_ID'],
20+
'messages': [
21+
{'role': 'system', 'content': behavior},
22+
{'role': 'context'},
23+
{'role': 'user', 'content': instructions},
24+
{'role': 'query', 'content': query},
25+
],
26+
}
27+
)
28+
29+
pprint(payload, stream=sys.stderr)
1530

1631
headers = {'content-type': 'application/json', 'X-API-KEY': os.environ['BOT_API_KEY']}
1732
r = requests.post(os.environ['BOT_API_ENDPOINT'], data=payload, headers=headers)
@@ -30,12 +45,17 @@ def get_suggestion(issue_body: str) -> str:
3045

3146
def main():
3247
parser = argparse.ArgumentParser()
33-
parser.add_argument('input_file', type=str, default=None)
48+
parser.add_argument('query_file', type=str, default=None)
49+
parser.add_argument('--instructions', type=str, required=True)
50+
parser.add_argument('--behavior', type=str, required=True)
3451
args = parser.parse_args()
3552

36-
if args.input_file:
37-
with open(args.input_file, 'r', encoding='utf-8') as f:
38-
print(get_suggestion(f.read()))
53+
with (
54+
open(args.query_file, 'r', encoding='utf-8') as q,
55+
open(args.instructions, 'r', encoding='utf-8') as inst,
56+
open(args.behavior, 'r', encoding='utf-8') as behav,
57+
):
58+
print(get_suggestion(q.read(), inst.read(), behav.read()))
3959

4060

4161
if __name__ == '__main__':

0 commit comments

Comments
 (0)