google

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package google implements stream.Stream for Google.

Index

Constants

This section is empty.

Variables

View Source
var ErrTooManyEmptyStreamMessages = errors.New("stream has sent too many empty messages")

ErrTooManyEmptyStreamMessages represents an error when a stream has sent too many empty messages.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Content      Content `json:"content,omitempty"`
	FinishReason string  `json:"finishReason,omitempty"`
	TokenCount   uint    `json:"tokenCount,omitempty"`
	Index        uint    `json:"index,omitempty"`
}

Candidate represents a response candidate generated from the model.

type Client

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

Client is a client for the Google API.

func New

func New(config Config) *Client

New creates a new Client with the given configuration.

func (*Client) Request

func (c *Client) Request(ctx context.Context, request proto.Request) stream.Stream

Request implements stream.Client.

type CompletionMessageResponse

type CompletionMessageResponse struct {
	Candidates []Candidate `json:"candidates,omitempty"`
}

CompletionMessageResponse represents a response to an Google completion message.

type Config

type Config struct {
	BaseURL        string
	HTTPClient     *http.Client
	ThinkingBudget int
}

Config represents the configuration for the Google API client.

func DefaultConfig

func DefaultConfig(model, authToken string) Config

DefaultConfig returns the default configuration for the Google API client.

type Content

type Content struct {
	Parts []Part `json:"parts,omitempty"`
	Role  string `json:"role,omitempty"`
}

Content is the base structured datatype containing multi-part content of a message.

type ErrorAccumulator

type ErrorAccumulator interface {
	Write(p []byte) error
	Bytes() []byte
}

ErrorAccumulator is an interface for accumulating errors.

type GenerationConfig

type GenerationConfig struct {
	StopSequences    []string        `json:"stopSequences,omitempty"`
	ResponseMimeType string          `json:"responseMimeType,omitempty"`
	CandidateCount   uint            `json:"candidateCount,omitempty"`
	MaxOutputTokens  uint            `json:"maxOutputTokens,omitempty"`
	Temperature      float64         `json:"temperature,omitempty"`
	TopP             float64         `json:"topP,omitempty"`
	TopK             int64           `json:"topK,omitempty"`
	ThinkingConfig   *ThinkingConfig `json:"thinkingConfig,omitempty"`
}

GenerationConfig are the options for model generation and outputs. Not all parameters are configurable for every model.

type HTTPRequestBuilder

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

HTTPRequestBuilder is an implementation of OllamaRequestBuilder that builds HTTP requests.

func NewRequestBuilder

func NewRequestBuilder() *HTTPRequestBuilder

NewRequestBuilder creates a new HTTPRequestBuilder.

func (*HTTPRequestBuilder) Build

func (b *HTTPRequestBuilder) Build(
	ctx context.Context,
	method string,
	url string,
	body any,
	header http.Header,
) (req *http.Request, err error)

Build builds an HTTP request.

type JSONMarshaller

type JSONMarshaller struct{}

JSONMarshaller is a marshaller that marshals values to JSON.

func (*JSONMarshaller) Marshal

func (jm *JSONMarshaller) Marshal(value any) ([]byte, error)

Marshal marshals a value to JSON.

type JSONUnmarshaler

type JSONUnmarshaler struct{}

JSONUnmarshaler is an unmarshaler that unmarshals JSON data.

func (*JSONUnmarshaler) Unmarshal

func (jm *JSONUnmarshaler) Unmarshal(data []byte, v any) error

Unmarshal unmarshals JSON data.

type Marshaller

type Marshaller interface {
	Marshal(value any) ([]byte, error)
}

Marshaller is an interface for marshalling values to bytes.

type MessageCompletionRequest

type MessageCompletionRequest struct {
	Contents         []Content        `json:"contents,omitempty"`
	GenerationConfig GenerationConfig `json:"generationConfig,omitempty"`
}

MessageCompletionRequest represents the valid parameters and value options for the request.

type Part

type Part struct {
	Text string `json:"text,omitempty"`
}

Part is a datatype containing media that is part of a multi-part Content message.

type RequestBuilder

type RequestBuilder interface {
	Build(ctx context.Context, method, url string, body any, header http.Header) (*http.Request, error)
}

RequestBuilder is an interface for building HTTP requests for the Google API.

type Stream

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

Stream struct represents a stream of messages from the Google API.

func (*Stream) CallTools

func (s *Stream) CallTools() []proto.ToolCallStatus

CallTools implements stream.Stream.

func (*Stream) Close

func (s *Stream) Close() error

Close closes the stream.

func (*Stream) Current

func (s *Stream) Current() (proto.Chunk, error)

Current implements stream.Stream.

func (*Stream) Err

func (s *Stream) Err() error

Err implements stream.Stream.

func (*Stream) Messages

func (s *Stream) Messages() []proto.Message

Messages implements stream.Stream.

func (*Stream) Next

func (s *Stream) Next() bool

Next implements stream.Stream.

type ThinkingConfig

type ThinkingConfig struct {
	ThinkingBudget int `json:"thinkingBudget,omitempty"`
}

ThinkingConfig - for more details see https://ai.google.dev/gemini-api/docs/thinking#rest .

type Unmarshaler

type Unmarshaler interface {
	Unmarshal(data []byte, v any) error
}

Unmarshaler is an interface for unmarshalling bytes.

Jump to

Keyboard shortcuts

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