Spaces:
Sleeping
Sleeping
Update app.py
Browse files15 unmodified lines1617181920212214 unmodified lines3738394041424344454647484950515253545515 unmodified linesdef gpt_call(history, user_message,model="gpt-4o",max_tokens=1500, # Increased from 512 to 1500 to prevent truncationtemperature=0.7,top_p=0.95):"""14 unmodified lines# 3) Add the user's new messagemessages.append({"role": "user", "content": user_message})# 4) Call OpenAI APIcompletion = client.chat.completions.create(model=model,messages=messages,max_tokens=max_tokens, # Increased to allow longer responsestemperature=temperature,top_p=top_p)# 5) Ensure full response is returned without being cut offfull_response = "".join(choice.message.content for choice in completion.choices).strip()return full_responsedef respond(user_message, history):15 unmodified lines1617181920212214 unmodified lines3738394041424344454647484950515253545556575859606162636415 unmodified linesdef gpt_call(history, user_message,model="gpt-4o",max_tokens=3000, # Increased to 3000 to prevent truncationtemperature=0.7,top_p=0.95):"""14 unmodified lines# 3) Add the user's new messagemessages.append({"role": "user", "content": user_message})# 4) Call OpenAI API (with continuation handling)full_response = ""while True:completion = client.chat.completions.create(model=model,messages=messages,max_tokens=max_tokens, # Increased to allow longer responsestemperature=temperature,top_p=top_p)response_part = completion.choices[0].message.content.strip()full_response += " " + response_part# If the response looks incomplete, force the AI to continueif len(response_part) < max_tokens - 50: # Ensures near full completionbreak # Stop loop if response is complete# Add last response back into conversation history to continue itmessages.append({"role": "assistant", "content": response_part})return full_response.strip()def respond(user_message, history):
app.py+23-14