Skip to content

Commit 0310bc8

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

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
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, knowledeable, 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 unsufficient. Ask the customer to provide more information if this looks
29+
relevant. 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+
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: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@
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+
}
24+
)
1525

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

3141
def main():
3242
parser = argparse.ArgumentParser()
33-
parser.add_argument('input_file', type=str, default=None)
43+
parser.add_argument('query_file', type=str, required=True)
44+
parser.add_argument('--instructions', type=str, required=True)
45+
parser.add_argument('--behavior', type=str, required=True)
3446
args = parser.parse_args()
3547

36-
if args.input_file:
37-
with open(args.input_file, 'r', encoding='utf-8') as f:
38-
print(get_suggestion(f.read()))
48+
with (
49+
open(args.query_file, 'r', encoding='utf-8') as q,
50+
open(args.instructions, 'r', encoding='utf-8') as inst,
51+
open(args.behavior, 'r', encoding='utf-8') as behav,
52+
):
53+
print(get_suggestion(q.read(), inst.read(), behav.read()))
3954

4055

4156
if __name__ == '__main__':

0 commit comments

Comments
 (0)