mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-19 04:40:52 +08:00
feat(translator): add built-in translator registry and helpers
- Introduced `builtin` package exposing a default registry and pipeline for built-in translators. - Added format constants for common schemas (e.g., OpenAI, Gemini, Codex). - Implemented helper functions for schema translation using format name strings. - Provided example usage for integration with translator helpers.
This commit is contained in:
28
sdk/translator/helpers.go
Normal file
28
sdk/translator/helpers.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package translator
|
||||
|
||||
import "context"
|
||||
|
||||
// TranslateRequestByFormatName converts a request payload between schemas by their string identifiers.
|
||||
func TranslateRequestByFormatName(from, to Format, model string, rawJSON []byte, stream bool) []byte {
|
||||
return TranslateRequest(from, to, model, rawJSON, stream)
|
||||
}
|
||||
|
||||
// HasResponseTransformerByFormatName reports whether a response translator exists between two schemas.
|
||||
func HasResponseTransformerByFormatName(from, to Format) bool {
|
||||
return HasResponseTransformer(from, to)
|
||||
}
|
||||
|
||||
// TranslateStreamByFormatName converts streaming responses between schemas by their string identifiers.
|
||||
func TranslateStreamByFormatName(ctx context.Context, from, to Format, model string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string {
|
||||
return TranslateStream(ctx, from, to, model, originalRequestRawJSON, requestRawJSON, rawJSON, param)
|
||||
}
|
||||
|
||||
// TranslateNonStreamByFormatName converts non-streaming responses between schemas by their string identifiers.
|
||||
func TranslateNonStreamByFormatName(ctx context.Context, from, to Format, model string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) string {
|
||||
return TranslateNonStream(ctx, from, to, model, originalRequestRawJSON, requestRawJSON, rawJSON, param)
|
||||
}
|
||||
|
||||
// TranslateTokenCountByFormatName converts token counts between schemas by their string identifiers.
|
||||
func TranslateTokenCountByFormatName(ctx context.Context, from, to Format, count int64, rawJSON []byte) string {
|
||||
return TranslateTokenCount(ctx, from, to, count, rawJSON)
|
||||
}
|
||||
Reference in New Issue
Block a user