File size: 7,398 Bytes
ee96e07
 
 
564b273
ee96e07
 
564b273
 
 
 
ee96e07
c222558
 
 
 
 
 
 
 
 
 
 
 
564b273
c222558
 
 
 
 
 
564b273
c222558
 
564b273
0186a53
ee96e07
564b273
ee96e07
 
 
564b273
ee96e07
 
 
564b273
 
ee96e07
 
 
 
 
 
564b273
 
 
 
 
 
 
 
 
 
 
 
 
 
ee96e07
b177ad3
564b273
b177ad3
 
fef584f
564b273
 
c222558
564b273
 
 
c222558
564b273
 
c222558
 
 
 
564b273
 
 
 
c222558
 
 
 
 
 
 
 
 
 
564b273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c222558
564b273
 
 
 
 
c222558
 
 
 
 
564b273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c222558
 
0186a53
7673f6b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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."""

# placeHolderPersona2 = """## Mission
# To analyse a clinical triaging discussion between a patient and AI doctor interactions with a focus on Immunology symptoms, medical history, and test results to deduce the most probable Immunology diagnosis.
 
# ## Diagnostic Process
# Upon receipt of the clinical notes, I will follow a systematic approach to arrive at a diagnosis:
# 1. Review the patient's presenting symptoms and consider their relevance to immunopathology.
# 2. Cross-reference the gathered information with my knowledge base of immunology to identify patterns or indicators of specific immune disorders.
# 3. Formulate a diagnosis from the potential conditions.
# 4. Determine the most likely diagnosis and assign a confidence score from 1-100, with 100 being absolute certainty.
 
# # Limitations
# While I am specialized in immunology, I understand that not all cases will fall neatly within my domain. In instances where the clinical notes point to a condition outside of my expertise, I will provide the best possible diagnosis with the acknowledgment that my confidence score will reflect the limitations of my specialization in those cases"""


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/"
    # Validate and convert the data to a dictionary
    validated_data = data.dict()
    
    # Make the POST request to the FastAPI server
    response = requests.post(url, json=validated_data)
    
    if response.status_code == 200:
        return response.json()  # Return the JSON response if successful
    else:
        return "An error occured"  # Return the raw response text if not successful

def genuuid ():
    return uuid.uuid4()

def format_elapsed_time(time):
    # Format the elapsed time to two decimal places
    return "{:.2f}".format(time)


# Title of the application
# st.image('agentBuilderLogo.png')
st.title('RAG Query Designer')

# Sidebar for inputting personas
st.sidebar.image('cognizant_logo.jpg')
st.sidebar.header("Query Designer")
# st.sidebar.subheader("Welcome Message")
# welcomeMessage = st.sidebar.text_area("Define Intake Persona", value=welcomeMessage, height=300)
st.sidebar.subheader("Query Designer Config")
# numberOfQuestions = st.sidebar.slider("Number of Questions", min_value=0, max_value=10, step=1, value=5, key='persona1_questions')
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')

# # Persona 2
# st.sidebar.subheader("Recommendation and Next Best Action AI")
# persona2SystemMessage = st.sidebar.text_area("Define Recommendation Persona", value=placeHolderPersona2, height=300)
# with st.sidebar.expander("See explanation"):
#     st.write("This AI persona uses the output of the symptom intake AI as its input. This AI’s job is to augment a health professional by assisting with a diagnosis and possible next best action. The teams will need to determine if this should be a tool used directly by the patient, as an assistant to the health professional or a hybrid of the two. ")
#     st.image("agentPersona2.png")
# llm2 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona2_size')
# temp2 = st.sidebar.slider("Temperature", min_value=0.0, max_value=1.0, step=0.1, value=0.5, key='persona2_temp')
# tokens2 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona2_tokens')
# userMessage2 = st.sidebar.text_area("Define User Message", value="This is the conversation todate, ", height=150)
st.sidebar.caption(f"Session ID: {genuuid()}")


# Main chat interface
st.header("Chat with the Agents")

# User ID Input
user_id = st.text_input("User ID:", key="user_id")

# Ensure user_id is defined or fallback to a default value
if not user_id:
    st.warning("Please provide a User ID to start the chat.")
else:
    # Initialize chat history in session state
    if "messages" not in st.session_state:
        st.session_state.messages = []

    # Display chat messages from history on app rerun
    for message in st.session_state.messages:
        with st.chat_message(message["role"]):
            st.markdown(message["content"])

    # Collect user input
    if user_input := st.chat_input("Write your message here:"):
        # Add user message to the chat history
        st.session_state.messages.append({"role": "user", "content": user_input})
        st.chat_message("user").markdown(user_input)

        # Prepare data for API call
        data = ChatRequestClient(
            user_id=user_id,  # Ensure user_id is passed correctly
            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
        )

        # Call the API
        response = call_chat_api(data)

        # Process the API response
        agent_message = response.get("content", "No response received from the agent.")
        elapsed_time = response.get("elapsed_time", 0)
        count = response.get("count", 0)

        # Add agent response to the chat history
        st.session_state.messages.append({"role": "assistant", "content": agent_message})
        with st.chat_message("assistant"):
            st.markdown(agent_message)

        # Display additional metadata
        st.caption(f"##### Time taken: {format_elapsed_time(elapsed_time)} seconds")
        st.caption(f"##### Question Count: {count} of {numberOfQuestions}")