|
import os |
|
import streamlit as st |
|
from datetime import datetime |
|
import json |
|
import requests |
|
import uuid |
|
from datetime import date, datetime |
|
import requests |
|
from pydantic import BaseModel, Field |
|
from typing import Optional |
|
|
|
placeHolderPersona1 = """##Mission |
|
Please use the Conversation Summary and the Follow Up Question to create a highly targeted query for a semantic search engine. The query must represent the follow up question in the context of the conversation to date. Use the conversation summary to guide your thinking. |
|
You will be given the converstaion to date in the user prompt |
|
|
|
##Rules |
|
Ensure the query is concise |
|
Ensure the query has keywords from the Conversation Summary embedding within it such as the technical details from the summary |
|
If the Conversation Summary mentions a product like a 'loadcell' or 'hoist' or specific version of lift or moving walkway like 'Skyrise' or 'Gen2' then please use this in the query. |
|
Do not respond with anything other than the query for the Semantic Search Engine.""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChatRequestClient(BaseModel): |
|
|
|
user_id: str |
|
user_input: str |
|
numberOfQuestions: int |
|
welcomeMessage: str |
|
llm1: str |
|
tokens1: int |
|
temperature1: float |
|
persona1SystemMessage: str |
|
persona2SystemMessage: str |
|
userMessage2: str |
|
llm2: str |
|
tokens2: int |
|
temperature2: float |
|
|
|
def call_chat_api(data: ChatRequestClient): |
|
url = "https://agent-builder-api.greensea-b20be511.northeurope.azurecontainerapps.io/chat/" |
|
|
|
validated_data = data.dict() |
|
|
|
|
|
response = requests.post(url, json=validated_data) |
|
|
|
if response.status_code == 200: |
|
return response.json() |
|
else: |
|
return "An error occured" |
|
|
|
def genuuid (): |
|
return uuid.uuid4() |
|
|
|
def format_elapsed_time(time): |
|
|
|
return "{:.2f}".format(time) |
|
|
|
|
|
|
|
|
|
st.title('RAG Query Designer') |
|
|
|
|
|
st.sidebar.image('cognizant_logo.jpg') |
|
st.sidebar.header("Query Designer") |
|
|
|
|
|
st.sidebar.subheader("Query Designer Config") |
|
|
|
persona1SystemMessage = st.sidebar.text_area("Query Designer System Message", value=placeHolderPersona1, height=300) |
|
|
|
llm1 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona1_size') |
|
temp1 = st.sidebar.slider("Temperature", min_value=0.0, max_value=1.0, step=0.1, value=0.6, key='persona1_temp') |
|
tokens1 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona1_tokens') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.sidebar.caption(f"Session ID: {genuuid()}") |
|
|
|
|
|
|
|
st.header("Chat with the Agents") |
|
|
|
|
|
user_id = st.text_input("User ID:", key="user_id") |
|
|
|
|
|
if not user_id: |
|
st.warning("Please provide a User ID to start the chat.") |
|
else: |
|
|
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [] |
|
|
|
|
|
for message in st.session_state.messages: |
|
with st.chat_message(message["role"]): |
|
st.markdown(message["content"]) |
|
|
|
|
|
if user_input := st.chat_input("Write your message here:"): |
|
|
|
st.session_state.messages.append({"role": "user", "content": user_input}) |
|
st.chat_message("user").markdown(user_input) |
|
|
|
|
|
data = ChatRequestClient( |
|
user_id=user_id, |
|
user_input=user_input, |
|
numberOfQuestions=1000, |
|
welcomeMessage="", |
|
llm1=llm1, |
|
tokens1=tokens1, |
|
temperature1=temp1, |
|
persona1SystemMessage=persona1SystemMessage, |
|
persona2SystemMessage="", |
|
userMessage2="", |
|
llm2="GPT3.5", |
|
tokens2=1000, |
|
temperature2=0.2 |
|
) |
|
|
|
|
|
response = call_chat_api(data) |
|
|
|
|
|
agent_message = response.get("content", "No response received from the agent.") |
|
elapsed_time = response.get("elapsed_time", 0) |
|
count = response.get("count", 0) |
|
|
|
|
|
st.session_state.messages.append({"role": "assistant", "content": agent_message}) |
|
with st.chat_message("assistant"): |
|
st.markdown(agent_message) |
|
|
|
|
|
st.caption(f"##### Time taken: {format_elapsed_time(elapsed_time)} seconds") |
|
st.caption(f"##### Question Count: {count} of {numberOfQuestions}") |
|
|
|
|
|
|