Files
ragflow/conf/models/openai.json
Panda Dev b8b741555f Go: implement provider: OpenAI (#14605)
### What problem does this PR solve?

Add a Go driver for OpenAI (GPT models).

The config file conf/models/openai.json has been in the repo for a while
with the full GPT-5 model list, but
internal/entity/models/factory.go had no case for "openai". So any
tenant that configured OpenAI as a model provider in the Go layer fell
through to the default branch and got the dummy driver. Chat, list
models, and check connection all returned dummy responses instead of
reaching the API.

OpenAI is the most commonly requested provider and the JSON config
already ships with the repo, so this gap is high impact even though the
JSON has been there for some time.

### What this PR includes

- New file internal/entity/models/openai.go with an OpenAIModel that
implements the ModelDriver interface.
- factory.go: route the "openai" provider name to NewOpenAIModel.
- conf/models/openai.json: add "models": "models" under url_suffix so
ListModels can hit /v1/models with no hardcoded fallback.

### How the driver works

- OpenAI exposes the canonical OpenAI-compatible API at
https://api.openai.com/v1.
- ChatWithMessages and ChatStreamlyWithSender post to /chat/completions
in the same shape the moonshot, vllm, and xai drivers use.
- ListModels and CheckConnection call /models to list available ids and
confirm the API key works.
- reasoning_content is passed through for the o-series and other
reasoning models, in both the non-stream and stream paths.
- Encode (embeddings) is left as "not implemented" for now, the same way
the other recent provider drivers do it. Rerank and Balance are not part
of OpenAI's public API surface in this layer and return a clear "not
implemented" or "no such method" error.

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

### How was this tested?

- go build ./internal/entity/models/... in a clean go 1.25 image (the
go.mod minimum) returns exit 0 with no errors.
- Method set of OpenAIModel matches the ModelDriver interface:
NewInstance, Name, ChatWithMessages, ChatStreamlyWithSender, Encode,
Rerank, ListModels, Balance, CheckConnection.
- Pattern parity with the merged moonshot (#14433), volcengine (#14460),
minimax (#14478), vllm (#14532), xai (#14550), and lm-studio (#14586)
PRs.

Closes #14604
2026-05-07 13:09:51 +08:00

194 lines
3.2 KiB
JSON

{
"name": "OpenAI",
"url": {
"default": "https://api.openai.com/v1"
},
"url_suffix": {
"chat": "chat/completions",
"models": "models"
},
"class": "gpt",
"models": [
{
"name": "gpt-5.2-pro",
"max_tokens": 400000,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-5.2",
"max_tokens": 400000,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-5.1",
"max_tokens": 400000,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-5.1-chat-latest",
"max_tokens": 400000,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-5",
"max_tokens": 400000,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-5-mini",
"max_tokens": 400000,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-5-nano",
"max_tokens": 400000,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-5-chat-latest",
"max_tokens": 400000,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-4.1",
"max_tokens": 1047576,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-4.1-mini",
"max_tokens": 1047576,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-4.1-nano",
"max_tokens": 1047576,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-4.5-preview",
"max_tokens": 128000,
"model_types": [
"chat"
]
},
{
"name": "gpt-4o-mini",
"max_tokens": 128000,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-4o",
"max_tokens": 128000,
"model_types": [
"chat",
"vision"
]
},
{
"name": "gpt-3.5-turbo",
"max_tokens": 4096,
"model_types": [
"chat"
]
},
{
"name": "gpt-3.5-turbo-16k-0613",
"max_tokens": 16385,
"model_types": [
"chat"
]
},
{
"name": "text-embedding-ada-002",
"max_tokens": 8191,
"model_types": [
"embedding"
]
},
{
"name": "text-embedding-3-small",
"max_tokens": 8191,
"model_types": [
"embedding"
]
},
{
"name": "text-embedding-3-large",
"max_tokens": 8191,
"model_types": [
"embedding"
]
},
{
"name": "whisper-1",
"max_tokens": 26214400,
"model_types": [
"asr"
]
},
{
"name": "gpt-4",
"max_tokens": 8191,
"model_types": [
"chat"
]
},
{
"name": "gpt-4-turbo",
"max_tokens": 8191,
"model_types": [
"chat"
]
},
{
"name": "gpt-4-32k",
"max_tokens": 32768,
"model_types": [
"chat"
]
},
{
"name": "tts-1",
"max_tokens": 2048,
"model_types": [
"tts"
]
}
]
}