2026-04-02 20:20:35 +08:00
|
|
|
//
|
|
|
|
|
// 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
|
2026-04-20 15:31:12 +08:00
|
|
|
func (f *ModelFactory) CreateModelDriver(providerName string, baseURL map[string]string, urlSuffix URLSuffix) (ModelDriver, error) {
|
2026-04-02 20:20:35 +08:00
|
|
|
providerLower := strings.ToLower(providerName)
|
|
|
|
|
switch providerLower {
|
|
|
|
|
case "zhipu-ai":
|
|
|
|
|
return NewZhipuAIModel(baseURL, urlSuffix), nil
|
2026-04-21 16:52:32 +08:00
|
|
|
case "deepseek":
|
|
|
|
|
return NewDeepSeekModel(baseURL, urlSuffix), nil
|
|
|
|
|
case "moonshot":
|
2026-04-21 21:31:50 +08:00
|
|
|
return NewMoonshotModel(baseURL, urlSuffix), nil
|
2026-04-23 10:16:20 +08:00
|
|
|
case "minimax":
|
|
|
|
|
return NewMinimaxModel(baseURL, urlSuffix), nil
|
2026-04-24 20:59:30 +08:00
|
|
|
case "gitee":
|
|
|
|
|
return NewGiteeModel(baseURL, urlSuffix), nil
|
|
|
|
|
case "siliconflow":
|
|
|
|
|
return NewSiliconflowModel(baseURL, urlSuffix), nil
|
2026-04-27 20:35:47 +08:00
|
|
|
case "google":
|
|
|
|
|
return NewGoogleModel(baseURL, urlSuffix), nil
|
2026-04-27 14:53:33 +08:00
|
|
|
case "aliyun":
|
|
|
|
|
return NewAliyunModel(baseURL, urlSuffix), nil
|
2026-04-28 12:12:58 +08:00
|
|
|
case "volcengine":
|
|
|
|
|
return NewVolcEngine(baseURL, urlSuffix), nil
|
2026-04-29 17:05:08 +08:00
|
|
|
case "vllm":
|
|
|
|
|
return NewVllmModel(baseURL, urlSuffix), nil
|
Go: implement provider: xAI (#14550)
Closes #14552
### What problem does this PR solve?
Add a Go driver for xAI (Grok models).
The config file conf/models/xai.json has been in the repo since the
early Go provider work, but internal/entity/models/factory.go had no
case for "xai". So any xAI request fell through to the dummy driver
and never reached the API. This PR adds the missing driver and wires it
up.
### What this PR includes
- New file internal/entity/models/xai.go with an XAIModel that
implements the ModelDriver interface.
- factory.go: route the "xai" provider name to NewXAIModel.
### How the driver works
- xAI exposes an OpenAI-compatible API at https://api.x.ai/v1.
- ChatWithMessages and ChatStreamlyWithSender post to /chat/completions
in the same shape the moonshot and deepseek drivers use.
- ListModels and CheckConnection call /models to confirm the API key
works and to list available model ids.
- reasoning_content is passed through for grok-3-mini and other xAI
reasoning models, both in the non-stream and stream paths.
- Encode, Rerank, and Balance are not part of the public xAI API at the
moment, so they 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 XAIModel matches the ModelDriver interface: NewInstance,
Name, ChatWithMessages, ChatStreamlyWithSender, Encode, Rerank,
ListModels, Balance, CheckConnection.
- Pattern parity with the merged moonshot (#14433), volcengine (#14460),
minimax (#14478), and vllm (#14532) PRs.
---------
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
2026-05-06 06:16:37 +02:00
|
|
|
case "xai":
|
|
|
|
|
return NewXAIModel(baseURL, urlSuffix), nil
|
2026-05-06 19:23:11 +08:00
|
|
|
case "lmstudio":
|
|
|
|
|
return NewLmStudioModel(baseURL, urlSuffix), nil
|
2026-05-07 14:17:57 +08:00
|
|
|
case "nvidia":
|
|
|
|
|
return NewNvidiaModel(baseURL, urlSuffix), nil
|
2026-04-02 20:20:35 +08:00
|
|
|
default:
|
|
|
|
|
return NewDummyModel(baseURL, urlSuffix), nil
|
|
|
|
|
}
|
|
|
|
|
}
|