quarkiverse / quarkus-langchain4j

Quarkus Langchain4j extension
https://docs.quarkiverse.io/quarkus-langchain4j/dev/index.html
Apache License 2.0
127 stars 73 forks source link

@Tool class not invoked in 0.9.1 #383

Open lordofthejars opened 5 months ago

lordofthejars commented 5 months ago

Hi I have the following example https://github.com/lordofthejars/quarkus-langchain-examples/tree/main/email-a-poem

It's the email in the poem example, but I am using DevServices to send the email.

If I use version 0.5.0, everything works as expected, the poem is generated, and the email tool is invoked. But with just a "simple" change updating to 0.9.1, now the email tool is not invoked even though ChatGPT is not returning that it cannot send an email.

I have not debugged it, so I don't know if the problem is in Quarkus, in Langchain4J, or in the extension.

It seems like @Tool was not registered. The good news is that it is easily reproducible; take my example and update the version to 0.9.1.

(I also tried the email the poem example from the SNAPSHOT current version, and I couldn't see the log lines of sending the email so I assumed it is a bug on the version).

geoand commented 5 months ago

I could not reproduce the problem with https://github.com/quarkiverse/quarkus-langchain4j/tree/0.9.1/samples/email-a-poem

lordofthejars commented 5 months ago

Ok, so why does 0.5.0 work in my example and 0.9.1 not? It was curious to me to discover this.

geoand commented 5 months ago

No idea :)

geoand commented 5 months ago

Is this still a problem with 0.10.1?

lordofthejars commented 5 months ago

I am going to try

lordofthejars commented 5 months ago

No, it is not working; Tool seems to send correctly function information to chatgpt but nothing is invoked back:

2024-03-28 09:16:51,324 INFO  [io.qua.lan.ope.OpenAiRestApi$OpenAiClientLogger] (vert.x-eventloop-thread-1) Request:
- method: POST
- url: http://langchain4j.dev/demo/openai/v1/chat/completions
- headers: [Accept: application/json], [Authorization: Bearer demo], [Content-Type: application/json], [User-Agent: langchain4j-openai], [content-length: 497]
- body: {"model":"gpt-3.5-turbo","messages":[{"role":"system","content":"You are a professional poet"},{"role":"user","content":"Write a poem about Quarkus. The poem should be 4 lines long. Then send this poem by email."}],"temperature":1.0,"top_p":1.0,"presence_penalty":0.0,"frequency_penalty":0.0,"tools":[{"type":"function","function":{"name":"sendAnEmail","description":"send given content by email","parameters":{"type":"object","properties":{"content":{"type":"string"}},"required":["content"]}}}]}

2024-03-28 09:16:52,660 INFO  [io.qua.lan.ope.OpenAiRestApi$OpenAiClientLogger] (vert.x-eventloop-thread-1) Response:
- status code: 200
- headers: [Date: Thu, 28 Mar 2024 08:16:51 GMT], [Content-Type: text/html;charset=utf-8], [Transfer-Encoding: chunked], [Server: Jetty(9.4.48.v20220622)]
- body: {"id":"chatcmpl-97fEJMEE0LING0xTCBZwpcQDJJxuS","created":1711613811,"model":"gpt-3.5-turbo-0125","choices":[{"index":0,"message":{"role":"assistant","content":"In the land of Quarkus, magic lights do gleam,\nWhere dreams take flight and reality may seem\nA wondrous place where fantasies align,\nIn Quarkus, the heart will always find its prime."},"finish_reason":"stop"}],"usage":{"prompt_tokens":40,"completion_tokens":44,"total_tokens":84}}
kdubois commented 3 months ago

@geoand I am able to reproduce the issue @lordofthejars reported, even in the latest 0.13.1 version.

I used the sample from https://github.com/quarkiverse/quarkus-langchain4j/tree/main/samples/email-a-poem

with quarkus.langchain4j.openai.api-key=demo

geoand commented 3 months ago

I tried it again and I still could not reproduce the problem

geoand commented 3 months ago

After talking to @kdubois we figured out that the problem is the use of the demo key. When this is used, a fake OpenAI REST API is hit which apparently does not work with tools.

kdubois commented 3 months ago

FYI looks like there's an open issue in the LangChain4j project for this : https://github.com/langchain4j/langchain4j/issues/927