hussamalafandi commited on
Commit
aff055d
·
1 Parent(s): db15426

Refactor respond function to use consistent parameter naming and improve clarity

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -1,13 +1,13 @@
1
  import gradio as gr
2
- from langchain_core.messages import HumanMessage
3
  from langchain.chat_models import init_chat_model
 
4
 
5
  model = init_chat_model("gemini-2.0-flash", model_provider="google_genai")
6
 
7
 
8
  def respond(
9
  user_input: str,
10
- messages: list[dict],
11
  system_message: str,
12
  max_new_tokens: int,
13
  temperature: float,
@@ -17,10 +17,11 @@ def respond(
17
  Respond to user input using the model.
18
  """
19
  response = model.invoke(
20
- messages + [HumanMessage(content=user_input)],
21
  )
22
  return response.content
23
 
 
24
  """
25
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
26
  """
@@ -28,9 +29,12 @@ demo = gr.ChatInterface(
28
  fn=respond,
29
  type="messages",
30
  additional_inputs=[
31
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
32
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
33
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
 
 
 
34
  gr.Slider(
35
  minimum=0.1,
36
  maximum=1.0,
 
1
  import gradio as gr
 
2
  from langchain.chat_models import init_chat_model
3
+ from langchain_core.messages import HumanMessage
4
 
5
  model = init_chat_model("gemini-2.0-flash", model_provider="google_genai")
6
 
7
 
8
  def respond(
9
  user_input: str,
10
+ dialog_history: list[dict],
11
  system_message: str,
12
  max_new_tokens: int,
13
  temperature: float,
 
17
  Respond to user input using the model.
18
  """
19
  response = model.invoke(
20
+ dialog_history + [HumanMessage(content=user_input)],
21
  )
22
  return response.content
23
 
24
+
25
  """
26
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
27
  """
 
29
  fn=respond,
30
  type="messages",
31
  additional_inputs=[
32
+ gr.Textbox(value="You are a friendly Chatbot.",
33
+ label="System message"),
34
+ gr.Slider(minimum=1, maximum=2048, value=512,
35
+ step=1, label="Max new tokens"),
36
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7,
37
+ step=0.1, label="Temperature"),
38
  gr.Slider(
39
  minimum=0.1,
40
  maximum=1.0,