mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-12 06:35:44 +08:00
### What problem does this PR solve? Adds the missing Anthropic provider implementation for the Go model provider layer. Closes #14939 ### What changed - Add `conf/models/anthropic.json` with Anthropic Claude chat/vision models and API endpoints. - Add `internal/entity/models/anthropic.go` implementing non-streaming Messages API chat, model listing, and connection checking. - Register `anthropic` in the Go model factory. - Add httptest coverage for headers, payload mapping, response parsing, validation errors, provider errors, model listing, connection checking, factory registration, and unsupported methods. ### Notes Streaming chat is left as an explicit `no such method` follow-up because this initial provider focuses on non-streaming chat and connection checking. ### Tests - `docker run --rm -v /home/ubuntu/Documents/gitTensor_repos/carlos/ragflow:/work -v /tmp/ragflow-go-cache:/go/pkg/mod -v /tmp/ragflow-go-build:/root/.cache/go-build -w /work golang:1.25 go test -vet=off ./internal/entity/models -run Anthropic -count=1 -v` - `docker run --rm -v /home/ubuntu/Documents/gitTensor_repos/carlos/ragflow:/work -v /tmp/ragflow-go-cache:/go/pkg/mod -v /tmp/ragflow-go-build:/root/.cache/go-build -w /work golang:1.25 go test -vet=off ./internal/entity -count=1` - `git diff --check` - `jq . conf/models/anthropic.json >/dev/null` Plain `go test ./internal/entity/models` currently hits pre-existing unrelated vet findings in other provider files (`baidu.go`, `cohere.go`, `fishaudio.go`, `openrouter.go`). --------- Co-authored-by: Jin Hai <haijin.chn@gmail.com>
102 lines
3.2 KiB
Go
102 lines
3.2 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 "anthropic":
|
|
return NewAnthropicModel(baseURL, urlSuffix), nil
|
|
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 "ollama":
|
|
return NewOllamaModel(baseURL, urlSuffix), nil
|
|
case "openai":
|
|
return NewOpenAIModel(baseURL, urlSuffix), nil
|
|
case "nvidia":
|
|
return NewNvidiaModel(baseURL, urlSuffix), nil
|
|
case "openrouter":
|
|
return NewOpenRouterModel(baseURL, urlSuffix), nil
|
|
case "huggingface":
|
|
return NewHuggingFaceModel(baseURL, urlSuffix), nil
|
|
case "baidu":
|
|
return NewBaiduModel(baseURL, urlSuffix), nil
|
|
case "cohere":
|
|
return NewCoHereModel(baseURL, urlSuffix), nil
|
|
case "fishaudio":
|
|
return NewFishAudioModel(baseURL, urlSuffix), nil
|
|
case "mistral":
|
|
return NewMistralModel(baseURL, urlSuffix), nil
|
|
case "upstage":
|
|
return NewUpstageModel(baseURL, urlSuffix), nil
|
|
case "stepfun":
|
|
return NewStepFunModel(baseURL, urlSuffix), nil
|
|
case "baichuan":
|
|
return NewBaichuanModel(baseURL, urlSuffix), nil
|
|
case "jina":
|
|
return NewJinaModel(baseURL, urlSuffix), nil
|
|
case "localai":
|
|
return NewLocalAIModel(baseURL, urlSuffix), nil
|
|
case "longcat":
|
|
return NewLongCatModel(baseURL, urlSuffix), nil
|
|
case "novita":
|
|
return NewNovitaModel(baseURL, urlSuffix), nil
|
|
case "voyage":
|
|
return NewVoyageModel(baseURL, urlSuffix), nil
|
|
case "paddleocr":
|
|
return NewPaddleOCRModel(baseURL, urlSuffix), nil
|
|
default:
|
|
return NewDummyModel(baseURL, urlSuffix), nil
|
|
}
|
|
}
|