Skip to content

Commit

Permalink
Merge pull request #8 from a-gleeson/conversation
Browse files Browse the repository at this point in the history
Conversation bot added
  • Loading branch information
James-Osmond authored Apr 17, 2024
2 parents d4ca5f8 + 33d7ec7 commit 4d83239
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 30 deletions.
29 changes: 21 additions & 8 deletions app/pages/3_Summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from config.logging import setup_logging
from config.settings import ENV
from hackathon.api import fact_check_api, glossery_api, summary_api
from hackathon.api import conversation_api, fact_check_api, glossery_api, summary_api
from hackathon.streamlit.utils import check_password
from hackathon.transcripts.transcript_handling import Transcript

Expand Down Expand Up @@ -105,23 +105,31 @@ def image_to_base64(image):
def llm_summarise(transcript: str) -> str:
post_response = summary_api.invoke_post(transcript)
fact_check_response = fact_check_api.invoke_post(transcript)
conversation_response = conversation_api.invoke_post(transcript)
time.sleep(15)

get_summary_response = summary_api.invoke_get(post_response["conversationId"])
get_fact_response = fact_check_api.invoke_get(fact_check_response["conversationId"])

post_glossary = glossery_api.invoke_post(get_summary_response)
time.sleep(15)
time.sleep(25)
get_glossary = glossery_api.invoke_get(post_glossary["conversationId"])
conversation_api.invoke_get(conversation_response["conversationId"])
return {
"summary": get_summary_response,
"facts": get_fact_response,
"glossary": get_glossary,
"conversationConversationId": conversation_response["conversationId"],
}


def query_llm(prompt: str) -> str:
return f'Hello! I am *not* an LLM! James created me as an "artificial artificial intelligence" - this is the only thing I can say. ({dt.datetime.now()})'
def query_llm(prompt: str, transcript: str, conversationId) -> str:
query = f"With knowledge of this transcript:\n{transcript}\n\nAnswer this query: {prompt}"
print(query)
query_response = conversation_api.invoke_post(query, conversationId)
time.sleep(15)
chat_response = conversation_api.invoke_get(query_response["conversationId"])
return chat_response


with st.expander("#### Upload transcript", expanded=False):
Expand All @@ -138,21 +146,26 @@ def query_llm(prompt: str) -> str:
else:
st_summarise_button = st.button("Generate meeting summary")
if st_summarise_button or st.session_state.summary_generated:
if not st.session_state.summary_generated:
returned_data = llm_summarise(transcript=data)
st.session_state.returned_data = returned_data
returned_data = st.session_state.returned_data
st.session_state.summary_generated = True
returned_data = llm_summarise(transcript=data)
st.markdown(returned_data["summary"])
prompt = st.text_input(label="Enter query here:", placeholder="How ")
st_query_button = st.button("Query LLM")
if st_query_button and prompt != "":
st.session_state.chat_history += f"User: {prompt}\n\n"
st.session_state.chat_history += f"Claude: {query_llm(prompt)}\n\n"
st.session_state.chat_history += f"Claude: {query_llm(prompt, data, conversationId=returned_data['conversationConversationId'])}\n\n"
st.markdown(st.session_state.chat_history)
# TODO: Add button to download summary as txt file

with st.expander("#### Identify facts", expanded=False):
if returned_data.get("facts"):
if returned_data.get("facts") and st.session_state.summary_generated:
returned_data = st.session_state.returned_data
st.write(returned_data["facts"])

with st.expander("#### Generate glossary", expanded=False):
if returned_data.get("glossary"):
if returned_data.get("glossary") and st.session_state.summary_generated:
returned_data = st.session_state.returned_data
st.write(returned_data["glossary"])
2 changes: 2 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@
FACTCHECK_URL = os.environ.get("FACTCHECK_URL")
GLOSSERY_API = os.environ.get("GLOSSERY_API")
GLOSSERY_URL = os.environ.get("GLOSSERY_URL")
CONVERSATION_API = os.environ.get("CONVERSATION_API")
CONVERSATION_URL = os.environ.get("CONVERSATION_URL")
51 changes: 29 additions & 22 deletions hackathon/api.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
import requests
import time

from config.settings import MODEL
from config.settings import SUMMARISE_API
from config.settings import SUMMARISE_URL
from config.settings import FACTCHECK_API
from config.settings import FACTCHECK_URL
from config.settings import GLOSSERY_API
from config.settings import GLOSSERY_URL
import requests

from config.settings import (
CONVERSATION_API,
CONVERSATION_URL,
FACTCHECK_API,
FACTCHECK_URL,
GLOSSERY_API,
GLOSSERY_URL,
MODEL,
SUMMARISE_API,
SUMMARISE_URL,
)


class API:

def __init__(self, api_key, url):
self.api_key = api_key
self.api_key = api_key
self.url = url
self.headers = {
"Content-Type": "application/json",
"X-API-Key": f"{self.api_key}",
}

def invoke_post(self, message):
def invoke_post(self, message, conversation_id=None):
post_data = {
"message": {
"message": {
"content": [
{
"contentType": "text",
"mediaType": "string",
"body": message
}
{"contentType": "text", "mediaType": "string", "body": message}
],
"model": MODEL
"model": MODEL,
}
}
response = requests.post(self.url+ "/conversation", json=post_data, headers=self.headers)
json_respn = response.json()
if conversation_id is not None:
post_data["conversationId"] = conversation_id
response = requests.post(
self.url + "/conversation", json=post_data, headers=self.headers
)
json_respn = response.json()
return json_respn

def invoke_get(self, conversation_id):
uri_path = "/conversation/"+conversation_id
uri_path = "/conversation/" + conversation_id
response = requests.get(
self.url + uri_path,
headers=self.headers,
Expand All @@ -46,8 +52,9 @@ def invoke_get(self, conversation_id):

last_msg_id = json_response["lastMessageId"]
return json_response["messageMap"][last_msg_id]["content"][0]["body"]


summary_api = API(SUMMARISE_API, SUMMARISE_URL)
fact_check_api = API(FACTCHECK_API, FACTCHECK_URL)
glossery_api = API(GLOSSERY_API, GLOSSERY_URL)
conversation_api = API(CONVERSATION_API, CONVERSATION_URL)

0 comments on commit 4d83239

Please sign in to comment.