mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-02 16:55:42 +08:00
### What problem does this PR solve? The OpenAI Go driver landed in #14605 with chat, list models, and check connection. Encode was left as a stub that returns \`not implemented\`. \`conf/models/openai.json\` already lists three embedding models out of the box: - text-embedding-ada-002 - text-embedding-3-small - text-embedding-3-large So a tenant who picked one of these in the Go layer could not actually run an embedding call. This PR fills the gap. ### What this PR includes - \`conf/models/openai.json\`: add \`\"embedding\": \"embeddings\"\` under \`url_suffix\` so the driver can build the URL from config. This matches the \`URLSuffix.Embedding\` field used by other drivers (siliconflow, zhipu-ai). - \`internal/entity/models/openai.go\`: replace the Encode stub with a real implementation that POSTs to \`/v1/embeddings\`. Adds a small local response type \`openaiEmbeddingResponse\`. No factory change. No interface change. ### How the implementation works - Validate \`apiConfig\` and the API key, validate the model name. Use the existing \`baseURLForRegion\` helper so an unknown region fails fast with a clear error. - Wrap the request with \`context.WithTimeout(nonStreamCallTimeout)\` so the call has a clear deadline. Same pattern as \`ChatWithMessages\` and \`ListModels\` already use in this file. - Send all input texts in one request. The OpenAI API accepts the \`input\` field as an array. - Parse \`data[*].embedding\` and copy each slice into a \`[][]float64\` indexed by \`data[*].index\` so the output order matches the input order even if the API returns items in a different order. - Handle both \`float64\` and \`float32\` element types, the way the SiliconFlow driver does. - An empty input slice returns \`[][]float64{}\` with no HTTP call. - Non-200 responses propagate the upstream status line and body. - A final pass checks that every input slot got a vector. If any slot is still nil, return a clear error so the caller does not silently use a zero vector. ### 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. - The full method set on \`OpenAIModel\` still matches the \`ModelDriver\` interface. - Pattern parity with the existing SiliconFlow Encode implementation (\`internal/entity/models/siliconflow.go\`). Closes #14629 --------- Co-authored-by: Jin Hai <haijin.chn@gmail.com>
195 lines
3.2 KiB
JSON
195 lines
3.2 KiB
JSON
{
|
|
"name": "OpenAI",
|
|
"url": {
|
|
"default": "https://api.openai.com/v1"
|
|
},
|
|
"url_suffix": {
|
|
"chat": "chat/completions",
|
|
"models": "models",
|
|
"embedding": "embeddings"
|
|
},
|
|
"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"
|
|
]
|
|
}
|
|
]
|
|
} |