Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] AiMessage text content is not copied when toolCalls are present #986

Open
langchain4j opened this issue Apr 19, 2024 · 0 comments
Open
Labels
bug Something isn't working P3 Medium priority

Comments

@langchain4j
Copy link
Owner

Describe the bug
When AiMessage contains both text and toolCalls, next time it is sent to the LLM again in a list of messages, only toolCalls is present.

Log and Stack trace
Response:

{
  "id": "chatcmpl-9Fel2FjEBshnmq0c4wiEtOgnJRHnT",
  "object": "chat.completion",
  "created": 1713518620,
  "model": "gpt-3.5-turbo-0125",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "I encountered an issue while trying to add the word \"haben\" to your vocabulary. Let me try that again.",
        "tool_calls": [
          {
            "id": "call_nZ6wMhj9MXkch4zBPKGcd3xS",
            "type": "function",
            "function": {
              "name": "addWordToVocabulary",
              "arguments": "{\"arg1\":\"haben\"}"
            }
          }
        ]
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 109,
    "completion_tokens": 44,
    "total_tokens": 153
  },
  "system_fingerprint": "fp_d9767fc5b9"
}

Next request:

{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "system",
      "content": "You are a tutor of a German language."
    },
    {
      "role": "user",
      "content": "add a word \"haben\" in my vocab"
    },
    {
      "role": "assistant",
      "content": null,
      "tool_calls": [
        {
          "id": "call_h6DsefXXfv2kgacwW1M9MkBw",
          "type": "function",
          "function": {
            "name": "addWordToVocabulary",
            "arguments": "{\"arg1\":\"haben\"}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "call_h6DsefXXfv2kgacwW1M9MkBw",
      "content": "DB was closed"
    },
    {
      "role": "assistant",
      "content": null,
      "tool_calls": [
        {
          "id": "call_nZ6wMhj9MXkch4zBPKGcd3xS",
          "type": "function",
          "function": {
            "name": "addWordToVocabulary",
            "arguments": "{\"arg1\":\"haben\"}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "call_nZ6wMhj9MXkch4zBPKGcd3xS",
      "content": "DB was closed"
    }
  ],
  "temperature": 0.7,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "addWordToVocabulary",
        "description": "",
        "parameters": {
          "type": "object",
          "properties": {
            "arg1": {
              "type": "string"
            }
          },
          "required": [
            "arg1"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "startLesson",
        "description": "",
        "parameters": {
          "type": "object",
          "properties": {},
          "required": []
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "finishLesson",
        "description": "",
        "parameters": {
          "type": "object",
          "properties": {},
          "required": []
        }
      }
    }
  ]
}

To Reproduce
Return an error from a tool call, so that LLM needs to retry.

Expected behavior
Text content should not be lost.

Please complete the following information:

  • LangChain4j version: 0.30.0
  • LLM(s) used: openai
  • Java version: 21
@langchain4j langchain4j added bug Something isn't working P3 Medium priority labels Apr 19, 2024
hrhrng added a commit to hrhrng/langchain4j that referenced this issue May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P3 Medium priority
Projects
None yet
Development

No branches or pull requests

1 participant