desert commited on
Commit
408d189
1 Parent(s): b2af35c

init inference

Browse files
Files changed (1) hide show
  1. app.py +15 -18
app.py CHANGED
@@ -15,36 +15,33 @@ def respond(
15
  temperature,
16
  top_p,
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]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
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
  """
44
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
  """
46
  demo = gr.ChatInterface(
47
  respond,
 
48
  additional_inputs=[
49
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
 
15
  temperature,
16
  top_p,
17
  ):
18
+ # Combine the system message and chat history into a single string
19
+ prompt = system_message + "\n"
20
+ for user_input, assistant_reply in history:
21
+ if user_input:
22
+ prompt += f"User: {user_input}\n"
23
+ if assistant_reply:
24
+ prompt += f"Assistant: {assistant_reply}\n"
25
+ prompt += f"User: {message}\nAssistant:"
26
+
27
+ # Send the request to the model
28
  response = ""
29
+ for token in client.text_generation(
30
+ prompt,
31
+ max_new_tokens=max_tokens,
 
32
  stream=True,
33
  temperature=temperature,
34
  top_p=top_p,
35
  ):
36
+ response += token.token
 
 
37
  yield response
38
 
 
39
  """
40
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
41
  """
42
  demo = gr.ChatInterface(
43
  respond,
44
+ type="messages",
45
  additional_inputs=[
46
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
47
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),