Ari1020 commited on
Commit
4700995
·
verified ·
1 Parent(s): d5ae4af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -17,6 +17,16 @@ def respond(
17
  ):
18
  messages = [{"role": "system", "content": system_message}]
19
 
 
 
 
 
 
 
 
 
 
 
20
  for val in history:
21
  if val[0]:
22
  messages.append({"role": "user", "content": val[0]})
@@ -25,19 +35,18 @@ def respond(
25
 
26
  messages.append({"role": "user", "content": message})
27
 
28
- response = ""
29
-
30
- for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
33
  stream=True,
34
  temperature=temperature,
35
  top_p=top_p,
36
- ):
 
 
37
  token = message.choices[0].delta.content
38
 
39
- response += token
40
- yield response
41
 
42
 
43
  """
@@ -45,8 +54,13 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
45
  """
46
  demo = gr.ChatInterface(
47
  respond,
 
 
 
 
 
48
  )
49
 
50
 
51
  if __name__ == "__main__":
52
- demo.launch()
 
17
  ):
18
  messages = [{"role": "system", "content": system_message}]
19
 
20
+ # Introduce itself at the start
21
+ if not history:
22
+ response = client.chat_completion(
23
+ [{"role": "system", "content": system_message}, {"role": "assistant", "content": "Ciao, sono la tua segretaria. Come posso aiutarti oggi?"}],
24
+ max_tokens=max_tokens,
25
+ temperature=temperature,
26
+ top_p=top_p,
27
+ )
28
+ yield response[0].choices[0].text
29
+
30
  for val in history:
31
  if val[0]:
32
  messages.append({"role": "user", "content": val[0]})
 
35
 
36
  messages.append({"role": "user", "content": message})
37
 
38
+ response = client.chat_completion(
 
 
39
  messages,
40
  max_tokens=max_tokens,
41
  stream=True,
42
  temperature=temperature,
43
  top_p=top_p,
44
+ )
45
+
46
+ for message in response:
47
  token = message.choices[0].delta.content
48
 
49
+ yield message.choices[0].text
 
50
 
51
 
52
  """
 
54
  """
55
  demo = gr.ChatInterface(
56
  respond,
57
+ title="Segretaria Pincopallino",
58
+ description="Chatta con la tua segretaria",
59
+ max_tokens=512,
60
+ temperature=0.7,
61
+ top_p=0.95,
62
  )
63
 
64
 
65
  if __name__ == "__main__":
66
+ demo.launch()