khoj-ai / khoj

Your AI second brain. Self-hostable. Get answers from the web or your docs. Build custom agents, schedule automations, do deep research. Turn any online or local LLM into your personal, autonomous AI (e.g gpt, claude, gemini, llama, qwen, mistral).
https://khoj.dev
GNU Affero General Public License v3.0
14.15k stars 704 forks source link

[FIX] Empty system message error for subqueries #650

Closed sabaimran closed 8 months ago

sabaimran commented 8 months ago

Describe the bug

Issue

See a link to the discussion here. Text reproduced for ease:

i'm self hosting using lm studio and it was working fine but I recently updated my docker containers and now i'm getting this issue when calling the local openai api
[2024-02-21 07:05:56.521] [ERROR] [Server Error] {"title":"'messages' array must only contain objects with a 'content' field that is not empty"}
[2024-02-21 07:05:56.818] [INFO] [LM STUDIO SERVER] Processing queued request...
[2024-02-21 07:05:56.818] [INFO] Received POST request to /v1/chat/completions with body: {
  "messages": [
    {
      "role": "system",
      "content": ""
    },
    {
      "role": "user",
      "content": "You are Khoj,
looks like it doesnt like the system content being empty
any ideas how I resolve this?
looks like before it had
"messages": [
    {
      "role": "assistant",
      "content":
and it was working fine

Resolution

In generate_chatml_messages_with_context, don't add a message to the list if the content is empty.

If self-hosted