Spaces:
Running
Running
Updated code to log name and email
Browse files- app/main.py +9 -3
- app/rag.py +3 -1
app/main.py
CHANGED
|
@@ -23,18 +23,19 @@ app.add_middleware(
|
|
| 23 |
class ChatInput(BaseModel):
|
| 24 |
question: str
|
| 25 |
session_id: str
|
|
|
|
|
|
|
| 26 |
|
| 27 |
@app.post("/chat")
|
| 28 |
async def chat(input: ChatInput):
|
| 29 |
print("Got question:", input.question)
|
| 30 |
print("Session ID:", input.session_id)
|
| 31 |
-
|
| 32 |
config = {
|
| 33 |
'configurable': {
|
| 34 |
'thread_id': input.session_id
|
| 35 |
}
|
| 36 |
}
|
| 37 |
-
response = await get_response(input.question, config=config)
|
| 38 |
return {"answer": response['response']}
|
| 39 |
|
| 40 |
|
|
@@ -44,6 +45,8 @@ class FAQInput(BaseModel):
|
|
| 44 |
session_id: str
|
| 45 |
question: str
|
| 46 |
answer: str
|
|
|
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
#Log FAQ in conversation History even though RAG not being called so future RAG calls have access to info
|
|
@@ -52,6 +55,9 @@ async def log_faq(faq: FAQInput):
|
|
| 52 |
session_id = faq.session_id
|
| 53 |
question = faq.question
|
| 54 |
answer = faq.answer
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
from app.rag import session_histories, HumanMessage, AIMessage, log_chat
|
| 57 |
if session_id not in session_histories:
|
|
@@ -60,5 +66,5 @@ async def log_faq(faq: FAQInput):
|
|
| 60 |
session_histories[session_id].append(HumanMessage(content=question))
|
| 61 |
session_histories[session_id].append(AIMessage(content=answer))
|
| 62 |
|
| 63 |
-
log_chat(session_id=session_id, query=question, answer=answer, metadata={"source": "FAQ"})
|
| 64 |
return {"status": "success"}
|
|
|
|
| 23 |
class ChatInput(BaseModel):
|
| 24 |
question: str
|
| 25 |
session_id: str
|
| 26 |
+
name: str
|
| 27 |
+
email: str
|
| 28 |
|
| 29 |
@app.post("/chat")
|
| 30 |
async def chat(input: ChatInput):
|
| 31 |
print("Got question:", input.question)
|
| 32 |
print("Session ID:", input.session_id)
|
|
|
|
| 33 |
config = {
|
| 34 |
'configurable': {
|
| 35 |
'thread_id': input.session_id
|
| 36 |
}
|
| 37 |
}
|
| 38 |
+
response = await get_response(input.question, name=input.name, email=input.email, config=config)
|
| 39 |
return {"answer": response['response']}
|
| 40 |
|
| 41 |
|
|
|
|
| 45 |
session_id: str
|
| 46 |
question: str
|
| 47 |
answer: str
|
| 48 |
+
name: str
|
| 49 |
+
email: str
|
| 50 |
|
| 51 |
|
| 52 |
#Log FAQ in conversation History even though RAG not being called so future RAG calls have access to info
|
|
|
|
| 55 |
session_id = faq.session_id
|
| 56 |
question = faq.question
|
| 57 |
answer = faq.answer
|
| 58 |
+
name=faq.name
|
| 59 |
+
email=faq.email
|
| 60 |
+
|
| 61 |
|
| 62 |
from app.rag import session_histories, HumanMessage, AIMessage, log_chat
|
| 63 |
if session_id not in session_histories:
|
|
|
|
| 66 |
session_histories[session_id].append(HumanMessage(content=question))
|
| 67 |
session_histories[session_id].append(AIMessage(content=answer))
|
| 68 |
|
| 69 |
+
log_chat(session_id=session_id, name=name, email=email, query=question, answer=answer, metadata={"source": "FAQ"})
|
| 70 |
return {"status": "success"}
|
app/rag.py
CHANGED
|
@@ -256,7 +256,7 @@ graph.add_edge("generate_response", END)
|
|
| 256 |
|
| 257 |
app = graph.compile()
|
| 258 |
|
| 259 |
-
async def get_response(query: str, config) -> dict:
|
| 260 |
start_time = time.time()
|
| 261 |
session_id = config['configurable']['thread_id']
|
| 262 |
history = session_histories.get(session_id, [])
|
|
@@ -276,6 +276,8 @@ async def get_response(query: str, config) -> dict:
|
|
| 276 |
|
| 277 |
log_chat(
|
| 278 |
session_id=session_id,
|
|
|
|
|
|
|
| 279 |
query=query,
|
| 280 |
answer=result.get("response", ""),
|
| 281 |
latency_ms= latency_ms,
|
|
|
|
| 256 |
|
| 257 |
app = graph.compile()
|
| 258 |
|
| 259 |
+
async def get_response(query: str, name, email, config) -> dict:
|
| 260 |
start_time = time.time()
|
| 261 |
session_id = config['configurable']['thread_id']
|
| 262 |
history = session_histories.get(session_id, [])
|
|
|
|
| 276 |
|
| 277 |
log_chat(
|
| 278 |
session_id=session_id,
|
| 279 |
+
name=name,
|
| 280 |
+
email=email,
|
| 281 |
query=query,
|
| 282 |
answer=result.get("response", ""),
|
| 283 |
latency_ms= latency_ms,
|