provider

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetProductIDFromAPIKey

func GetProductIDFromAPIKey(ctx context.Context, apiKeyId uuid.UUID) (uuid.UUID, error)

func HandleAPICallAndResponse

func HandleAPICallAndResponse(w http.ResponseWriter, r *http.Request, ctx context.Context, req ChatCompletionRequest, productID uuid.UUID, provider Provider)

func HandleContextCache

func HandleContextCache(ctx context.Context, req ChatCompletionRequest, productID uuid.UUID) (string, bool, error)

func HandleError

func HandleError(w http.ResponseWriter, err error, statusCode int)

func LogProviderError added in v0.4.0

func LogProviderError(r *http.Request, provider string, err error)

func LogProviderInput added in v0.4.0

func LogProviderInput(r *http.Request, provider string, content interface{})

func LogProviderOutput added in v0.4.0

func LogProviderOutput(r *http.Request, provider string, content interface{})

func PerformAuditLogging

func PerformAuditLogging(r *http.Request, logType string, messageType string, body []byte)

func SetContextCacheResponse

func SetContextCacheResponse(ctx context.Context, req ChatCompletionRequest, resp *ChatCompletionResponse, productID uuid.UUID) error

Types

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model     string          `json:"model"`
	Messages  []types.Message `json:"messages"`
	MaxTokens int             `json:"max_tokens"`
	Stream    bool            `json:"stream"`
}

func HandleCommonRequestLogic

func HandleCommonRequestLogic(w http.ResponseWriter, r *http.Request, providerName string) (ChatCompletionRequest, context.Context, uuid.UUID, bool)

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID      string   `json:"id"`
	Object  string   `json:"object"`
	Created int64    `json:"created"`
	Model   string   `json:"model"`
	Choices []Choice `json:"choices"`
	Usage   Usage    `json:"usage"`
}

func CreateChatCompletionResponseFromCache

func CreateChatCompletionResponseFromCache(cachedResponse string, model string) (*ChatCompletionResponse, error)

func HandleCacheLogic

func HandleCacheLogic(ctx context.Context, req ChatCompletionRequest, productID uuid.UUID) (*ChatCompletionResponse, bool, error)

type Choice

type Choice struct {
	Index        int           `json:"index"`
	Message      types.Message `json:"message"`
	FinishReason string        `json:"finish_reason"`
}

type InputRequest

type InputRequest struct {
	Model     string          `json:"model"`
	Messages  []types.Message `json:"messages"`
	MaxTokens int             `json:"max_tokens"`
	Stream    bool            `json:"stream"`
}

type Provider

type Provider interface {
	CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (*ChatCompletionResponse, error)
	CreateChatCompletionStream(ctx context.Context, req ChatCompletionRequest) (Stream, error)
}

type Stream

type Stream interface {
	Recv() (StreamResponse, error)
	Close()
}

type StreamResponse

type StreamResponse interface {
	GetContent() string
	GetFinishReason() string
	GetID() string
	GetCreated() int64
	GetModel() string
}

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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