Skip to content

Commit

Permalink
Merge branch 'master' into feature/add-ruff-github-workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Song Luar <[email protected]>
  • Loading branch information
luarss authored Jul 9, 2024
2 parents ef4d19b + 8ec4b28 commit 9a9e6d2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
4 changes: 2 additions & 2 deletions evaluation/human_evaluation/.env_example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Environment configuration example

# API endpoint for the chat application
# (eg. http://your-api-endpoint.com/chatApp)
# (eg. http://your-api-endpoint.com/)
CHAT_ENDPOINT=

# Google Sheets IDs (Note: This will be filled by setup.py script if you choose to create a new sheet)
Expand All @@ -17,4 +17,4 @@ RANGE_ANSWERS=
GOOGLE_CREDENTIALS_JSON=

# Google Form ID (Note: This will be filled by setup.py script if you choose to create a new form.)
GOOGLE_FORM_ID=
GOOGLE_FORM_ID=
21 changes: 19 additions & 2 deletions evaluation/human_evaluation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

from utils.sheets import read_questions_and_answers, write_responses, find_new_questions
from utils.api import get_responses
from utils.api import fetch_endpoints, get_responses
from utils.utils import (
parse_custom_input,
selected_questions,
Expand All @@ -18,13 +18,30 @@ def main() -> None:
google_sheet_id = os.getenv("GOOGLE_SHEET_ID")
google_form_id = os.getenv("GOOGLE_FORM_ID")

if not google_sheet_id:
st.error("GOOGLE_SHEET_ID is not set in the environment variables.")
return

if not google_form_id:
st.error("GOOGLE_FORM_ID is not set in the environment variables.")
return

st.title("OR Assistant: Populate Human Evaluation Form")

st.write(f"""
Add questions to be tested by OR Assistant in this Google Sheet:
[Google Sheet Link](https://docs.google.com/spreadsheets/d/{google_sheet_id}/edit)
""")

endpoints = fetch_endpoints()

selected_endpoint = st.selectbox(
"Select preferred architecture",
options=endpoints,
index=0,
format_func=lambda x: x.split('/')[-1].capitalize()
)

options = ["", "All", "All New Questions", "Custom"]
selected_option: str = st.selectbox(
"Choose which set of questions you want to be generated by the model:", options
Expand Down Expand Up @@ -99,7 +116,7 @@ def main() -> None:

questions_to_process = selected_questions(questions, parsed_values)
responses = get_responses(
questions_to_process, progress, status_text, current_question_text
questions_to_process, progress, status_text, current_question_text, selected_endpoint
)
updated_cells = write_responses(responses, parsed_values)
st.success("Answers generated successfully")
Expand Down
18 changes: 14 additions & 4 deletions evaluation/human_evaluation/utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
import os
from typing import Any

API_URL = os.getenv("CHAT_ENDPOINT", "http://localhost:8000/chatApp")
API_BASE_URL = os.getenv("CHAT_ENDPOINT", "http://localhost:8000")
HEADERS = {"accept": "application/json", "Content-Type": "application/json"}

def fetch_endpoints() -> list[str]:
url = f"{API_BASE_URL}/chains/listAll"
try:
response = requests.get(url)
response.raise_for_status()
return list(response.json())
except requests.exceptions.RequestException:
return []

def get_responses(
questions: list[str], progress: Any, status_text: Any, current_question_text: Any
questions: list[str], progress: Any, status_text: Any, current_question_text: Any, selected_endpoint: str
) -> list[str]:
"""
Fetch responses from AI for a list of questions.
Expand All @@ -17,6 +25,7 @@ def get_responses(
- progress (Any): Streamlit progress bar object.
- status_text (Any): Streamlit text object for status updates.
- current_question_text (Any): Streamlit text object for current question display.
- selected_endpoint (str): The selected endpoint to use for the API call.
Returns:
- list[str]: List of responses from the AI combined with sources.
Expand All @@ -25,10 +34,11 @@ def get_responses(

for i, question in enumerate(questions):
current_question_text.text(f"Current question: {question}")
payload = {"query": question, "listSources": True}
payload = {"query": question, "list_sources": True}

try:
response = requests.post(API_URL, headers=HEADERS, json=payload)
url = f"{API_BASE_URL}/{selected_endpoint}"
response = requests.post(url, headers=HEADERS, json=payload)
response.raise_for_status()

try:
Expand Down

0 comments on commit 9a9e6d2

Please sign in to comment.