engines

package
v0.0.0-...-f179465 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenLimitExceeded = fmt.Errorf("token limit exceeded")
View Source
var OpenAIBaseURL = "https://api.openai.com"

Functions

This section is empty.

Types

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model       string          `json:"model"`
	Temperature float64         `json:"temperature,omitempty"`
	Messages    []*ChatMessage  `json:"messages"`
	Functions   []FunctionSpecs `json:"functions,omitempty"`
}

type ChatCompletionResponse

type ChatCompletionResponse struct {
	Choices []struct {
		Message *ChatMessage `json:"message"`
	} `json:"choices"`
	Usage struct {
		PromptTokensUsed     int `json:"prompt_tokens"`
		CompletionTokensUsed int `json:"completion_tokens"`
	} `json:"usage"`
}

type ChatMessage

type ChatMessage struct {
	Role         ConvRole      `json:"role"`
	Text         string        `json:"content"`
	FunctionCall *FunctionCall `json:"function_call,omitempty"`
	Name         string        `json:"name,omitempty"`
}

type ChatPrompt

type ChatPrompt struct {
	History []*ChatMessage
}

type ConvRole

type ConvRole string
const (
	ConvRoleUser      ConvRole = "user"
	ConvRoleSystem    ConvRole = "system"
	ConvRoleAssistant ConvRole = "assistant"
	ConvRoleFunction  ConvRole = "function"
)

type FunctionCall

type FunctionCall struct {
	Name string `json:"name"`
	Args string `json:"arguments"`
}

type FunctionSpecs

type FunctionSpecs struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  *ParameterSpecs `json:"parameters"`
}

type GPT

type GPT struct {
	APIToken             string
	Model                string
	PromptTokensUsed     int
	CompletionTokensUsed int
	PromptTokenLimit     int
	CompletionTokenLimit int
	TotalTokenLimit      int
	Temperature          float64
}

func NewGPTEngine

func NewGPTEngine(apiToken string, model string) *GPT

func (*GPT) Chat

func (gpt *GPT) Chat(prompt *ChatPrompt) (*ChatMessage, error)

func (*GPT) ChatWithFunctions

func (gpt *GPT) ChatWithFunctions(prompt *ChatPrompt, functions []FunctionSpecs) (*ChatMessage, error)

func (*GPT) WithCompletionTokenLimit

func (gpt *GPT) WithCompletionTokenLimit(limit int) *GPT

func (*GPT) WithPromptTokenLimit

func (gpt *GPT) WithPromptTokenLimit(limit int) *GPT

func (*GPT) WithTemperature

func (gpt *GPT) WithTemperature(temperature float64) *GPT

func (*GPT) WithTotalTokenLimit

func (gpt *GPT) WithTotalTokenLimit(limit int) *GPT

type LLM

type LLM interface {
	Chat(prompt *ChatPrompt) (*ChatMessage, error)
}

type LLMWithFunctionCalls

type LLMWithFunctionCalls interface {
	LLM
	ChatWithFunctions(prompt *ChatPrompt, functions []FunctionSpecs) (*ChatMessage, error)
}

type ParameterSpecs

type ParameterSpecs struct {
	Type        string                     `json:"type"`
	Description string                     `json:"description,omitempty"`
	Properties  map[string]*ParameterSpecs `json:"properties,omitempty"`
	Required    []string                   `json:"required,omitempty"`
	Items       *ParameterSpecs            `json:"items,omitempty"`
	Enum        []any                      `json:"enum,omitempty"`
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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