Location: ai_chatbot_backend/app/dependencies/openai_model.py:120-121
Problem:
request_params = {
"model": self.model,
"messages": messages,
# "temperature": temperature, # COMMENTED OUT!
# "max_tokens": max_tokens, # COMMENTED OUT!
"stream": stream,
}Impact:
- OpenAI uses default
temperature=1.0(more random than intended) max_tokensnot set, OpenAI may use a low default → SHORT OUTPUTS- Your code sets
SAMPLING_PARAMSwithmax_tokens: 6000inrag_generation.py:19-24, but they're never passed!
Fix Required: Uncomment lines 120-121 in openai_model.py
Location: ai_chatbot_backend/.env:34-35
Problem:
llm_mode=local # ← ACTIVE (using vLLM)
#llm_mode = openai # ← COMMENTED OUT (OpenAI NOT used)Impact:
- Server initializes vLLM client, not OpenAI client
- All requests go to
http://128.32.43.210:8001/v1(your local vLLM server) - OpenAI API is NEVER called (confirmed by checking API usage)
Fix Required:
#llm_mode=local
llm_mode=openaiThen restart the server.
Location: ai_chatbot_backend/.env:48
Current Setting:
OPENAI_MODEL=gpt-5.2Note: User confirmed this is correct, but if you encounter issues, valid alternatives:
gpt-4o(recommended, latest)gpt-4o-mini(cheaper, faster)gpt-4-turboo1-preview,o1-mini
Location: ai_chatbot_backend/app/services/rag_generation.py:177-183
Problem: When using OpenAIModelClient, the code doesn't pass sampling parameters:
response = engine(
messages[-1].content,
messages=remote_messages,
stream=stream,
course=course,
response_format=response_format,
# Missing: temperature, max_tokens!
)Impact: Even if we uncomment them in openai_model.py, they won't be passed from rag_generation.py.
Fix Required: Add temperature and max_tokens parameters:
response = engine(
messages[-1].content,
messages=remote_messages,
stream=stream,
course=course,
response_format=response_format,
temperature=SAMPLING_PARAMS["temperature"], # Add this
max_tokens=SAMPLING_PARAMS["max_tokens"], # Add this
)Location: ai_chatbot_backend/app/services/rag_generation.py:166-169
Current Behavior: When tutor_mode=True, system uses structured JSON schema (RESPONSE_BLOCKS_OPENAI_FORMAT) which enforces strict JSON structure.
Potential Impact: Structured output mode may limit response length or creativity.
Testing: Try with tutor_mode=False to see if responses are longer without JSON constraints.
- ✅ Confirmed:
.envhasllm_mode=localinstead ofllm_mode=openai - ✅ Confirmed: User checked OpenAI API usage, no calls are being made
- ❌ Critical:
max_tokensparameter is commented out and not passed to OpenAI - ❌ Critical:
temperatureparameter is commented out ⚠️ Possible: Structured JSON schema may constrain output length
- Update .env: Change
llm_mode=localtollm_mode=openai - Restart server after .env change
- Uncomment parameters in
openai_model.py:120-121 - Pass parameters in
rag_generation.py:177-183
- Verify
OPENAI_MODEL=gpt-5.2is correct (user confirmed) - Test with
tutor_mode=Falseto rule out JSON schema constraints
After making fixes:
-
Check server startup logs:
🤖 LLM Mode: openai 🌐 Setting up OpenAI model pipeline... ✅ OpenAI model pipeline setup successfully! (model: gpt-5.2) -
Check request logs during chat:
[OpenAI Stream] Starting streaming response (chat.completions)... -
Check OpenAI API usage dashboard: Should see API calls
-
Check response length: Should see longer, more complete responses
# Change line 34:
#llm_mode=local
llm_mode=openai# Uncomment lines 120-121:
request_params = {
"model": self.model,
"messages": messages,
"temperature": temperature, # UNCOMMENT THIS
"max_tokens": max_tokens, # UNCOMMENT THIS
"stream": stream,
}# Add parameters to engine call (line 177-183):
response = engine(
messages[-1].content,
messages=remote_messages,
stream=stream,
course=course,
response_format=response_format,
temperature=SAMPLING_PARAMS["temperature"], # ADD THIS
max_tokens=SAMPLING_PARAMS["max_tokens"], # ADD THIS
)- The system uses a 4-mode architecture (Chat Tutor, Chat Regular, Voice Tutor, Voice Regular)
- Structured JSON output is used in tutor modes for citation tracking
- OpenAI API key is present in .env and appears valid
- vLLM servers are configured at
http://128.32.43.210:8001/v1(currently being used)