Utils

package
v0.0.0-...-761c5f7 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EndpointCompletion = "/chat/completions"
	EndpointSearch     = "/search"
)

Variables

This section is empty.

Functions

func SendRequest

func SendRequest(req *http.Request) (*http.Response, error)

Types

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"`
	SystemFingerprint string   `json:"system_fingerprint"`
}

func HandleResponse

func HandleResponse(resp *http.Response) (*ChatCompletionResponse, error)

type Choice

type Choice struct {
	Index        int       `json:"index"`
	Message      Message   `json:"message"`
	LogProbs     *LogProbs `json:"logprobs,omitempty"`
	FinishReason string    `json:"finish_reason"`
}

type LogProbs

type LogProbs struct {
	Tokens        []string             `json:"tokens,omitempty"`
	TokenLogProbs []float64            `json:"token_logprobs,omitempty"`
	TopLogProbs   []map[string]float64 `json:"top_logprobs,omitempty"`
}

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type RequestBuilder

type RequestBuilder struct {
	// contains filtered or unexported fields
}

func NewRequestBuilder

func NewRequestBuilder(authToken string) *RequestBuilder

NewRequestBuilder initializes a new RequestBuilder.

func (*RequestBuilder) Build

func (rb *RequestBuilder) Build(ctx context.Context) (*http.Request, error)

Build constructs the HTTP request.

func (*RequestBuilder) SetBaseURL

func (rb *RequestBuilder) SetBaseURL(baseURL string) *RequestBuilder

SetBaseURL sets the base URL for the request.

func (*RequestBuilder) SetBodyFromStruct

func (rb *RequestBuilder) SetBodyFromStruct(data interface{}) *RequestBuilder

transform interface to ChatCompletionRequest

func (*RequestBuilder) SetPath

func (rb *RequestBuilder) SetPath(path string) *RequestBuilder

SetPath sets the path for the request.

type Usage

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

Jump to

Keyboard shortcuts

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