Shreyas094 commited on
Commit
3a4edb7
·
verified ·
1 Parent(s): c1f06dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -54,14 +54,14 @@ class CitingSources(BaseModel):
54
  description="List of sources to cite. Should be an URL of the source."
55
  )
56
 
57
- def chatbot_interface(message, history, model, temperature, num_calls, use_embeddings, system_prompt):
58
  if not message.strip():
59
  return "", history
60
 
61
  history = history + [(message, "")]
62
 
63
  try:
64
- for response in respond(message, history, model, temperature, num_calls, use_embeddings, system_prompt):
65
  history[-1] = (message, response)
66
  yield history
67
  except gr.CancelledError:
@@ -71,16 +71,16 @@ def chatbot_interface(message, history, model, temperature, num_calls, use_embed
71
  history[-1] = (message, f"An unexpected error occurred: {str(e)}")
72
  yield history
73
 
74
- def retry_last_response(history, model, temperature, num_calls, use_embeddings, system_prompt):
75
  if not history:
76
  return history
77
 
78
  last_user_msg = history[-1][0]
79
  history = history[:-1] # Remove the last response
80
 
81
- return chatbot_interface(last_user_msg, history, model, temperature, num_calls, use_embeddings, system_prompt)
82
 
83
- def respond(message, history, model, temperature, num_calls, use_embeddings, system_prompt):
84
  logging.info(f"User Query: {message}")
85
  logging.info(f"Model Used: {model}")
86
  logging.info(f"Use Embeddings: {use_embeddings}")
@@ -106,7 +106,7 @@ def create_web_search_vectors(search_results):
106
 
107
  return FAISS.from_documents(documents, embed)
108
 
109
- def get_response_with_search(query, model, num_calls=3, temperature=0.2, use_embeddings=True, system_prompt=DEFAULT_SYSTEM_PROMPT):
110
  search_results = duckduckgo_search(query)
111
 
112
  if use_embeddings:
@@ -202,11 +202,11 @@ demo = gr.ChatInterface(
202
  respond,
203
  additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),
204
  additional_inputs=[
 
205
  gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[3]),
206
  gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
207
  gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
208
  gr.Checkbox(label="Use Embeddings", value=False),
209
- gr.Textbox(label="System Prompt", lines=5, value=DEFAULT_SYSTEM_PROMPT),
210
  ],
211
  title="AI-powered Web Search Assistant",
212
  description="Ask questions and get answers from web search results.",
 
54
  description="List of sources to cite. Should be an URL of the source."
55
  )
56
 
57
+ def chatbot_interface(message, system_prompt, history, model, temperature, num_calls, use_embeddings):
58
  if not message.strip():
59
  return "", history
60
 
61
  history = history + [(message, "")]
62
 
63
  try:
64
+ for response in respond(message, system_prompt, history, model, temperature, num_calls, use_embeddings):
65
  history[-1] = (message, response)
66
  yield history
67
  except gr.CancelledError:
 
71
  history[-1] = (message, f"An unexpected error occurred: {str(e)}")
72
  yield history
73
 
74
+ def retry_last_response(system_prompt, history, model, temperature, num_calls, use_embeddings):
75
  if not history:
76
  return history
77
 
78
  last_user_msg = history[-1][0]
79
  history = history[:-1] # Remove the last response
80
 
81
+ return chatbot_interface(last_user_msg, , system_prompt, history, model, temperature, num_calls, use_embeddings)
82
 
83
+ def respond(message, system_prompt, history, model, temperature, num_calls, use_embeddings):
84
  logging.info(f"User Query: {message}")
85
  logging.info(f"Model Used: {model}")
86
  logging.info(f"Use Embeddings: {use_embeddings}")
 
106
 
107
  return FAISS.from_documents(documents, embed)
108
 
109
+ def get_response_with_search(query, system_prompt=DEFAULT_SYSTEM_PROMPT, model, num_calls=3, temperature=0.2, use_embeddings=True):
110
  search_results = duckduckgo_search(query)
111
 
112
  if use_embeddings:
 
202
  respond,
203
  additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),
204
  additional_inputs=[
205
+ gr.Textbox(label="System Prompt", lines=5, value=DEFAULT_SYSTEM_PROMPT),
206
  gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[3]),
207
  gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
208
  gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
209
  gr.Checkbox(label="Use Embeddings", value=False),
 
210
  ],
211
  title="AI-powered Web Search Assistant",
212
  description="Ask questions and get answers from web search results.",