mikemin027 commited on
Commit
abff1a0
1 Parent(s): 39dd6d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -15,32 +15,36 @@ def respond(
15
  temperature,
16
  top_p,
17
  ):
18
- # Flatten the history and system message into a list of strings
19
- messages = [system_message] # Start with the system message
20
 
 
 
 
 
21
  for val in history:
22
  if val[0]:
23
- messages.append(val[0]) # Append user message
24
  if val[1]:
25
- messages.append(val[1]) # Append assistant message
26
 
27
- messages.append(message) # Add the current user message
 
28
 
29
  response = ""
30
 
31
- # Use llm.create_completion instead of llm.chat_completion
32
- for message in llm.create_completion(
33
- messages,
34
  max_tokens=max_tokens,
35
  stream=True,
36
  temperature=temperature,
37
  top_p=top_p,
38
  ):
39
- token = message['choices'][0]['delta']['content']
40
- response += token
41
  yield response
42
 
43
-
44
  # Gradio demo setup
45
  demo = gr.ChatInterface(
46
  respond,
 
15
  temperature,
16
  top_p,
17
  ):
18
+ # Initialize an empty list to hold tokenized messages
19
+ tokenized_messages = []
20
 
21
+ # Tokenize the system message
22
+ tokenized_messages.append(llm.tokenizer.encode(system_message))
23
+
24
+ # Tokenize the history messages
25
  for val in history:
26
  if val[0]:
27
+ tokenized_messages.append(llm.tokenizer.encode(val[0])) # User message
28
  if val[1]:
29
+ tokenized_messages.append(llm.tokenizer.encode(val[1])) # Assistant message
30
 
31
+ # Tokenize the current user message
32
+ tokenized_messages.append(llm.tokenizer.encode(message))
33
 
34
  response = ""
35
 
36
+ # Use llm.create_completion with tokenized messages
37
+ for token in llm.create_completion(
38
+ tokenized_messages,
39
  max_tokens=max_tokens,
40
  stream=True,
41
  temperature=temperature,
42
  top_p=top_p,
43
  ):
44
+ token_content = token['choices'][0]['delta']['content']
45
+ response += token_content
46
  yield response
47
 
 
48
  # Gradio demo setup
49
  demo = gr.ChatInterface(
50
  respond,