mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-15 09:28:27 +08:00
### 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
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
//
|
|
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
package models
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// ModelFactory creates ModelDriver instances based on provider name
|
|
type ModelFactory struct {
|
|
}
|
|
|
|
// NewModelFactory creates a new ModelFactory
|
|
func NewModelFactory() *ModelFactory {
|
|
return &ModelFactory{}
|
|
}
|
|
|
|
// CreateModelDriver creates a ModelDriver for the given provider and model
|
|
func (f *ModelFactory) CreateModelDriver(providerName string, baseURL map[string]string, urlSuffix URLSuffix) (ModelDriver, error) {
|
|
providerLower := strings.ToLower(providerName)
|
|
switch providerLower {
|
|
case "zhipu-ai":
|
|
return NewZhipuAIModel(baseURL, urlSuffix), nil
|
|
case "deepseek":
|
|
return NewDeepSeekModel(baseURL, urlSuffix), nil
|
|
case "moonshot":
|
|
return NewMoonshotModel(baseURL, urlSuffix), nil
|
|
case "minimax":
|
|
return NewMinimaxModel(baseURL, urlSuffix), nil
|
|
case "gitee":
|
|
return NewGiteeModel(baseURL, urlSuffix), nil
|
|
case "siliconflow":
|
|
return NewSiliconflowModel(baseURL, urlSuffix), nil
|
|
case "google":
|
|
return NewGoogleModel(baseURL, urlSuffix), nil
|
|
case "aliyun":
|
|
return NewAliyunModel(baseURL, urlSuffix), nil
|
|
case "volcengine":
|
|
return NewVolcEngine(baseURL, urlSuffix), nil
|
|
case "vllm":
|
|
return NewVllmModel(baseURL, urlSuffix), nil
|
|
case "xai":
|
|
return NewXAIModel(baseURL, urlSuffix), nil
|
|
case "lmstudio":
|
|
return NewLmStudioModel(baseURL, urlSuffix), nil
|
|
case "openai":
|
|
return NewOpenAIModel(baseURL, urlSuffix), nil
|
|
default:
|
|
return NewDummyModel(baseURL, urlSuffix), nil
|
|
}
|
|
}
|