opensearch-project / ml-commons

ml-commons provides a set of common machine learning algorithms, e.g. k-means, or linear regression, to help developers build ML related features within OpenSearch.
Apache License 2.0
99 stars 136 forks source link

[BUG] need fix #2655 for RAGTool to handle pure json response #3236

Open layavadi opened 6 days ago

layavadi commented 6 days ago

What is the bug?

When connecting to OpenAI model for chat response getting following error while processing the response TransportError(500, '{"error":{"reason":"System Error","details":"Cannot invoke \"org.opensearch.ml.common.output.Output.toXContent(org.opensearch.core.xcontent.XContentBuilder, org.opensearch.core.xcontent.ToXContent$Params)\" because \"this.output\" is null","type":"NullPointerException"},"status":500}', None) This is because issue found in https://github.com/opensearch-project/ml-commons/issues/2654

How can one reproduce the bug?

Same as https://github.com/opensearch-project/ml-commons/issues/2654 where we use the RAGTool to connect openAI using connector with "actions": [ { "action_type": "predict", "method": "POST", "url": "https://${parameters.endpoint}/openai/deployments/${parameters.model}/chat/completions?api-version=${parameters.api_version}", "headers": { "api-key": "${credential.openAI_key}", "Content-type": "application/json" }, "request_body": "{ \"model\": \"${parameters.model}\", \"messages\": [ { \"role\":\"user\" , \"content\": \" ${parameters.prompt} \" } ] }" }

and execute

body = { "parameters": { "question": query } } response_str = "" combined_response = "" try: response = client.http.post(f'/_plugins/_ml/agents/{agent_id}/_execute', body=body)

What is the expected behavior?

It is expected to fetch the response from OpenAI model .

What is your host/environment?

Docker image of OS running on MacOS

Do you have any screenshots?

Getting error while calling the client.http/post

TransportError(500, '{"error":{"reason":"System Error","details":"Cannot invoke \"org.opensearch.ml.common.output.Output.toXContent(org.opensearch.core.xcontent.XContentBuilder, org.opensearch.core.xcontent.ToXContent$Params)\" because \"this.output\" is null","type":"NullPointerException"},"status":500}', None)

Do you have any additional context?

This issue similar to https://github.com/opensearch-project/ml-commons/issues/2654

And needs same fix Earlier for MLTool

https://github.com/opensearch-project/ml-commons/blob/f9cbf15edcf885fa3f64dbb39a467c29604bbc5c/ml-algorithms/src/main/java/org/opensearch/ml/engine/tools/MLModelTool.java#L72

in RAGTool https://github.com/opensearch-project/skills/blob/a95cfaeef88b6e442b9bd05485f128813c3c284e/src/main/java/org/opensearch/agent/tools/RAGTool.java#L91

pyek-bot commented 5 days ago

Hi, Thanks for reporting the bug! Would you like to try and fix it? @layavadi

layavadi commented 5 days ago

Yea. Working on it. My first time. So it is taking bit longer.

Vadi

On Tue, 26 Nov, 2024, 02:27 Pavan Yekbote, @.***> wrote:

Hi, Thanks for reporting the bug! Would you like to try and fix it? @layavadi https://github.com/layavadi

— Reply to this email directly, view it on GitHub https://github.com/opensearch-project/ml-commons/issues/3236#issuecomment-2499017374, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZK35FUPQHO3SGRAD3BY3D2COFMNAVCNFSM6AAAAABSN44UJSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOJZGAYTOMZXGQ . You are receiving this because you were mentioned.Message ID: @.***>

pyek-bot commented 5 days ago

Hi @layavadi, no rush - please take your time. I only wanted to understand if you were working on it so we don't duplicate effort and can assign this issue to you. Next time you start working on an issue, please comment on the issue and one of the maintainers will assign the task to you!

Thank you for your contribution! Appreciate it!

@mingshl Can you assign this to @layavadi please?