redjkh commited on
Commit
59f1df2
·
verified ·
1 Parent(s): 275fc16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -20,7 +20,28 @@ recipes = [
20
  client = InferenceClient("microsoft/phi-4")
21
 
22
  def respond(message, history):
23
- messages = [{"role": "system", "content": "You are a friendly chatbot"}]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  if history:
25
  messages.extend(history)
26
  messages.append({"role": "user", "content": message})
@@ -30,7 +51,7 @@ def respond(message, history):
30
  max_tokens=1000
31
  )
32
 
33
- return response['choices'][0]['message']['content'].strip()
34
 
35
 
36
  with gr.Blocks() as demo:
 
20
  client = InferenceClient("microsoft/phi-4")
21
 
22
  def respond(message, history):
23
+ # Start with a system prompt
24
+ messages = [{"role": "system", "content": "You are a friendly recipe assistant."}]
25
+
26
+ # Convert Gradio history (list of [user, assistant] pairs) to OpenAI-style message format
27
+ for user_msg, bot_msg in history:
28
+ if user_msg:
29
+ messages.append({"role": "user", "content": user_msg})
30
+ if bot_msg:
31
+ messages.append({"role": "assistant", "content": bot_msg})
32
+
33
+ # Append the new user message
34
+ messages.append({"role": "user", "content": message})
35
+
36
+ # Call the model
37
+ response = client.chat_completion(
38
+ messages=messages,
39
+ max_tokens=200
40
+ )
41
+
42
+ return response["choices"][0]["message"]["content"].strip()
43
+
44
+ """messages = [{"role": "system", "content": "You are a friendly chatbot"}]
45
  if history:
46
  messages.extend(history)
47
  messages.append({"role": "user", "content": message})
 
51
  max_tokens=1000
52
  )
53
 
54
+ return response['choices'][0]['message']['content'].strip()"""
55
 
56
 
57
  with gr.Blocks() as demo: