mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-11-10 21:32:43 +08:00
feat: add AI Stupid Level as a model provider (#21185)
This commit is contained in:
1 parent
8113fdbc2a
commit
e2afaaf3bb
9 files changed
+306
No files matched your search
@@ -3491,6 +3491,14 @@
|
||||
"llm": [],
|
||||
"url": "https://api.trustedrouter.com/v1"
|
||||
},
|
||||
{
|
||||
"name": "AI Stupid Level",
|
||||
"logo": "",
|
||||
"tags": "LLM",
|
||||
"status": "1",
|
||||
"llm": [],
|
||||
"url": "https://aistupidlevel.info/v1"
|
||||
},
|
||||
{
|
||||
"name": "Demon Route",
|
||||
"logo": "",
|
||||
|
||||
@@ -197,6 +197,7 @@ The following providers are **aggregators** — they host models from multiple u
|
||||
| **TogetherAI** | Open-source model hosting |
|
||||
| **TokenHub** | Multi-provider aggregator |
|
||||
| **TrustedRouter** | OpenAI-compatible router |
|
||||
| **AI Stupid Level** | Benchmark-based router (routes each request to the best-scoring model, with your own provider keys) |
|
||||
| **TokenPony** | Multi-provider aggregator |
|
||||
| **Volcengine (Doubao)** | ByteDance's cloud (hosts Doubao + third-party) |
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
{
|
||||
"name": "AI Stupid Level",
|
||||
"url": {
|
||||
"default": "https://aistupidlevel.info/v1"
|
||||
},
|
||||
"url_suffix": {
|
||||
"chat": "chat/completions",
|
||||
"models": "models"
|
||||
},
|
||||
"class": "aistupidlevel",
|
||||
"models": [
|
||||
{
|
||||
"name": "auto-coding",
|
||||
"context_length": 262144,
|
||||
"model_types": [
|
||||
"chat"
|
||||
],
|
||||
"tools": {
|
||||
"support": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "auto-reasoning",
|
||||
"context_length": 262144,
|
||||
"model_types": [
|
||||
"chat"
|
||||
],
|
||||
"tools": {
|
||||
"support": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "auto-tooling",
|
||||
"context_length": 262144,
|
||||
"model_types": [
|
||||
"chat"
|
||||
],
|
||||
"tools": {
|
||||
"support": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "auto-best",
|
||||
"context_length": 262144,
|
||||
"model_types": [
|
||||
"chat"
|
||||
],
|
||||
"tools": {
|
||||
"support": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "auto-task",
|
||||
"context_length": 262144,
|
||||
"model_types": [
|
||||
"chat"
|
||||
],
|
||||
"tools": {
|
||||
"support": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "auto-value",
|
||||
"context_length": 262144,
|
||||
"model_types": [
|
||||
"chat"
|
||||
],
|
||||
"tools": {
|
||||
"support": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "auto-value-coding",
|
||||
"context_length": 262144,
|
||||
"model_types": [
|
||||
"chat"
|
||||
],
|
||||
"tools": {
|
||||
"support": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "auto-fastest-quality",
|
||||
"context_length": 262144,
|
||||
"model_types": [
|
||||
"chat"
|
||||
],
|
||||
"tools": {
|
||||
"support": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
// AIStupidLevelModel drives AI Stupid Level's Smart Router, an OpenAI-compatible
|
||||
// router (https://aistupidlevel.info/v1) whose model ids are routing modes such as
|
||||
// "auto-coding" or "auto-value", or real model ids that pin one model. Each request
|
||||
// goes to the model that currently scores best on its continuously re-run benchmarks,
|
||||
// called with the user's own provider keys, so the embedded OpenAIAPICompatibleModel
|
||||
// covers every call.
|
||||
type AIStupidLevelModel struct {
|
||||
*OpenAIAPICompatibleModel
|
||||
}
|
||||
|
||||
// NewAIStupidLevelModel creates an AI Stupid Level driver.
|
||||
func NewAIStupidLevelModel(baseURL map[string]string, urlSuffix URLSuffix) *AIStupidLevelModel {
|
||||
return &AIStupidLevelModel{
|
||||
OpenAIAPICompatibleModel: NewOpenAIAPICompatibleModel(baseURL, urlSuffix),
|
||||
}
|
||||
}
|
||||
|
||||
// Name returns the driver name.
|
||||
func (m *AIStupidLevelModel) Name() string {
|
||||
return "aistupidlevel"
|
||||
}
|
||||
|
||||
// NewInstance returns a driver bound to the given base URL.
|
||||
func (m *AIStupidLevelModel) NewInstance(baseURL map[string]string) ModelDriver {
|
||||
return NewAIStupidLevelModel(baseURL, m.baseModel.URLSuffix)
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// 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 (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"ragflow/internal/common"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// newAIStupidLevelForTest creates an AIStupidLevelModel instance for testing.
|
||||
func newAIStupidLevelForTest(baseURL string) *AIStupidLevelModel {
|
||||
return NewAIStupidLevelModel(
|
||||
map[string]string{"default": baseURL},
|
||||
URLSuffix{Chat: "chat/completions", Models: "models"},
|
||||
)
|
||||
}
|
||||
|
||||
// TestAIStupidLevelName tests the driver name.
|
||||
func TestAIStupidLevelName(t *testing.T) {
|
||||
if got := newAIStupidLevelForTest("http://unused").Name(); got != "aistupidlevel" {
|
||||
t.Errorf("Name()=%q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAIStupidLevelFactory tests creating the driver from the factory by the provider name.
|
||||
func TestAIStupidLevelFactory(t *testing.T) {
|
||||
driver, err := NewModelFactory().CreateModelDriver("AI Stupid Level", map[string]string{"default": "http://unused"}, URLSuffix{})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateModelDriver: %v", err)
|
||||
}
|
||||
if _, ok := driver.(*AIStupidLevelModel); !ok {
|
||||
t.Fatalf("driver type=%T, want *AIStupidLevelModel", driver)
|
||||
}
|
||||
if _, ok := driver.NewInstance(map[string]string{"default": "http://other"}).(*AIStupidLevelModel); !ok {
|
||||
t.Fatal("NewInstance did not return *AIStupidLevelModel")
|
||||
}
|
||||
}
|
||||
|
||||
// The shipped config must resolve to the AI Stupid Level driver: CreateModelDriver
|
||||
// dispatches on strings.ToLower(name), so "AI Stupid Level" has to match the
|
||||
// "ai stupid level" case; anything else silently falls through to DummyModel.
|
||||
func TestAIStupidLevelProviderConfig(t *testing.T) {
|
||||
dir, restore := setupProviderTestDir(t, "aistupidlevel.json")
|
||||
defer restore()
|
||||
|
||||
if err := InitProviderManager(dir); err != nil {
|
||||
t.Fatalf("InitProviderManager: %v", err)
|
||||
}
|
||||
|
||||
provider := GetProviderManager().FindProvider("AI Stupid Level")
|
||||
if provider == nil {
|
||||
t.Fatal("AI Stupid Level provider not found")
|
||||
}
|
||||
if _, ok := provider.ModelDriver.(*AIStupidLevelModel); !ok {
|
||||
t.Fatalf("ModelDriver=%T, want *models.AIStupidLevelModel", provider.ModelDriver)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAIStupidLevelChatSendsAPIKey tests chat authentication and that the routing
|
||||
// mode reaches the API unchanged as the model id.
|
||||
func TestAIStupidLevelChatSendsAPIKey(t *testing.T) {
|
||||
withSSRFBypass(t)
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/chat/completions" {
|
||||
t.Errorf("path=%s", r.URL.Path)
|
||||
}
|
||||
if got := r.Header.Get("Authorization"); got != "Bearer sk-gw-test" {
|
||||
t.Errorf("Authorization=%q", got)
|
||||
}
|
||||
var body struct {
|
||||
Model string `json:"model"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
t.Errorf("decode request: %v", err)
|
||||
}
|
||||
if body.Model != "auto-coding" {
|
||||
t.Errorf("model=%q", body.Model)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"id": "chat-aistupidlevel",
|
||||
"model": "claude-opus-5-5",
|
||||
"choices": []map[string]any{{"message": map[string]any{"content": "pong"}}},
|
||||
"usage": map[string]any{"prompt_tokens": 3, "completion_tokens": 5, "total_tokens": 8},
|
||||
})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
usage := &common.ModelUsage{}
|
||||
resp, err := newAIStupidLevelForTest(srv.URL).ChatWithMessages(
|
||||
t.Context(),
|
||||
"auto-coding",
|
||||
[]Message{{Role: "user", Content: "ping"}},
|
||||
&APIConfig{ApiKey: &testAPIKey},
|
||||
nil,
|
||||
usage,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("ChatWithMessages: %v", err)
|
||||
}
|
||||
if *resp.Answer != "pong" {
|
||||
t.Errorf("Answer=%q", *resp.Answer)
|
||||
}
|
||||
assertModelUsage(t, usage, 3, 5, 8)
|
||||
}
|
||||
|
||||
// TestAIStupidLevelListModelsAndCheckConnection tests model listing and the connectivity check.
|
||||
func TestAIStupidLevelListModelsAndCheckConnection(t *testing.T) {
|
||||
withSSRFBypass(t)
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet || r.URL.Path != "/models" {
|
||||
t.Errorf("%s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"data": []map[string]any{
|
||||
{"id": "auto-coding"},
|
||||
{"id": "claude-opus-5-5"},
|
||||
},
|
||||
})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
model := newAIStupidLevelForTest(srv.URL)
|
||||
list, err := model.ListModels(t.Context(), &APIConfig{ApiKey: &testAPIKey})
|
||||
if err != nil {
|
||||
t.Fatalf("ListModels: %v", err)
|
||||
}
|
||||
if joinModelNames(list, ",") != "auto-coding,claude-opus-5-5" {
|
||||
t.Errorf("models=%v", list)
|
||||
}
|
||||
if err := model.CheckConnection(t.Context(), &APIConfig{ApiKey: &testAPIKey}); err != nil {
|
||||
t.Fatalf("CheckConnection: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,8 @@ func (f *ModelFactory) CreateModelDriver(providerName string, baseURL map[string
|
||||
return NewDemonRouteModel(baseURL, urlSuffix), nil
|
||||
case "trustedrouter":
|
||||
return NewTrustedRouterModel(baseURL, urlSuffix), nil
|
||||
case "ai stupid level":
|
||||
return NewAIStupidLevelModel(baseURL, urlSuffix), nil
|
||||
case "novitaai":
|
||||
return NewNovitaModel(baseURL, urlSuffix), nil
|
||||
case "avian":
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -297.0 754 754">
|
||||
<path fill="#005DFB" fill-rule="evenodd" d="M1.0 159.2C1.0 158.4 23.9 133.0 101.0 48.0C112.7 35.1 127.3 19.0 133.4 12.3L144.5 0.0L165.7 0.0L187.0 0.0L226.7 79.4C248.6 123.1 266.2 159.1 265.9 159.4C265.6 159.8 226.2 159.9 178.4 159.8L91.5 159.5L108.3 141.9L125.0 124.2L152.8 124.4C168.0 124.5 183.5 124.3 187.2 124.0L193.8 123.5L176.4 88.0C166.9 68.5 158.7 52.5 158.3 52.5C157.8 52.5 144.7 66.4 129.1 83.5C113.4 100.6 97.5 117.9 93.6 122.0C89.7 126.1 80.3 136.4 72.7 144.8L58.8 160.0L29.9 160.0C14.0 160.0 1.0 159.7 1.0 159.2ZM277.9 155.8C276.7 153.4 272.7 145.6 268.9 138.4L262.0 125.3L266.3 124.7C268.6 124.4 305.4 124.2 348.1 124.2C404.3 124.3 426.6 124.0 429.1 123.1C433.2 121.8 438.4 116.7 439.9 112.7C441.9 107.4 441.3 101.6 438.4 98.9L435.8 96.5L362.2 95.9C297.8 95.5 287.8 95.2 283.1 93.8C268.5 89.3 257.4 80.6 252.4 69.7C250.1 64.8 249.5 61.7 249.2 54.7C248.5 38.8 253.6 26.7 265.5 15.8C270.0 11.6 283.0 5.2 291.7 2.8C299.4 0.6 300.2 0.6 399.3 0.2L499.1 -0.1L498.8 3.8C498.5 7.3 497.0 9.4 484.5 22.8L470.5 37.9L390.7 38.0C303.1 38.0 306.3 37.8 302.7 43.9C301.8 45.5 301.0 48.7 301.0 51.0C301.0 54.4 301.6 55.7 304.0 58.0C305.6 59.5 308.4 61.0 310.1 61.4C311.8 61.7 345.9 62.0 385.9 62.0C431.2 62.0 460.1 62.4 462.9 63.1C474.5 65.7 485.2 73.8 489.2 82.8C492.1 89.2 492.7 100.5 490.6 109.5C487.7 121.7 482.7 130.5 473.6 139.5C464.4 148.7 455.7 153.8 443.3 157.2C435.6 159.4 434.1 159.4 357.8 159.8L280.1 160.1L277.9 155.8Z"/>
|
||||
<path fill="#001961" fill-rule="evenodd" d="M499.4 155.8C500.1 151.5 519.8 53.1 526.8 19.0L530.7 0.5L557.0 0.2C571.5 0.1 583.7 0.3 584.0 0.7C584.4 1.2 582.9 10.5 580.8 21.5C567.8 89.0 561.3 123.6 561.6 123.9C561.9 124.2 604.8 124.5 657.2 124.7C709.5 124.8 752.4 125.1 752.6 125.3C752.8 125.5 744.7 133.3 734.7 142.8L716.5 159.9L607.6 160.0L498.7 160.0L499.4 155.8ZM499.0 3.6C499.0 0.3 499.2 -0.0 502.1 -0.0L505.1 -0.0L503.0 3.0C499.9 7.4 499.0 7.5 499.0 3.6Z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
@@ -120,6 +120,7 @@ const svgIcons = [
|
||||
LLMFactory.Opper,
|
||||
LLMFactory.TrustedRouter,
|
||||
LLMFactory.EmpirioLabs,
|
||||
LLMFactory.AIStupidLevel,
|
||||
];
|
||||
|
||||
export const LlmIcon = ({
|
||||
|
||||
@@ -114,6 +114,7 @@ export enum LLMFactory {
|
||||
DemonRoute = 'Demon Route',
|
||||
TrustedRouter = 'TrustedRouter',
|
||||
EmpirioLabs = 'EmpirioLabs AI',
|
||||
AIStupidLevel = 'AI Stupid Level',
|
||||
}
|
||||
|
||||
// Please lowercase the file name
|
||||
@@ -210,6 +211,7 @@ export const IconMap = {
|
||||
[LLMFactory.Opper]: 'opper',
|
||||
[LLMFactory.TrustedRouter]: 'trustedrouter',
|
||||
[LLMFactory.EmpirioLabs]: 'empiriolabs',
|
||||
[LLMFactory.AIStupidLevel]: 'aistupidlevel',
|
||||
};
|
||||
|
||||
export const ModelTypeToField: Record<string, string> = {
|
||||
@@ -242,6 +244,7 @@ export const APIMapUrl = {
|
||||
[LLMFactory.TrustedRouter]: 'https://trustedrouter.com/keys',
|
||||
[LLMFactory.EmpirioLabs]:
|
||||
'https://platform.empiriolabs.ai/dashboard/api-keys',
|
||||
[LLMFactory.AIStupidLevel]: 'https://aistupidlevel.info/router/keys',
|
||||
[LLMFactory.MWS]:
|
||||
'https://mws.ru/docs/cloud-platform/gpt/general/inference-text.html',
|
||||
[LLMFactory.Anthropic]: 'https://console.anthropic.com/settings/keys',
|
||||
|
||||
Reference in new issue
Block a user