-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
63 lines (45 loc) · 1.35 KB
/
app.py
File metadata and controls
63 lines (45 loc) · 1.35 KB
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
from dotenv import load_dotenv
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain.agents import create_agent
from langchain.messages import HumanMessage, SystemMessage
import langsmith as ls
from prompt import SYSTEM_PROMPT
from logger import logger
load_dotenv()
client = MultiServerMCPClient(
{
"products": {
"transport": "streamable_http",
"url": "https://vipfapwm3x.us-east-1.awsapprunner.com/mcp",
}
}
)
import gradio as gr
async def chat(message, history):
tools = await client.get_tools()
agent = create_agent(
"gpt-4o-mini",
tools,
system_prompt=SYSTEM_PROMPT,
)
try:
result = await agent.ainvoke({"messages": history + [HumanMessage(content=message)]})
except Exception as e:
logger.error(e)
yield f'Error: {str(e)}. Kindly try a different request or contact the support team.'
return
if message is None:
yield ''
yield result["messages"][-1].content
title = 'GHTechCorp Customer Support'
with gr.Blocks(title=title, fill_height=True) as demo:
gr.Markdown(
"""
# GHTechCorp Customer Support
Welcome! I'm your virtual assistant for monitors, computers, printers & accessories.
"""
)
gr.ChatInterface(
fn=chat,
)
demo.launch(share=True)