Files
yawan f7fc992f57
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

87 lines
2.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package provider
import (
"fmt"
"strings"
"github.com/Tencent/WeKnora/internal/types"
)
const (
OpenAIBaseURL = "https://api.openai.com/v1"
)
// OpenAIProvider 实现 OpenAI 的 Provider 接口
type OpenAIProvider struct{}
func init() {
Register(&OpenAIProvider{})
}
// Info 返回 OpenAI provider 的元数据
func (p *OpenAIProvider) Info() ProviderInfo {
return ProviderInfo{
Name: ProviderOpenAI,
DisplayName: "OpenAI",
Description: "gpt-5.2, gpt-5-mini, etc.",
DefaultURLs: map[types.ModelType]string{
types.ModelTypeKnowledgeQA: OpenAIBaseURL,
types.ModelTypeEmbedding: OpenAIBaseURL,
types.ModelTypeRerank: OpenAIBaseURL,
types.ModelTypeVLLM: OpenAIBaseURL,
types.ModelTypeASR: OpenAIBaseURL,
},
ModelTypes: []types.ModelType{
types.ModelTypeKnowledgeQA,
types.ModelTypeEmbedding,
types.ModelTypeRerank,
types.ModelTypeVLLM,
types.ModelTypeASR,
},
RequiresAuth: true,
}
}
// ValidateConfig 验证 OpenAI provider 配置
func (p *OpenAIProvider) ValidateConfig(config *Config) error {
if config.APIKey == "" {
return fmt.Errorf("API key is required for OpenAI provider")
}
if config.ModelName == "" {
return fmt.Errorf("model name is required")
}
return nil
}
// IsOpenAIReasoningOrGPT5Model 判断模型是否为 OpenAI / Azure OpenAI 的
// 推理类(o-series)或 GPT-5 系列模型。
//
// 这些模型在 OpenAI Chat Completions API 中:
// - 不再支持 `max_tokens`,必须使用 `max_completion_tokens`;
// - 仅支持默认的 `temperature=1`、`top_p=1`,且不支持 `frequency_penalty` /
// `presence_penalty` 等采样参数(传非默认值会被拒绝)。
//
// 参考:
// - https://platform.openai.com/docs/api-reference/chat
// - https://learn.microsoft.com/azure/ai-services/openai/how-to/reasoning
//
// 仅基于模型名做启发式匹配;对于 Azure OpenAI,因为模型名实际上是 deployment 名,
// 用户若用了自定义部署名我们无法识别,此时仍会按普通模型处理(保持原行为)。
func IsOpenAIReasoningOrGPT5Model(modelName string) bool {
name := strings.ToLower(strings.TrimSpace(modelName))
if name == "" {
return false
}
if strings.HasPrefix(name, "gpt-5") {
return true
}
// o1 / o1-mini / o1-preview / o3 / o3-mini / o4-mini ...
// 必须精确匹配,避免误命中 "openai-..." 之类。
for _, prefix := range []string{"o1", "o3", "o4"} {
if name == prefix || strings.HasPrefix(name, prefix+"-") {
return true
}
}
return false
}