channel

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 5 Imported by: 0

README

channel

Provider adaptor implementations for the relay system. Each subdirectory implements one AI provider (OpenAI, Claude, Gemini, etc.) behind the common.Adaptor interface.

Adaptor Interface

Every channel implements common.Adaptor (defined in relay/common/adaptor.go):

type Adaptor interface {
    Init(info *RelayInfo)
    GetRequestURL(info *RelayInfo) (string, error)
    SetupRequestHeader(ctx context.Context, header *http.Header, info *RelayInfo) error
    ConvertOpenAIRequest(ctx, info, request) (any, error)
    ConvertClaudeRequest(ctx, info, request) (any, error)
    ConvertGeminiRequest(ctx, info, request) (any, error)
    ConvertImageRequest(ctx, info, request) (any, error)
    ConvertEmbeddingRequest(ctx, info, request) (any, error)
    ConvertAudioRequest(ctx, info, request) (io.Reader, error)
    ConvertRerankRequest(ctx, relayMode, request) (any, error)
    ConvertOpenAIResponsesRequest(ctx, info, request) (any, error)
    DoRequest(ctx, info, body) (*http.Response, error)
    DoResponse(ctx, resp, info, w) (usage any, err *types.NewAPIError)
    GetModelList() []string
    GetChannelName() string
}

The request flow is: Init -> ConvertXxxRequest -> GetRequestURL -> SetupRequestHeader -> DoRequest -> DoResponse.

Shared Helpers (channel.go)

  • SetupApiRequestHeader -- sets Content-Type and Accept headers.
  • DoApiRequest -- builds and sends a JSON POST to the upstream provider.
  • DoFormRequest -- sends a multipart form request.
  • DoTaskApiRequest -- sends a request for async task adaptors.
  • GetFullRequestURL -- concatenates a base URL and path.

Available Channels

advancedcustom, ai360, ali, aws, baidu, baidu_v2, claude, cloudflare, codex, cohere, coze, deepseek, dify, gemini, huggingface, jimeng, jina, lingyiwanwu, minimax, mistral, mokaai, moonshot, newapi, ollama, openai, openrouter, palm, perplexity, replicate, siliconflow, sub2api, submodel, tencent, vertex, volcengine, xai, xinference, xunfei, zhipu, zhipu_4v.

Adding a New Channel

  1. Create a subdirectory named after the provider (e.g. myprovider/).
  2. Implement common.Adaptor in an adaptor.go or <name>.go file.
  3. Register the adaptor with common.DefaultRegistry.Register(apiType, factory).
  4. Add the channel type constant in relay/constant/channel.go and the API type in relay/constant/api_type.go.
  5. Provide a NewProvider wrapper if the channel should be usable via the high-level relay.Client.
// myprovider/adaptor.go
func New(apiKey string) *Adaptor {
    return &Adaptor{APIKey: apiKey, BaseURL: "https://api.example.com"}
}

Documentation

Overview

Package channel provides shared utilities for provider adaptors. It is adapted from LingRein's pkg/relay/channel top-level package, with gin.Context dependencies removed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoApiRequest

func DoApiRequest(ctx context.Context, a common.Adaptor, info *common.RelayInfo, requestBody io.Reader) (*http.Response, error)

DoApiRequest sends an HTTP request to the upstream provider. This is the library-mode replacement for LingRein's channel.DoApiRequest.

func DoFormRequest

func DoFormRequest(ctx context.Context, a common.Adaptor, info *common.RelayInfo, requestBody io.Reader) (*http.Response, error)

DoFormRequest sends a multipart form request to the upstream provider.

func DoTaskApiRequest

func DoTaskApiRequest(a common.TaskAdaptor, ctx context.Context, info *common.RelayInfo, requestBody io.Reader) (*http.Response, error)

DoTaskApiRequest sends an HTTP request to the upstream provider for an async task adaptor. It is the library-mode replacement for LingRein's channel.DoTaskApiRequest.

func GetFullRequestURL

func GetFullRequestURL(baseURL, requestURL string, channelType int) string

GetFullRequestURL builds a full request URL from a base URL and path.

func SetupApiRequestHeader

func SetupApiRequestHeader(info *common.RelayInfo, header *http.Header)

SetupApiRequestHeader sets common headers for upstream API requests.

Types

This section is empty.

Directories

Path Synopsis
Package claude provides an Anthropic Claude AI provider adaptor.
Package claude provides an Anthropic Claude AI provider adaptor.
Package gemini provides a Google Gemini AI provider adaptor.
Package gemini provides a Google Gemini AI provider adaptor.
Package huggingface provides a HuggingFace Inference Router adaptor.
Package huggingface provides a HuggingFace Inference Router adaptor.
Package openai provides an OpenAI-compatible AI provider adaptor.
Package openai provides an OpenAI-compatible AI provider adaptor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL