psy7743 commited on
Commit
4b8a906
·
verified ·
1 Parent(s): 7b22111

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -82,8 +82,8 @@ def search_chroma(query, n_results=5):
82
  )
83
  return results["documents"][0]
84
 
85
- def generate_response(user_query: str) -> str:
86
- docs = search_chroma(user_query)
87
  context_str = "\n\n".join(docs)
88
 
89
  sys_prompt = """You are a helpful assistant. Based on the context and user query, provide an accurate and concise answer.
@@ -94,7 +94,7 @@ def generate_response(user_query: str) -> str:
94
  - Do not hallucinate or make up answers.
95
  - Keep the tone friendly."""
96
 
97
- prompt = f"{sys_prompt}\n\ncontext:\n{context_str}\n\nQuestion: {user_query}\nAnswer:"
98
 
99
  response = llm(
100
  prompt,
@@ -104,6 +104,7 @@ def generate_response(user_query: str) -> str:
104
  stop=["Q:", "\n"],
105
  echo=True
106
  )
 
107
  return response["choices"][0]["text"].split("Answer:")[-1].strip()
108
 
109
  # ---------------------- Gradio Interface ----------------------
@@ -116,7 +117,7 @@ def gradio_chat_interface(message, history):
116
  demo = gr.ChatInterface(
117
  fn=generate_response,
118
  title="🦙 LLaMA-3 FAQ Chatbot",
119
- chatbot=gr.Chatbot(label="Ask me anything about Jupiter Money!"),
120
  examples=[
121
  "What is Jupiter Edge credit card?",
122
  "What happens if I miss a payment?",
 
82
  )
83
  return results["documents"][0]
84
 
85
+ def generate_response(message, history=[]):
86
+ docs = search_chroma(message)
87
  context_str = "\n\n".join(docs)
88
 
89
  sys_prompt = """You are a helpful assistant. Based on the context and user query, provide an accurate and concise answer.
 
94
  - Do not hallucinate or make up answers.
95
  - Keep the tone friendly."""
96
 
97
+ prompt = f"{sys_prompt}\n\ncontext:\n{context_str}\n\nQuestion: {message}\nAnswer:"
98
 
99
  response = llm(
100
  prompt,
 
104
  stop=["Q:", "\n"],
105
  echo=True
106
  )
107
+
108
  return response["choices"][0]["text"].split("Answer:")[-1].strip()
109
 
110
  # ---------------------- Gradio Interface ----------------------
 
117
  demo = gr.ChatInterface(
118
  fn=generate_response,
119
  title="🦙 LLaMA-3 FAQ Chatbot",
120
+ chatbot=gr.Chatbot(label="Ask me anything about Jupiter Money!", type="messages"),
121
  examples=[
122
  "What is Jupiter Edge credit card?",
123
  "What happens if I miss a payment?",