Reality123b commited on
Commit
94730d2
·
verified ·
1 Parent(s): db7d152

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -159,12 +159,19 @@ class XylariaChat:
159
  content=user_input
160
  ).to_dict())
161
 
 
 
 
 
 
 
 
162
  # Generate response with streaming
163
  stream = self.client.chat_completion(
164
  messages=messages,
165
  model="Qwen/QwQ-32B-Preview",
166
  temperature=0.7,
167
- max_tokens=16384,
168
  top_p=0.9,
169
  stream=True
170
  )
 
159
  content=user_input
160
  ).to_dict())
161
 
162
+ # Calculate available tokens
163
+ input_tokens = sum(len(msg['content'].split()) for msg in messages)
164
+ max_new_tokens = 16384 - input_tokens - 50 # Reserve some tokens for safety
165
+
166
+ # Limit max_new_tokens to prevent exceeding the total limit
167
+ max_new_tokens = min(max_new_tokens, 10020)
168
+
169
  # Generate response with streaming
170
  stream = self.client.chat_completion(
171
  messages=messages,
172
  model="Qwen/QwQ-32B-Preview",
173
  temperature=0.7,
174
+ max_tokens=max_new_tokens,
175
  top_p=0.9,
176
  stream=True
177
  )