gptclient

package
v1.12.8 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModelGPT3Dot5Turbo = openai.GPT3Dot5Turbo
	ModelGPT4          = openai.GPT4
	ModelGPT4Turbo     = openai.GPT4Turbo
	ModelGPT4o         = openai.GPT4o // default
	ModelGPT4oMini     = openai.GPT4oMini
	ModelO1Mini        = openai.O1Mini
	ModelO1Preview     = openai.O1Preview

	DefaultModel = ModelO1Mini

	RoleTypeGopher = "You are a Go Language Coder Assistant, an AI specialized in writing, debugging, " +
		"and explaining Go code. You only provide solutions and explanations for Go programming " +
		"language. Always provide clear and concise code examples, and explain your solutions step by step."
	RoleTypeGeneral = "You are a General Assistant, an AI that can help with a wide range of tasks, including " +
		"answering questions, writing content, generating code, translating languages, and more. " +
		"Always provide clear, concise, and helpful responses."
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ModelName string
	Cli       *openai.Client
	// contains filtered or unexported fields
}

Client is a chat GPT client.

func NewClient

func NewClient(apiKey string, opts ...ClientOption) (*Client, error)

NewClient creates a new chat client.

func (*Client) ListModelNames

func (c *Client) ListModelNames(ctx context.Context) ([]string, error)

ListModelNames lists all available model names.

func (*Client) RefreshContext

func (c *Client) RefreshContext()

RefreshContext refreshes assistant context

func (*Client) Send

func (c *Client) Send(ctx context.Context, prompt string) (string, error)

Send sends a prompt to the chat gpt and returns the response.

func (*Client) SendStream

func (c *Client) SendStream(ctx context.Context, prompt string) *StreamReply

SendStream sends a prompt to the chat gpt and returns a channel of responses.

type ClientOption

type ClientOption func(*Client)

ClientOption is a function that sets a Client option.

func WithMaxTokens

func WithMaxTokens(max int) ClientOption

WithMaxTokens sets the maximum number of tokens

func WithModel

func WithModel(name string) ClientOption

WithModel sets the model name

func WithRole

func WithRole(role string) ClientOption

WithRole sets the role type

func WithTemperature

func WithTemperature(temperature float32) ClientOption

WithTemperature sets the temperature

func WithUseContext

func WithUseContext(isUse bool) ClientOption

WithUseContext sets assistant context

type StreamReply

type StreamReply struct {
	Content chan string
	Err     error // if nil means successfully response
}

StreamReply reply with stream response

Jump to

Keyboard shortcuts

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