translator

package
v6.2.7 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package translator provides request and response translation functionality between different AI API formats. It acts as a wrapper around the SDK translator registry, providing convenient functions for translating requests and responses between OpenAI, Claude, Gemini, and other API formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NeedConvert

func NeedConvert(from, to string) bool

NeedConvert checks if a response translation is needed between two API formats.

Parameters:

  • from: The source API format identifier
  • to: The target API format identifier

Returns:

  • bool: True if response translation is needed, false otherwise

func Register

func Register(from, to string, request interfaces.TranslateRequestFunc, response interfaces.TranslateResponse)

Register registers a new translator for converting between two API formats.

Parameters:

  • from: The source API format identifier
  • to: The target API format identifier
  • request: The request translation function
  • response: The response translation function

func Request

func Request(from, to, modelName string, rawJSON []byte, stream bool) []byte

Request translates a request from one API format to another.

Parameters:

  • from: The source API format identifier
  • to: The target API format identifier
  • modelName: The model name for the request
  • rawJSON: The raw JSON request data
  • stream: Whether this is a streaming request

Returns:

  • []byte: The translated request JSON

func Response

func Response(from, to string, ctx context.Context, modelName string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string

Response translates a streaming response from one API format to another.

Parameters:

  • from: The source API format identifier
  • to: The target API format identifier
  • ctx: The context for the translation
  • modelName: The model name for the response
  • originalRequestRawJSON: The original request JSON
  • requestRawJSON: The translated request JSON
  • rawJSON: The raw response JSON
  • param: Additional parameters for translation

Returns:

  • []string: The translated response lines

func ResponseNonStream

func ResponseNonStream(from, to string, ctx context.Context, modelName string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) string

ResponseNonStream translates a non-streaming response from one API format to another.

Parameters:

  • from: The source API format identifier
  • to: The target API format identifier
  • ctx: The context for the translation
  • modelName: The model name for the response
  • originalRequestRawJSON: The original request JSON
  • requestRawJSON: The translated request JSON
  • rawJSON: The raw response JSON
  • param: Additional parameters for translation

Returns:

  • string: The translated response JSON

Types

This section is empty.

Jump to

Keyboard shortcuts

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