Skip to content

Commit

Permalink
Finalize automation of query testing
Browse files Browse the repository at this point in the history
  • Loading branch information
markbotterill committed May 24, 2024
1 parent ebecb36 commit cd83661
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/send_performance_demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Run Performance Test
# NB This only works on the default (prod) branch
on:
workflow_dispatch:
# schedule:
# - cron: '0 9 1-7 * 5'

jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: production
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$PROD_SSH_KEY" > ~/.ssh/hubgpt_prod.key
chmod 600 ~/.ssh/hubgpt_prod.key
cat >>~/.ssh/config <<END
Host prod
HostName $PROD_EC2_HOST_IP
User $PROD_EC2_USER
IdentityFile ~/.ssh/hubgpt_prod.key
StrictHostKeyChecking no
END
env:
PROD_EC2_USER: ${{ secrets.PROD_EC2_USER }}
PROD_SSH_KEY: ${{ secrets.PROD_SSH_KEY }}
PROD_EC2_HOST_IP: ${{ secrets.PROD_EC2_HOST_IP }}

- name: Trigger metric dispatch
run: |
ssh prod << 'EOF'
cd danswer
make send-slack-metrics
EOF
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ secrets.yaml
deployment/data/nginx/app.conf
/deployment/data/nginx/app.conf
.vscode/launch.json
*.csv
48 changes: 48 additions & 0 deletions backend/scripts/hubgpt_eval_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,31 @@
import datetime
import json
import os
<<<<<<< Updated upstream

import pandas as pd
import requests
=======
import pandas as pd
import requests

>>>>>>> Stashed changes
from slack_sdk import WebClient


def create_new_chat_session(danswer_url: str, api_key: str | None) -> int:
headers = {"Authorization": f"Bearer {api_key}"} if api_key else None
session_endpoint = danswer_url + "/api/chat/create-chat-session"

<<<<<<< Updated upstream
response = requests.post(session_endpoint, headers=headers, json={"persona_id": 0})
=======
response = requests.post(
session_endpoint,
headers=headers,
json={"persona_id": 0}
)
>>>>>>> Stashed changes
response.raise_for_status()

new_session_id = response.json()["chat_session_id"]
Expand Down Expand Up @@ -57,8 +71,12 @@ def process_question(danswer_url: str, question: str, api_key: str | None) -> No
if new_token:
response_str += new_token
return response_str
<<<<<<< Updated upstream


=======

>>>>>>> Stashed changes
def upload_to_slack(filename, channel_id):
slack_client = WebClient(token=os.environ.get("SLACK_BOT_TOKEN"))
size = os.stat(filename).st_size
Expand All @@ -68,6 +86,7 @@ def upload_to_slack(filename, channel_id):
post_response = requests.post(url=upload_url, data=open(filename, "rb"))
if post_response.status_code == 200:
upload_response = slack_client.files_completeUploadExternal(
<<<<<<< Updated upstream
files=[{"id": file_id, "title": "Monthly Performance Evaluation"}],
channel_id=channel_id,
)
Expand All @@ -94,6 +113,35 @@ def upload_to_slack(filename, channel_id):

# Record + send info
data.to_csv("hubgpt_eval_automated.csv", index=False)
=======
files=[{"id": file_id, "title": "Monthly Performance Evaluation"}], channel_id=channel_id
)
return upload_response.status_code

if __name__ == "__main__":

data = pd.read_csv("hubgpt_eval_automated.csv")

queries_list = data.Query.tolist()

responses = []

for num, query in enumerate(queries_list):
print(f"Query {num+1}/{len(queries_list)}: {query}")
# response = process_question(danswer_url="https://hubgpt-staging.idinsight.io",
# question=query,
# api_key=None)
response = 1
print(response)
responses.append(response)
print("\n ------------------- \n")

today_str = str(datetime.date.today())
data[today_str] = responses

# Record + send info
data.to_csv("hubgpt_eval_automated.csv", index = False)
>>>>>>> Stashed changes
print("Complete")
CHANNEL_ID = os.environ.get("METRICS_CHANNEL_ID")
upload_to_slack("hubgpt_eval_automated.csv", CHANNEL_ID)

0 comments on commit cd83661

Please sign in to comment.