Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- agentBuilderLogo.png +0 -0
- app.py +121 -0
- requirements.txt +3 -0
agentBuilderLogo.png
ADDED
|
app.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
import json
|
| 5 |
+
import requests
|
| 6 |
+
import uuid
|
| 7 |
+
from datetime import date, datetime
|
| 8 |
+
import requests
|
| 9 |
+
from pydantic import BaseModel, Field
|
| 10 |
+
from typing import Optional
|
| 11 |
+
|
| 12 |
+
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"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
placeHolderPersona1 = """# MISSION
|
| 16 |
+
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.
|
| 17 |
+
When they ask you a question or give you a need ask a suitable follow up question
|
| 18 |
+
|
| 19 |
+
# RULES
|
| 20 |
+
Ask only one question at a time.
|
| 21 |
+
Provide some context or clarification around the follow-up questions you ask.
|
| 22 |
+
Do not converse with the customer.
|
| 23 |
+
Be as concise as possible"""
|
| 24 |
+
|
| 25 |
+
placeHolderPersona2 = """# MISSION
|
| 26 |
+
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
|
| 27 |
+
# RULES
|
| 28 |
+
You will need to select 1 primary choice car and one secondary choice car
|
| 29 |
+
You will need to give some justification as to why you have chosen these cars
|
| 30 |
+
Do not converse with the customer.
|
| 31 |
+
Be as concise as possible"""
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class ChatRequestClient(BaseModel):
|
| 36 |
+
user_id: str
|
| 37 |
+
user_input: str
|
| 38 |
+
numberOfQuestions: int
|
| 39 |
+
welcomeMessage: str
|
| 40 |
+
llm1: str
|
| 41 |
+
tokens1: int
|
| 42 |
+
temperature1: float
|
| 43 |
+
persona1SystemMessage: str
|
| 44 |
+
persona2SystemMessage: str
|
| 45 |
+
userMessage2: str
|
| 46 |
+
llm2: str
|
| 47 |
+
tokens2: int
|
| 48 |
+
temperature2: float
|
| 49 |
+
|
| 50 |
+
def call_chat_api(data: ChatRequestClient):
|
| 51 |
+
url = "http://localhost:8000/chat/"
|
| 52 |
+
# Validate and convert the data to a dictionary
|
| 53 |
+
validated_data = data.dict()
|
| 54 |
+
|
| 55 |
+
# Make the POST request to the FastAPI server
|
| 56 |
+
response = requests.post(url, json=validated_data)
|
| 57 |
+
|
| 58 |
+
if response.status_code == 200:
|
| 59 |
+
return response.json() # Return the JSON response if successful
|
| 60 |
+
else:
|
| 61 |
+
return "An error occured" # Return the raw response text if not successful
|
| 62 |
+
|
| 63 |
+
def genuuid ():
|
| 64 |
+
return uuid.uuid4()
|
| 65 |
+
|
| 66 |
+
# Title of the application
|
| 67 |
+
# st.image('agentBuilderLogo.png')
|
| 68 |
+
st.title('LLM-Powered Agent Interaction')
|
| 69 |
+
|
| 70 |
+
# Sidebar for inputting personas
|
| 71 |
+
st.sidebar.image('agentBuilderLogo.png')
|
| 72 |
+
st.sidebar.header("Agent Personas Design")
|
| 73 |
+
st.sidebar.subheader("Welcome Message")
|
| 74 |
+
welcomeMessage = st.sidebar.text_area("Define Persona 1", value=welcomeMessage, height=150)
|
| 75 |
+
st.sidebar.subheader("Personas 1 Settings")
|
| 76 |
+
numberOfQuestions = st.sidebar.slider("Number of Questions", min_value=0, max_value=2, step=1, value=5, key='persona1_questions')
|
| 77 |
+
persona1SystemMessage = st.sidebar.text_area("Define Persona 1", value=placeHolderPersona1, height=150)
|
| 78 |
+
llm1 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona1_size')
|
| 79 |
+
temp1 = st.sidebar.slider("Tempreature", min_value=0.0, max_value=1.0, step=0.1, value=0.6, key='persona1_temp')
|
| 80 |
+
tokens1 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona1_tokens')
|
| 81 |
+
|
| 82 |
+
# Persona 2
|
| 83 |
+
st.sidebar.subheader("Personas 2 Settings")
|
| 84 |
+
persona2SystemMessage = st.sidebar.text_area("Define Persona 2", value=placeHolderPersona2, height=150)
|
| 85 |
+
llm2 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona2_size')
|
| 86 |
+
temp2 = st.sidebar.slider("Tempreature", min_value=0.0, max_value=1.0, step=0.1, value=0.5, key='persona2_temp')
|
| 87 |
+
tokens2 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona2_tokens')
|
| 88 |
+
userMessage2 = st.sidebar.text_area("Define User Message", value="This is the conversation todate, ", height=150)
|
| 89 |
+
st.sidebar.caption(f"Session ID: {genuuid()}")
|
| 90 |
+
# Main chat interface
|
| 91 |
+
st.header("Chat with the Agents")
|
| 92 |
+
user_id = st.text_input("User ID:", key="user_id")
|
| 93 |
+
user_input = st.text_input("Write your message here:", key="user_input")
|
| 94 |
+
|
| 95 |
+
if 'history' not in st.session_state:
|
| 96 |
+
st.session_state.history = []
|
| 97 |
+
|
| 98 |
+
if st.button("Send"):
|
| 99 |
+
# Placeholder for processing the input and generating a response
|
| 100 |
+
data = ChatRequestClient(
|
| 101 |
+
user_id=user_id,
|
| 102 |
+
user_input=user_input,
|
| 103 |
+
numberOfQuestions=numberOfQuestions,
|
| 104 |
+
welcomeMessage=welcomeMessage,
|
| 105 |
+
llm1=llm1,
|
| 106 |
+
tokens1=tokens1,
|
| 107 |
+
temperature1=temp1,
|
| 108 |
+
persona1SystemMessage=persona1SystemMessage,
|
| 109 |
+
persona2SystemMessage=persona2SystemMessage,
|
| 110 |
+
userMessage2=userMessage2,
|
| 111 |
+
llm2=llm2,
|
| 112 |
+
tokens2=tokens2,
|
| 113 |
+
temperature2=temp2
|
| 114 |
+
)
|
| 115 |
+
response = call_chat_api(data)
|
| 116 |
+
st.session_state.history.append("You: " + user_input)
|
| 117 |
+
st.session_state.history.append("Agent: " + response) # Using 'response' after it's defined
|
| 118 |
+
|
| 119 |
+
# Display the chat history
|
| 120 |
+
for message in st.session_state.history:
|
| 121 |
+
st.text(message)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
requests
|
| 3 |
+
pydantic
|