Skip to content

feat: Switch to the custom chat bot feature and improve the suggestions #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@ inputs:
description: Issue title.
required: false
default: ''
bot_behavior_setup:
required: false
description: Sets the behavior of the bot who should know where it is being deployed.
default: >
You are an Engineer tasked to solve Github issues. You are professional, knowledgeable, helpful and always
friendly. You try to understand the given issue (bug report, feature request) and provide several ideas which
the customer can try until an Espressif Engineer handles the issue.
bot_query_prefix:
description: The issue message can be prefixed with this string before evaluation.
description: Instructions to the bot how to respond to issues.
required: false
default: >
The customer opened a Github issue with the following information. Please help and I'll post your answer there.
Write a detailed reaction to the Github issue. Please warn the customer if you suggest to try something which
can do irreversible damage (e.g. writing eFuses, enabling security features). Check if the bug report have
enough information for reproducing the issue. Feature requests should give detailed justification of the request
including why existing solutions are insufficient. Ask the customer to provide more information if needed.
Try to provide links to documentation, troubleshooting guides or other Espressif documents if you used
knowledge from them. If possible then link related and similar issues. Suggest to open a new Github issue only
in the case the customer is opened it for the wrong Github repository.
github_comments:
description: If set to false, the bot will not post a reply to the issue.
default: true
Expand Down Expand Up @@ -69,13 +82,19 @@ runs:
run: |
source venv/bin/activate
cat << 'EOF' > input.txt
The issue posted in the Github repository: ${{ inputs.github_repository }}
Github issue title: ${{ inputs.title }}
Github issue text: ${{ inputs.in_msg }}
EOF
cat << 'EOF' > bot_instructions.txt
${{ inputs.bot_query_prefix }}
${{ inputs.title }}
${{ inputs.in_msg }}
EOF
cat << 'EOF' > bot_behavior.txt
${{ inputs.bot_behavior_setup }}
EOF
printf "%s\n" "${{ inputs.prefix_out_msg }}" > output.txt
printf "\n---\n" >> output.txt
python bot_action/bot_action.py input.txt >> output.txt || exit 1
python bot_action/bot_action.py --behavior bot_behavior.txt --instructions bot_instructions.txt input.txt >> output.txt || exit 1

- name: Archive artifacts
uses: actions/upload-artifact@v4
Expand All @@ -85,6 +104,8 @@ runs:
path: |
output.txt
input.txt
bot_instructions.txt
bot_behavior.txt

- name: Comment
if: ${{ inputs.github_comments == 'true' }}
Expand Down
39 changes: 32 additions & 7 deletions bot_action/bot_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@
import requests


def get_suggestion(issue_body: str) -> str:
payload = json.dumps({'integration_id': os.environ['BOT_INTEGRATION_ID'], 'query': issue_body})
def get_suggestion(query: str, instructions: str, behavior: str) -> str:
payload = json.dumps(
{
'integration_id': os.environ['BOT_INTEGRATION_ID'],
'messages': [
{'role': 'system', 'content': behavior},
{'role': 'context'},
{'role': 'user', 'content': instructions},
{'role': 'query', 'content': query},
{
'role': 'user',
'content': 'Output your response in Github markdown. Sign it as "Espressif Bot".',
},
],
}
)

endpoint = os.environ['BOT_API_ENDPOINT']

if endpoint.endswith('chat/'):
# Switch to "custom chat" feature if the URL is for simple chat
endpoint = f'{endpoint}custom/'

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

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

def main():
parser = argparse.ArgumentParser()
parser.add_argument('input_file', type=str, default=None)
parser.add_argument('query_file', type=str, default=None)
parser.add_argument('--instructions', type=str, required=True)
parser.add_argument('--behavior', type=str, required=True)
args = parser.parse_args()

if args.input_file:
with open(args.input_file, 'r', encoding='utf-8') as f:
print(get_suggestion(f.read()))
with (
open(args.query_file, 'r', encoding='utf-8') as q,
open(args.instructions, 'r', encoding='utf-8') as inst,
open(args.behavior, 'r', encoding='utf-8') as behav,
):
print(get_suggestion(q.read(), inst.read(), behav.read()))


if __name__ == '__main__':
Expand Down
Loading