etkecc / baibot

🤖 A Matrix bot for using diffent capabilities (text-generation, text-to-speech, speech-to-text, image-generation, etc.) of AI / Large Language Models (OpenAI, Anthropic, etc.)
GNU Affero General Public License v3.0
48 stars 4 forks source link

OpenAI Compatible error #9

Closed mwnu closed 2 months ago

mwnu commented 2 months ago

base_url: http://192.168.1.20:2041/v1

 Error: The provided configuration does not result in a working agent. The following error was encountered when trying to talk to the agent API:
task 18214 panicked with message "called `Result::unwrap()` on an `Err` value: Custom { kind: InvalidData, error: \"Failed to read JSON: expected value at line 1 column 1\" }"```

base_url: https://exampelecom:2042/api/v1

task 17902 panicked with message "called `Result::unwrap()` on an `Err` value: Error(\"missing field `choices`\", line: 0, column: 0)"```

The field validation is overly strict. This is an API provided by my RAG application, which can be used in most applications compatible with the OpenAI API.

spantaleev commented 2 months ago

It appears that some choices field is missing from some API response. Your API is not sufficiently compatible.

The openai_compatible provider is powered by the openai-rs/openai-api library (well, by our fork of it), Our fork does minor improvements - see these open PRs:

It may be possible to fix some issues there, although.. the lack of a choices field in the API response likely indicates that your API is doing something wrong.

You have not told us what your API requests & responses look like and why you think the API is responding in a valid (OpenAI-compatible) manner. You may also wish to report (and/or fix) any potential issue upstream (at the openai-api library's repository or in our fork).

mwnu commented 2 months ago

It appears that some choices field is missing from some API response. Your API is not sufficiently compatible.

The openai_compatible provider is powered by the openai-rs/openai-api library (well, by our fork of it), Our fork does minor improvements - see these open PRs:

It may be possible to fix some issues there, although.. the lack of a choices field in the API response likely indicates that your API is doing something wrong.

You have not told us what your API requests & responses look like and why you think the API is responding in a valid (OpenAI-compatible) manner. You may also wish to report (and/or fix) any potential issue upstream (at the openai-api library's repository or in our fork).

I am using the compatibility API as referenced in this document.

curl --location --request POST 'https://api.tryfastgpt.ai/api/v1/chat/completions' \
--header 'Authorization: Bearer fastgpt-xxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "chatId": "abcd",
    "stream": false,
    "detail": false,
    "variables": {
        "uid": "asdfadsfasfd2323",
        "name": "张三"
    },
    "messages": [
        {
            "content": "导演是谁",
            "role": "user"
        }
    ]
}'
{
    "id": "adsfasf",
    "model": "",
    "usage": {
        "prompt_tokens": 1,
        "completion_tokens": 1,
        "total_tokens": 1
    },
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "电影《铃芽之旅》的导演是新海诚。"
            },
            "finish_reason": "stop",
            "index": 0
        }
    ]
}

In the request body, only the "messages" parameter is necessary, consistent with OpenAI. The "choices" in the response are also basically the same. It seems to be missing the "logprobs" field, which is usually null and not very necessary.

It would be better if a custom model interface could be provided, for example, through a mapping configuration file.

spantaleev commented 2 months ago

Have you tried using https://api.tryfastgpt.ai/api/v1 as your base_url?

Your original error message seemed to indicate you're using some other API URL and that it's the choices field being missing that was causing the problem.

mwnu commented 2 months ago

Have you tried using https://api.tryfastgpt.ai/api/v1 as your base_url?

Your original error message seemed to indicate you're using some other API URL and that it's the choices field being missing that was causing the problem.

Yes, I've tried that. HTTPS, HTTP, domain names, and IP addresses (local addresses) all result in errors. These addresses can all be used to test other AI bot front-ends. However, if I switch to an OpenAI proxy address, it works normally.