|
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 |
|
|
|
welcomeMessage = "Welcome to the Ford Car Selection AI Agent I am here to talk about your motoring needs, please start by giving me your key requirement" |
|
|
|
|
|
placeHolderPersona1 = """# MISSION |
|
You are a car sales chatbot focusing on gaining enough information to make a selection. Your mission is to ask questions to help a customer fully articulate their needs in a clear manner. |
|
When they ask you a question or give you a need ask a suitable follow up question |
|
|
|
# RULES |
|
Ask only one question at a time. |
|
Provide some context or clarification around the follow-up questions you ask. |
|
Do not converse with the customer. |
|
Be as concise as possible""" |
|
|
|
placeHolderPersona2 = """# MISSION |
|
You are a car selection expert you will be given a dialoge between a customer and a sales executive. Your job is to select the perfect car for the customer based on their conversation |
|
# RULES |
|
You will need to select 1 primary choice car and one secondary choice car |
|
You will need to give some justification as to why you have chosen these cars |
|
Do not converse with the customer. |
|
Be as concise as possible""" |
|
|
|
|
|
|
|
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 = "http://localhost:8000/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() |
|
|
|
|
|
|
|
st.title('LLM-Powered Agent Interaction') |
|
|
|
|
|
st.sidebar.image('agentBuilderLogo.png') |
|
st.sidebar.header("Agent Personas Design") |
|
st.sidebar.subheader("Welcome Message") |
|
welcomeMessage = st.sidebar.text_area("Define Persona 1", value=welcomeMessage, height=150) |
|
st.sidebar.subheader("Personas 1 Settings") |
|
numberOfQuestions = st.sidebar.slider("Number of Questions", min_value=0, max_value=2, step=1, value=5, key='persona1_questions') |
|
persona1SystemMessage = st.sidebar.text_area("Define Persona 1", value=placeHolderPersona1, height=150) |
|
llm1 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona1_size') |
|
temp1 = st.sidebar.slider("Tempreature", 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.subheader("Personas 2 Settings") |
|
persona2SystemMessage = st.sidebar.text_area("Define Persona 2", value=placeHolderPersona2, height=150) |
|
llm2 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona2_size') |
|
temp2 = st.sidebar.slider("Tempreature", 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()}") |
|
|
|
st.header("Chat with the Agents") |
|
user_id = st.text_input("User ID:", key="user_id") |
|
user_input = st.text_input("Write your message here:", key="user_input") |
|
|
|
if 'history' not in st.session_state: |
|
st.session_state.history = [] |
|
|
|
if st.button("Send"): |
|
|
|
data = ChatRequestClient( |
|
user_id=user_id, |
|
user_input=user_input, |
|
numberOfQuestions=numberOfQuestions, |
|
welcomeMessage=welcomeMessage, |
|
llm1=llm1, |
|
tokens1=tokens1, |
|
temperature1=temp1, |
|
persona1SystemMessage=persona1SystemMessage, |
|
persona2SystemMessage=persona2SystemMessage, |
|
userMessage2=userMessage2, |
|
llm2=llm2, |
|
tokens2=tokens2, |
|
temperature2=temp2 |
|
) |
|
response = call_chat_api(data) |
|
st.session_state.history.append("You: " + user_input) |
|
st.session_state.history.append("Agent: " + response) |
|
|
|
|
|
for message in st.session_state.history: |
|
st.text(message) |