Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,76 @@ channels:
- "gemini-pro"
status: 1

- name: "fake-channel-1"
type_name: "fake"
key: "fake-key"
base_url: "https://fake.local/v1"
models:
- "fake-chat"
- "fake-completion"
- "fake-response"
- "fake-anthropic"
- "fake-gemini"
- "fake-embedding"
- "fake-image"
- "fake-rerank"
status: 1
priority: 100
sets:
- "default"
- "debug"
configs:
static_text: "Fake adaptor says hello."
response_prefix: "[debug] "
response_suffix: " <eom>"
reasoning_text: "This result is synthesized locally for testing."
delay_ms: 0
stream_chunks: 4
stream_chunk_size: 8
usage:
input_tokens: 32
output_tokens: 16
cached_tokens: 4
reasoning_tokens: 3
image_input_tokens: 12
image_output_tokens: 64
embedding:
dimensions: 12
base: "fake-embedding-seed"
image:
url: "https://fake.local/assets/fake-image.png"
b64_json: "ZmFrZS1pbWFnZQ=="
revised_prompt: "fake revised prompt"
image_tokens_in: 12
image_tokens_out: 64
rerank:
base_score: 0.98
step: 0.07
return_documents: true
response:
store: true
status: "completed"
parallel_tool_calls: true
anthropic:
stop_reason: "end_turn"
type: "message"
gemini:
finish_reason: "STOP"
model_version: "fake-1.0"
metadata:
environment: "local"
owner: "qa"
openapi:
spec_version: "3.1.0"
info:
title: "Fake Adaptor Template"
version: "1.0.0"
description: "OpenAPI-style config payload for the fake adaptor"
components:
examples:
chat:
summary: "Fake chat response"

# Model Configurations
modelconfigs:
- model: "gpt-4"
Expand Down
80 changes: 80 additions & 0 deletions config.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ You can use either `type_name` (human-readable string) or `type` (numeric code).
- `groq`: Groq
- `mistral`: Mistral AI
- `cohere`: Cohere
- `fake`: Local fake adaptor for protocol simulation and integration testing
- `openrouter`: OpenRouter
- And many more... (see `core/model/yaml_integration.go` for the complete list)

Expand All @@ -87,8 +88,87 @@ You can use either `type_name` (human-readable string) or `type` (numeric code).
- `3`: Azure
- `14`: Anthropic/Claude
- `24`: Google Gemini
- `53`: Fake adaptor
- See `core/model/chtype.go` for complete list

### Fake Adaptor Example

The `fake` channel type is intended for local protocol verification, end-to-end integration tests, demos, and front-end development without calling any upstream provider. It synthesizes responses for:

- OpenAI `chat/completions`
- OpenAI `completions`
- OpenAI `responses` and related sub-APIs
- Anthropic native `/messages`
- Gemini native `/models/*:generateContent`
- `embeddings`
- `images/generations`
- `rerank`

Example YAML:

```yaml
channels:
- name: "fake-debug"
type_name: "fake"
key: "fake-key"
models:
- "fake-chat"
- "fake-response"
- "fake-gemini"
- "fake-anthropic"
- "fake-embedding"
- "fake-image"
- "fake-rerank"
configs:
static_text: "Fake adaptor says hello."
response_prefix: "[debug] "
response_suffix: " <eom>"
reasoning_text: "Synthesized locally."
stream_chunks: 4
usage:
input_tokens: 32
output_tokens: 16
cached_tokens: 4
reasoning_tokens: 3
embedding:
dimensions: 12
image:
url: "https://fake.local/assets/fake-image.png"
b64_json: "ZmFrZS1pbWFnZQ=="
rerank:
base_score: 0.98
step: 0.07
response:
store: true
status: "completed"
anthropic:
stop_reason: "end_turn"
gemini:
finish_reason: "STOP"
metadata:
environment: "local"
openapi:
spec_version: "3.1.0"
info:
title: "Fake Adaptor Template"
version: "1.0.0"
```

#### Fake Adaptor Config Keys

- `static_text`: Main synthesized output text for chat/completion/responses/anthropic/gemini.
- `response_prefix` / `response_suffix`: Wrap synthesized text.
- `reasoning_text`: Summary inserted into Responses API reasoning output.
- `delay_ms`: Artificial latency in milliseconds.
- `stream_chunks` / `stream_chunk_size`: Control streaming segmentation.
- `usage.*`: Override input, output, cached, reasoning, and image token counts.
- `embedding.dimensions`: Output vector dimensions.
- `image.url` / `image.b64_json`: Fake image payload.
- `rerank.base_score` / `rerank.step`: Fake rerank score template.
- `response.store`: Whether fake Responses API objects should be pinned into the internal store for subsequent `GET /responses/{id}` style calls.
- `metadata`: Arbitrary metadata copied into fake Responses API objects.
- `openapi.*`: OpenAPI-style templating section for documenting or versioning fake channel config payloads.

### 2. Model Configurations

Define model-specific settings:
Expand Down
11 changes: 2 additions & 9 deletions core/model/chtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
ChannelTypeSangforAICP ChannelType = 50
ChannelTypeStreamlake ChannelType = 51
ChannelTypeZhipuCoding ChannelType = 52
ChannelTypeFake ChannelType = 53
)

var channelTypeNames = map[ChannelType]string{
Expand Down Expand Up @@ -95,13 +96,5 @@ var channelTypeNames = map[ChannelType]string{
ChannelTypeSangforAICP: "Sangfor AICP",
ChannelTypeStreamlake: "Streamlake",
ChannelTypeZhipuCoding: "zhipu coding",
}

func AllChannelTypes() []ChannelType {
types := make([]ChannelType, 0, len(channelTypeNames))
for t := range channelTypeNames {
types = append(types, t)
}

return types
ChannelTypeFake: "fake",
}
1 change: 1 addition & 0 deletions core/model/yaml_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func ChannelTypeNameToType(typeName string) int {
"streamlake": 51,
"zhipu coding": 52,
"zhipucoding": 52,
"fake": 53,
}

if typ, ok := typeMap[typeName]; ok {
Expand Down
6 changes: 6 additions & 0 deletions core/relay/adaptor/ai360/adaptor.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package ai360

import (
"github.com/labring/aiproxy/core/model"
"github.com/labring/aiproxy/core/relay/adaptor"
"github.com/labring/aiproxy/core/relay/adaptor/openai"
"github.com/labring/aiproxy/core/relay/adaptor/registry"
)

type Adaptor struct {
openai.Adaptor
}

func init() {
registry.Register(model.ChannelTypeAI360, &Adaptor{})
}

const baseURL = "https://ai.360.cn/v1"

func (a *Adaptor) DefaultBaseURL() string {
Expand Down
6 changes: 6 additions & 0 deletions core/relay/adaptor/ali/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"net/url"

"github.com/gin-gonic/gin"
"github.com/labring/aiproxy/core/model"
"github.com/labring/aiproxy/core/relay/adaptor"
"github.com/labring/aiproxy/core/relay/adaptor/anthropic"
"github.com/labring/aiproxy/core/relay/adaptor/openai"
"github.com/labring/aiproxy/core/relay/adaptor/registry"
"github.com/labring/aiproxy/core/relay/meta"
"github.com/labring/aiproxy/core/relay/mode"
relaymodel "github.com/labring/aiproxy/core/relay/model"
Expand All @@ -19,6 +21,10 @@ import (

type Adaptor struct{}

func init() {
registry.Register(model.ChannelTypeAli, &Adaptor{})
}

const baseURL = "https://dashscope.aliyuncs.com"

func (a *Adaptor) DefaultBaseURL() string {
Expand Down
6 changes: 6 additions & 0 deletions core/relay/adaptor/anthropic/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (

"github.com/bytedance/sonic"
"github.com/gin-gonic/gin"
"github.com/labring/aiproxy/core/model"
"github.com/labring/aiproxy/core/relay/adaptor"
"github.com/labring/aiproxy/core/relay/adaptor/registry"
"github.com/labring/aiproxy/core/relay/meta"
"github.com/labring/aiproxy/core/relay/mode"
relaymodel "github.com/labring/aiproxy/core/relay/model"
Expand All @@ -20,6 +22,10 @@ import (

type Adaptor struct{}

func init() {
registry.Register(model.ChannelTypeAnthropic, &Adaptor{})
}

const baseURL = "https://api.anthropic.com/v1"

func (a *Adaptor) DefaultBaseURL() string {
Expand Down
5 changes: 5 additions & 0 deletions core/relay/adaptor/aws/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import (
"github.com/labring/aiproxy/core/model"
"github.com/labring/aiproxy/core/relay/adaptor"
"github.com/labring/aiproxy/core/relay/adaptor/aws/utils"
"github.com/labring/aiproxy/core/relay/adaptor/registry"
"github.com/labring/aiproxy/core/relay/meta"
"github.com/labring/aiproxy/core/relay/mode"
relaymodel "github.com/labring/aiproxy/core/relay/model"
)

type Adaptor struct{}

func init() {
registry.Register(model.ChannelTypeAWS, &Adaptor{})
}

func (a *Adaptor) DefaultBaseURL() string {
return ""
}
Expand Down
6 changes: 6 additions & 0 deletions core/relay/adaptor/azure/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"strings"

"github.com/gin-gonic/gin"
"github.com/labring/aiproxy/core/model"
"github.com/labring/aiproxy/core/relay/adaptor"
"github.com/labring/aiproxy/core/relay/adaptor/openai"
"github.com/labring/aiproxy/core/relay/adaptor/registry"
"github.com/labring/aiproxy/core/relay/meta"
"github.com/labring/aiproxy/core/relay/mode"
)
Expand All @@ -19,6 +21,10 @@ type Adaptor struct {
openai.Adaptor
}

func init() {
registry.Register(model.ChannelTypeAzure, &Adaptor{})
}

func (a *Adaptor) DefaultBaseURL() string {
return "https://{resource_name}.openai.azure.com"
}
Expand Down
6 changes: 6 additions & 0 deletions core/relay/adaptor/azure2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/labring/aiproxy/core/model"
"github.com/labring/aiproxy/core/relay/adaptor"
"github.com/labring/aiproxy/core/relay/adaptor/azure"
"github.com/labring/aiproxy/core/relay/adaptor/openai"
"github.com/labring/aiproxy/core/relay/adaptor/registry"
"github.com/labring/aiproxy/core/relay/meta"
)

type Adaptor struct {
azure.Adaptor
}

func init() {
registry.Register(model.ChannelTypeAzure2, &Adaptor{})
}

func (a *Adaptor) GetRequestURL(
meta *meta.Meta,
_ adaptor.Store,
Expand Down
6 changes: 6 additions & 0 deletions core/relay/adaptor/baichuan/adaptor.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package baichuan

import (
"github.com/labring/aiproxy/core/model"
"github.com/labring/aiproxy/core/relay/adaptor"
"github.com/labring/aiproxy/core/relay/adaptor/openai"
"github.com/labring/aiproxy/core/relay/adaptor/registry"
)

type Adaptor struct {
openai.Adaptor
}

func init() {
registry.Register(model.ChannelTypeBaichuan, &Adaptor{})
}

const baseURL = "https://api.baichuan-ai.com/v1"

func (a *Adaptor) DefaultBaseURL() string {
Expand Down
6 changes: 6 additions & 0 deletions core/relay/adaptor/baidu/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"strings"

"github.com/gin-gonic/gin"
"github.com/labring/aiproxy/core/model"
"github.com/labring/aiproxy/core/relay/adaptor"
"github.com/labring/aiproxy/core/relay/adaptor/openai"
"github.com/labring/aiproxy/core/relay/adaptor/registry"
"github.com/labring/aiproxy/core/relay/meta"
"github.com/labring/aiproxy/core/relay/mode"
relaymodel "github.com/labring/aiproxy/core/relay/model"
Expand All @@ -18,6 +20,10 @@ import (

type Adaptor struct{}

func init() {
registry.Register(model.ChannelTypeBaidu, &Adaptor{})
}

const (
baseURL = "https://aip.baidubce.com"
)
Expand Down
6 changes: 6 additions & 0 deletions core/relay/adaptor/baiduv2/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"strings"

"github.com/gin-gonic/gin"
"github.com/labring/aiproxy/core/model"
"github.com/labring/aiproxy/core/relay/adaptor"
"github.com/labring/aiproxy/core/relay/adaptor/openai"
"github.com/labring/aiproxy/core/relay/adaptor/registry"
"github.com/labring/aiproxy/core/relay/meta"
"github.com/labring/aiproxy/core/relay/mode"
relaymodel "github.com/labring/aiproxy/core/relay/model"
Expand All @@ -18,6 +20,10 @@ import (

type Adaptor struct{}

func init() {
registry.Register(model.ChannelTypeBaiduV2, &Adaptor{})
}

const (
baseURL = "https://qianfan.baidubce.com/v2"
)
Expand Down
Loading
Loading