prompts

package module
v0.0.0-...-bc8aefc Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

README

💬 Prompts

Release Go Reference Go Report Card Taylor Swift Volkswagen

A teeny-tiny experimental package to prompt for answers in Ollama and other OpenAI-compatible APIs.

Use

The idea is to have a simple, minimalistic package that enables you to prompt for answers without the overhead of a full-fledged client library. The focus is on composable packages and a consistent API surface that can be used across different providers.

Supported Schemas

⚠️ The focus is on the modern Response API pioneered by OpenAI.

Provider Response API (compact) Chat Completion API Streams
Ollama 🛑

Docs

You can find the documentation hosted on godoc.org.

Examples

The examples are located in the examples directory.

License

Apache 2.0

Documentation

Overview

Package prompts is a collection of primitives for prompts.

Index

Constants

View Source
const (
	// FinishReasonStop indicates that the chat completion was finished because the model stopped generating content.
	FinishReasonStop = "stop"
	// FinishReasonLength indicates that the chat completion was finished because the maximum length was reached.
	FinishReasonLength = "length"
	// FinishReasonContentFilter indicates that the chat completion was finished because the content filter was triggered.
	FinishReasonContentFilter = "content_filter"
	// FinishReasonUnknown indicates that the chat completion was finished for an unknown reason.
	FinishReasonUnknown = ""
)
View Source
const (
	// StatusInProgress indicates that the response is in progress.
	StatusInProgress = "in_progress"
	// StatusCompleted indicates that the response is completed.
	StatusCompleted = "completed"
	// StatusIncomplete indicates that the response is incomplete.
	StatusIncomplete = "incomplete"
)
View Source
const (
	RoleNone      = ""
	RoleUser      = "user"
	RoleTool      = "tool"
	RoleSystem    = "system"
	RoleFunction  = "function"
	RoleAssistant = "assistant"
	RoleDeveloper = "developer"
	RoleAgent     = "agent"
)

Roles of a message in a model prompt.

View Source
const (
	// EventResponseStreamed is an event type that indicates that the response has been created.
	EventResponseCreated = "response.created"
	// EventResponseCompleted is an event type that indicates that the response has been completed.
	EventResponseCompleted = "respone.completed"
	// EventResponseFailed is an event type that indicates that the response has failed.
	EventResponseFailed = "response.failed"
)
View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout for the Perplexity API.

Variables

View Source
var DefaultClient = &http.Client{
	Timeout: DefaultTimeout,
}

DefaultClient is the default HTTP client for the Perplexity API.

View Source
var ErrInvalidSequence = fmt.Errorf("invalid event sequence")

ErrInvalidSequence is returned when the event sequence is invalid.

View Source
var ErrNotImplemented = fmt.Errorf("prompts: not implemented")

ErrNotImplemented is returned when a method is not implemented.

Functions

This section is empty.

Types

type BodyProvider

type BodyProvider interface {
	// ContentType returns the Content-Type of the body.
	ContentType() string
	// Body returns the io.Reader body.
	Body() (io.Reader, error)
}

BodyProvider provides Body content for http.Request attachment.

type ChatCompletionAnnotation

type ChatCompletionAnnotation struct {
	// Type is the type of the annotation.
	Type string `json:"type,omitempty"`
	// URLCitation is the URL citation for the chat completion.
	URLCitation ChatCompletionAnnotationUrlCitation `json:"url_citation,omitzero"`
}

ChatCompletionAnnotation is the annotation for the chat completion.

type ChatCompletionAnnotationUrlCitation

type ChatCompletionAnnotationUrlCitation struct {
	// Title is the title of the URL citation.
	Title string `json:"title,omitempty"`
	// URL is the URL of the URL citation.
	URL string `json:"url,omitempty"`
	// StartIndex is the start index of the URL citation in the content.
	StartIndex int `json:"start_index,omitempty"`
	// EndIndex is the end index of the URL citation in the content.
	EndIndex int `json:"end_index,omitempty"`
}

ChatCompletionAnnotationUrlCitation is the URL citation for the chat completion.

type ChatCompletionChoiceIndex

type ChatCompletionChoiceIndex struct {
	// Role is the role of the message sender.
	Role string `json:"role"`
	// Content is the content of the message.
	Content string `json:"content"`
	// Annotations is the annotations for the message.
	Annotations []ChatCompletionAnnotation `json:"annotations,omitempty"`
	// ToolCalls is the tool calls for the message.
	ToolCalls []ChatCompletionMessageToolCall `json:"tool_calls,omitempty"`
}

ChatCompletionChoiceIndex is the index for the chat completion.

type ChatCompletionMessageCustom

type ChatCompletionMessageCustom struct {
	// Name is the name of the custom tool.
	Name string `json:"name,omitempty"`
	// Input is the input for the custom tool.
	Input map[string]any `json:"input,omitempty"`
}

type ChatCompletionMessageCustomToolCall

type ChatCompletionMessageCustomToolCall struct {
	// ID is the unique identifier for the custom tool call.
	ID string `json:"id,omitempty"`
	// Type is the type of the custom tool being called.
	Type string `json:"type,omitempty"`
	// Custom is the custom tool being called.
	Custom ChatCompletionMessageCustom `json:"custom"`
}

ChatCompletionMessageCustomToolCall represents a custom tool call in a chat completion message.

type ChatCompletionMessageFunction

type ChatCompletionMessageFunction struct {
	// Name is the name of the function.
	Name string `json:"name,omitempty"`
	// Arguments is the arguments for the function.
	Arguments map[string]any `json:"arguments,omitempty"`
}

ChatCompletionMessageFunction represents a function in a chat completion message.

type ChatCompletionMessageFunctionToolCall

type ChatCompletionMessageFunctionToolCall struct {
	// ID is the unique identifier for the function tool call.
	ID string `json:"id,omitempty"`
	// Type is the type of the custom tool being called.
	Type string `json:"type,omitempty"`
	// Function is the function being called.
	Function ChatCompletionMessageFunction `json:"function,omitzero"`
}

ChatCompletionMessageFunctionToolCall represents a function tool call in a chat completion message.

type ChatCompletionMessageToolCall

type ChatCompletionMessageToolCall struct {
	// ToolCall is the name of the tool being called.
	ToolCall isToolCall
}

ChatCompletionMessageToolCall represents a tool call in a chat completion message.

func (*ChatCompletionMessageToolCall) UnmarshalJSON

func (c *ChatCompletionMessageToolCall) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ChatCompletionMessageToolCall.

type Client

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

Client is a struct for sending HTTP requests. It holds the http Client and the response decoder.

func NewClient

func NewClient(url ...string) *Client

NewClient returns a new Client with an http DefaultClient.

func (*Client) APIKey

func (s *Client) APIKey(apiKey string) *Client

APIKey sets the Authorization header to use the provided API key with the Bearer scheme.

func (*Client) Add

func (s *Client) Add(key, value string) *Client

Add adds the key, value pair in Headers, appending values for existing keys to the key's values. Header keys are canonicalized.

func (*Client) Base

func (s *Client) Base(rawURL ...string) *Client

Base sets the rawURL. If you intend to extend the url with Path, baseUrl should be specified with a trailing slash.

func (*Client) Body

func (s *Client) Body(body io.Reader) *Client

Body sets the Client's body. The body value will be set as the Body on new requests (see Request()). If the provided body is also an io.Closer, the request Body will be closed by http.Client methods.

func (*Client) BodyForm

func (s *Client) BodyForm(bodyForm any) *Client

BodyForm sets the Client's bodyForm. The value pointed to by the bodyForm will be url encoded as the Body on new requests (see Request()). The bodyForm argument should be a pointer to a url tagged struct. See https://godoc.org/github.com/google/go-querystring/query for details.

func (*Client) BodyJSON

func (s *Client) BodyJSON(bodyJSON any) *Client

BodyJSON sets the Client's bodyJSON. The value pointed to by the bodyJSON will be JSON encoded as the Body on new requests (see Request()). The bodyJSON argument should be a pointer to a JSON tagged struct. See https://golang.org/pkg/encoding/json/#MarshalIndent for details.

func (*Client) BodyProvider

func (s *Client) BodyProvider(body BodyProvider) *Client

BodyProvider sets the Client's body provider.

func (*Client) Client

func (s *Client) Client(httpClient *http.Client) *Client

Client sets the http Client used to do requests. If a nil client is given, the http.DefaultClient will be used.

func (*Client) Connect

func (s *Client) Connect(pathURL string) *Client

Connect sets the Client method to CONNECT and sets the given pathURL.

func (*Client) Delete

func (s *Client) Delete(pathURL string) *Client

Delete sets the Client method to DELETE and sets the given pathURL.

func (*Client) Do

func (s *Client) Do(req *http.Request, successV, failureV any) (*http.Response, error)

Do sends an HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV and other responses are JSON decoded into the value pointed to by failureV. If the status code of response is 204(no content) or the Content-Length is 0, decoding is skipped. Any error sending the request or decoding the response is returned.

func (*Client) Doer

func (s *Client) Doer(doer Doer) *Client

Doer sets the custom Doer implementation used to do requests. If a nil client is given, the http.DefaultClient will be used.

func (*Client) Get

func (s *Client) Get(pathURL string) *Client

Get sets the Client method to GET and sets the given pathURL.

func (*Client) Head

func (s *Client) Head(pathURL string) *Client

Head sets the Client method to HEAD and sets the given pathURL.

func (*Client) New

func (s *Client) New() *Client

New returns a copy of a Client for creating a new Client with properties from a parent Client. For example,

parentClient := clients.New().Client(client).Base("https://api.io/")
fooClient := parentClient.New().Get("foo/")
barClient := parentClient.New().Get("bar/")

fooClient and barClient will both use the same client, but send requests to https://api.io/foo/ and https://api.io/bar/ respectively.

Note that query and body values are copied so if pointer values are used, mutating the original value will mutate the value within the child Client.

func (*Client) Options

func (s *Client) Options(pathURL string) *Client

Options sets the Client method to OPTIONS and sets the given pathURL.

func (*Client) Patch

func (s *Client) Patch(pathURL string) *Client

Patch sets the Client method to PATCH and sets the given pathURL.

func (*Client) Path

func (s *Client) Path(path string) *Client

Path extends the rawURL with the given path by resolving the reference to an absolute URL. If parsing errors occur, the rawURL is left unmodified.

func (*Client) Post

func (s *Client) Post(pathURL string) *Client

Post sets the Client method to POST and sets the given pathURL.

func (*Client) Put

func (s *Client) Put(pathURL string) *Client

Put sets the Client method to PUT and sets the given pathURL.

func (*Client) QueryStruct

func (s *Client) QueryStruct(queryStruct any) *Client

QueryStruct appends the given queryStruct to the Client's queryStructs. The queryStruct argument should be a pointer to a url tagged struct. See https://godoc.org/github.com/google/go-querystring/query for details. Any error encoding the queryStruct will be returned when creating a request (see Request()).

func (*Client) Receive

func (s *Client) Receive(ctx context.Context, successV, failureV any) (*http.Response, error)

Receive creates a new HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV and other responses are JSON decoded into the value pointed to by failureV. If the status code of response is 204(no content) or the Content-Length is 0, decoding is skipped. Any error creating the request, sending it, or decoding the response is returned. Receive is shorthand for calling Request and Do.

func (*Client) ReceiveSuccess

func (s *Client) ReceiveSuccess(ctx context.Context, successV any) (*http.Response, error)

ReceiveSuccess creates a new HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV. Any error creating the request, sending it, or decoding a 2XX response is returned.

func (*Client) Request

func (s *Client) Request(ctx context.Context) (*http.Request, error)

Request returns a new http.Request created with the Sling properties. Returns any errors parsing the rawURL, encoding query structs, encoding the body, or creating the http.Request.

func (*Client) ResponseDecoder

func (s *Client) ResponseDecoder(decoder ResponseDecoder) *Client

ResponseDecoder sets the Client's response decoder.

func (*Client) Set

func (s *Client) Set(key, value string) *Client

Set sets the key, value pair in Headers, replacing existing values associated with key. Header keys are canonicalized.

func (*Client) SetBasicAuth

func (s *Client) SetBasicAuth(username, password string) *Client

SetBasicAuth sets the Authorization header to use HTTP Basic Authentication with the provided username and password. With HTTP Basic Authentication the provided username and password are not encrypted.

func (*Client) Trace

func (s *Client) Trace(pathURL string) *Client

Trace sets the Client method to TRACE and sets the given pathURL.

type Completion

type Completion struct {
	// ID is the unique identifier for the response
	ID string `json:"id,omitempty"`
	// Object is the type of object returned
	Object string `json:"object,omitempty"`
	// CreatedAt is the timestamp of when the response was created
	CreatedAt int64 `json:"created_at,omitempty"`
	// Status is the status of the response
	Status string `json:"status,omitempty"`
	// CompletedAt is the timestamp of when the response was completed
	CompletedAt int64 `json:"completed_at,omitempty"`
	// Instructions is the instructions for the chat completion response
	Instructions string `json:"instructions,omitempty"`
	// ParallelToolCalls indicates whether the tool calls were executed in parallel
	ParallelToolCalls bool `json:"parallel_tool_calls,omitempty"`
	// Output is the output of the chat completion response
	Output []Output `json:"output,omitempty"`
}

Completion represents a chat completion response.

type CompletionEvent

type CompletionEvent struct {
	// Type is the type of the event.
	Type string `json:"type"`
	// SequenceNumber is the sequence number of the event.
	SequenceNumber int `json:"sequence_number"`
	// Data is the data associated with the event.
	Response *Completion `json:"response"`
	// Raw is the raw data associated with the event. This is useful for debugging purposes.
	Raw SSEvent `json:"-"`
}

CompletionEvent is an event that is returned from an API.

type CompletionEventStream

type CompletionEventStream chan CompletionEvent

CompletionEventStream is a stream of completion events.

func NewCompletionEventStream

func NewCompletionEventStream() CompletionEventStream

NewCompletionEventStream creates a new completion event stream.

func (CompletionEventStream) Close

func (s CompletionEventStream) Close()

Close closes the stream.

type CompletionUsage

type CompletionUsage struct {
	// PromptTokens is the number of tokens in the prompt.
	PromptTokens int `json:"prompt_tokens,omitempty"`
	// CompletionTokens is the number of tokens in the completion.
	CompletionTokens int `json:"completion_tokens,omitempty"`
	// TotalTokens is the total number of tokens used in the chat completion.
	TotalTokens int `json:"total_tokens,omitempty"`
}

CompletionUsage represents the usage of the chat completion.

type CustomDefinition

type CustomDefinition struct {
	// Name is the name of the custom tool.
	Name string `json:"name"`
	// Description is the description of the custom tool.
	Description string `json:"description,omitempty"`
}

CustomDefinition represents the custom definition for the chat completion request.

type CustomTool

type CustomTool struct {
	// Custom is the custom tool for the chat completion request.
	Custom CustomDefinition `json:"custom,omitzero"`
}

CustomTool represents a custom tool for the chat completion request.

func (CustomTool) MarshalJSON

func (c CustomTool) MarshalJSON() ([]byte, error)

MarshalJSON marshals the response custom tool into JSON.

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer executes http requests. It is implemented by *http.Client. You can wrap *http.Client with layers of Doers to form a stack of client-side middleware.

type File

type File struct {
	// Name is the name of the file.
	Name string `json:"name"`
	// URL is the URL of the file.
	URL string `json:"url"`
}

File is the file for the response message content.

type FunctionDefinition

type FunctionDefinition struct {
	// Name is the name of the function.
	Name string `json:"name"`
	// Description is the description of the function.
	Description string `json:"description,omitempty"`
	// Parameters is the parameters for the function.
	Parameters FunctionParameters `json:"parameters,omitzero"`
	// Strict is a flag to indicate whether to strictly enforce the parameters.
	Strict bool `json:"strict,omitempty"`
}

FunctionDefinition represents the function definition for the chat completion request.

type FunctionParameters

type FunctionParameters struct {
	// Properties is the properties for the function tool.
	Properties FunctionProperties `json:"properties,omitempty"`
	// Required is the required parameters for the function tool.
	Required []string `json:"required,omitempty"`
}

FunctionParameters represents the parameters for the function tool.

func (FunctionParameters) MarshalJSON

func (c FunctionParameters) MarshalJSON() ([]byte, error)

MarshalJSON marshals the response function parameters into JSON.

type FunctionProperties

type FunctionProperties map[string]json.RawMessage

FunctionProperties represents the properties for the function tool.

type FunctionTool

type FunctionTool struct {
	// Function is the function for the chat completion request.
	Function FunctionDefinition `json:"function,omitzero"`
}

FunctionTool represents a function tool for the chat completion request.

func (FunctionTool) MarshalJSON

func (c FunctionTool) MarshalJSON() ([]byte, error)

MarshalJSON marshals the response function tool into JSON.

type Image

type Image struct {
	// URL is the URL of the image.
	URL string `json:"url,omitempty"`
	// Base64 is the base64 encoding of the image.
	Base64 string `json:"base64,omitempty"`
	// Name is the name of the image.
	Name string `json:"name,omitempty"`
}

Image is a type that represents an image.

func NewImage

func NewImage(data []byte) Image

NewImage creates a new image from the given data.

func (Image) Encode

func (i Image) Encode(data []byte) string

Encode encodes the image into a string.

type Input

type Input struct {
	// Role is the role of the message sender.
	Role string `json:"role"`
	// Content is the content of the message.
	Content []MessageContent `json:"content"`
	// Name is the name of the message sender (optional).
	Name string `json:"name,omitempty"`
}

Input is the message for chat completion.

type MessageContent

type MessageContent struct {
	Content isMessageContent
}

MessageContent is the content of a response message.

func NewMessageContent

func NewMessageContent() MessageContent

NewMessageContent creates a new response message content.

func (MessageContent) GetFile

func (c MessageContent) GetFile() (MessageContentFile, bool)

GetFile returns the file content of the response message content.

func (MessageContent) GetImage

func (c MessageContent) GetImage() (MessageContentImage, bool)

GetImage returns the image content of the response message content.

func (MessageContent) GetText

func (c MessageContent) GetText() (MessageContentText, bool)

GetText returns the text content of the response message content.

func (MessageContent) MarshalJSON

func (c MessageContent) MarshalJSON() ([]byte, error)

MarshalJSON marshals the response message content into JSON.

func (*MessageContent) Reset

func (c *MessageContent) Reset()

Reset resets the response message content.

type MessageContentFile

type MessageContentFile struct {
	File File `json:"file"`
}

MessageContentFile is the file content of a response message.

type MessageContentImage

type MessageContentImage struct {
	Image Image `json:"image"`
}

MessageContentImage is the image content of a response message.

type MessageContentText

type MessageContentText struct {
	// Text is the text of the content.
	Text string `json:"text"`
}

MessageContentText is the text content of a response message.

func (MessageContentText) MarshalJSON

func (c MessageContentText) MarshalJSON() ([]byte, error)

MarshalJSON marshals the response message content text into JSON.

type Output

type Output struct {
	// Output is the output of the completion of the response.
	Output isOutput
}

Output represents the output of the chat completion response.

func (*Output) GetFunctionCall

func (r *Output) GetFunctionCall() (*OutputFunctionCall, bool)

GetFunctionCall returns the function call if the output is a function call.

func (*Output) GetMessage

func (r *Output) GetMessage() (*OutputMessage, bool)

GetMessage returns the message if the output is a message.

func (*Output) UnmarshalJSON

func (r *Output) UnmarshalJSON(data []byte) error

type OutputFunctionCall

type OutputFunctionCall struct {
	// ID is the unique identifier for the function call output.
	ID string `json:"id,omitempty"`
	// CallID is the unique identifier for the function call.
	CallID string `json:"call_id,omitempty"`
	// Status is the status of the message output.
	Status string `json:"status,omitempty"`
	// Role is the role of the message sender.
	Role string `json:"role"`
	// Name is the name of the function being called.
	Name string `json:"name,omitempty"`
	// Arguments is the arguments for the function being called.
	Arguments string `json:"arguments,omitempty"`
}

OutputFunctionCall represents a function call output in the chat completion response.

type OutputMessage

type OutputMessage struct {
	// ID is the unique identifier for the message output.
	ID string `json:"id,omitempty"`
	// Status is the status of the message output.
	Status string `json:"status,omitempty"`
	// Role is the role of the message sender.
	Role string `json:"role"`
	// OutputMessageContent is the content of the message output.
	OutputMessageContent []OutputMessageContent `json:"content,omitzero"`
}

OutputMessage represents a message output in the chat completion response.

type OutputMessageContent

type OutputMessageContent struct {
	// Content is the content of the message output.
	Content isOutputMessageContent
}

OutputMessageContent represents the content of a message output in the chat completion response.

func (*OutputMessageContent) UnmarshalJSON

func (c *OutputMessageContent) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for OutputMessageContent.

type OutputMessageContentText

type OutputMessageContentText struct {
	// Text is the text content of the message output.
	Text string `json:"text,omitempty"`
}

OutputMessageContentText represents a text content of a message output in the chat completion response.

type Prompt

type Prompt struct {
	// Model is the model for the chat completion request.
	Model string `json:"model"`
	// Input is the list of messages for the chat completion request.
	Input []Input `json:"input"`
	// Instructions is the instructions for the chat completion request.
	Instructions string `json:"instructions,omitempty"`
	// Tools is the list of tools to use for the chat completion request.
	Tools []Tool `json:"tools,omitempty"`
	// ToolChoice is the tool choice for the chat completion request.
	ToolChoice ToolChoice `json:"tool_choice,omitempty"`
	// MaxTokens is the maximum number of tokens for the chat completion request.
	MaxTokens *int `json:"max_tokens,omitzero"`
	// Temperature is the sampling temperature
	Temperature *float32 `json:"temperature,omitzero"`
	// Stream is a flag to enable streaming
	Stream bool `json:"stream,omitempty"`
	// TopP is the nucleus sampling parameter
	TopP *float64 `json:"top_p,omitzero"`
	// TopK is the number of top tokens to sample from
	TopK *int `json:"top_k,omitzero"`
}

Prompt is a chat completion request.

func NewPrompt

func NewPrompt(opts ...PromptOpt) *Prompt

NewPrompt creates a new chat completion request with the given options.

type PromptError

type PromptError struct {
	Code    int    `json:"code"`
	Message string `json:"error"`
	Type    string `json:"type"`
	Param   string `json:"param"`
}

PromptError is an error that can be returned by the prompts package.

func NewPromptError

func NewPromptError() *PromptError

NewPromptError returns a new instance of prompts.PromptError.

func (*PromptError) Error

func (e *PromptError) Error() string

Error returns the error message associated with the Err instance.

func (*PromptError) UnmarshalJSON

func (e *PromptError) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON data into the Err instance.

type PromptOpt

type PromptOpt func(*Prompt)

PromptOpt is a function type for configuring the ResponseRequest.

func WithInput

func WithInput(msgs ...Input) PromptOpt

WithInput sets the messages for the chat completion request.

func WithInstructions

func WithInstructions(instructions string) PromptOpt

WithInstructions sets the instructions for the chat completion request.

func WithModel

func WithModel(model string) PromptOpt

WithModel sets the model for the chat completion request.

func WithStream

func WithStream() PromptOpt

WithStream sets whether or not to stream the chat completion response.

func WithTools

func WithTools(tools ...Tool) PromptOpt

WithTools sets the tools for the chat completion request.

type Promptable

type Promptable interface {
	// Do completes a prompt and returns the completion.
	Do(ctx context.Context, prompt *Prompt) (*Completion, error)
	// AsStream completes a prompt and returns the completion as a stream.
	AsStream(ctx context.Context, prompt *Prompt, stream CompletionEventStream) error
}

Promptable is an interface that enables to send a prompt.

type ResponseDecoder

type ResponseDecoder interface {
	// Decode decodes the response into the value pointed to by v.
	Decode(resp *http.Response, v any) error
}

ResponseDecoder decodes http responses into struct values.

func NewByteStreamer

func NewByteStreamer() ResponseDecoder

NewByteStreamer returns a ResponseDecoder that copies the response body into an io.Writer instance.

func NewCompletionEventDecoder

func NewCompletionEventDecoder() ResponseDecoder

NewCompletionEventDecoder returns a new SSE decoder.

func NewJSONDecoder

func NewJSONDecoder() ResponseDecoder

NewJSONDecoder returns a ResponseDecoder that decodes JSON responses into struct values.

type SSEvent

type SSEvent struct {
	// ID is the unique identifier for this event.
	ID []byte
	// Event is the name of the event.
	Event []byte
	// Data is the content of this message.
	Data []byte
	// Retry is the reconnection time (milliseconds).
	Retry []byte
}

SSEvent is an event emitted by the server.

type SearchResult

type SearchResult struct {
	// Title is the title of the search result
	Title string `json:"title,omitempty"`
	// URL is the URL of the search result
	URL string `json:"url,omitempty"`
	// Snippet is the snippet of the search result
	Snippet string `json:"snippet,omitempty"`
	// Source is the source of the search result
	Source string `json:"source,omitempty"`
}

SearchResult represents a search result structure for chat completion API.

type Tool

type Tool struct {
	Tool isCompletionTool
}

Tool is an interface that represents a tool for the chat completion request.

func (Tool) MarshalJSON

func (c Tool) MarshalJSON() ([]byte, error)

MarshalJSON marshals the response tool into JSON.

type ToolChoice

type ToolChoice string
const (
	// ToolChoiceAuto is the auto tool choice.
	ToolChoiceAuto ToolChoice = "auto"
	// ToolChoiceAll is the all tool choice.
	ToolChoiceNone ToolChoice = "none"
	// ToolChoiceRequired is the required tool choice.
	ToolChoiceRequired ToolChoice = "required"
)

type Unimplemented

type Unimplemented struct{}

Unimplemented is an unimplemented Promptable.

func (*Unimplemented) AsStream

AsStream is an unimplemented method.

func (*Unimplemented) Do

Complete is an unimplemented method.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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