client

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2025 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	RequestMutex sync.Mutex
	// contains filtered or unexported fields
}

Client is the main client for interacting with the CLI API.

func NewClient

func NewClient(httpClient *http.Client, ts *auth.TokenStorage, cfg *config.Config, glAPIKey ...string) *Client

NewClient creates a new CLI API client.

func (*Client) APIRequest added in v1.5.0

func (c *Client) APIRequest(ctx context.Context, endpoint string, body interface{}, stream bool) (io.ReadCloser, *ErrorMessage)

APIRequest handles making requests to the CLI API endpoints.

func (*Client) CheckCloudAPIIsEnabled added in v1.3.0

func (c *Client) CheckCloudAPIIsEnabled() (bool, error)

CheckCloudAPIIsEnabled sends a simple test request to the API to verify that the Cloud AI API is enabled for the user's project. It provides an activation URL if the API is disabled.

func (*Client) GetEmail added in v1.3.1

func (c *Client) GetEmail() string

func (*Client) GetGenerativeLanguageAPIKey added in v1.7.0

func (c *Client) GetGenerativeLanguageAPIKey() string

func (*Client) GetProjectID added in v1.3.1

func (c *Client) GetProjectID() string

func (*Client) GetProjectList

func (c *Client) GetProjectList(ctx context.Context) (*GCPProject, error)

GetProjectList fetches a list of Google Cloud projects accessible by the user.

func (*Client) IsAuto added in v1.3.0

func (c *Client) IsAuto() bool

func (*Client) IsChecked added in v1.3.0

func (c *Client) IsChecked() bool

func (*Client) IsModelQuotaExceeded added in v1.6.0

func (c *Client) IsModelQuotaExceeded(model string) bool

func (*Client) SaveTokenToFile added in v1.3.0

func (c *Client) SaveTokenToFile() error

SaveTokenToFile serializes the client's current token storage to a JSON file. The filename is constructed from the user's email and project ID.

func (*Client) SendMessage added in v1.5.0

func (c *Client) SendMessage(ctx context.Context, rawJson []byte, model string, contents []Content, tools []ToolDeclaration) ([]byte, *ErrorMessage)

SendMessageStream handles a single conversational turn, including tool calls.

func (*Client) SendMessageStream

func (c *Client) SendMessageStream(ctx context.Context, rawJson []byte, model string, contents []Content, tools []ToolDeclaration) (<-chan []byte, <-chan *ErrorMessage)

SendMessageStream handles a single conversational turn, including tool calls.

func (*Client) SetIsAuto added in v1.3.0

func (c *Client) SetIsAuto(auto bool)

func (*Client) SetIsChecked added in v1.3.0

func (c *Client) SetIsChecked(checked bool)

func (*Client) SetProjectID added in v1.3.0

func (c *Client) SetProjectID(projectID string)

func (*Client) SetupUser

func (c *Client) SetupUser(ctx context.Context, email, projectID string) error

SetupUser performs the initial user onboarding and setup.

type Content

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

Content represents a single message in a conversation, with a role and parts.

type ErrorMessage added in v1.2.0

type ErrorMessage struct {
	StatusCode int
	Error      error
}

ErrorMessage encapsulates an error with an associated HTTP status code.

type FunctionCall

type FunctionCall struct {
	Name string                 `json:"name"`
	Args map[string]interface{} `json:"args"`
}

FunctionCall represents a tool call requested by the model, including the function name and its arguments.

type FunctionResponse

type FunctionResponse struct {
	Name     string                 `json:"name"`
	Response map[string]interface{} `json:"response"`
}

FunctionResponse represents the result of a tool execution, sent back to the model.

type GCPProject

type GCPProject struct {
	Projects []GCPProjectProjects `json:"projects"`
}

GCPProject represents the response structure for a Google Cloud project list request.

type GCPProjectLabels

type GCPProjectLabels struct {
	GenerativeLanguage string `json:"generative-language"`
}

GCPProjectLabels defines the labels associated with a GCP project.

type GCPProjectProjects

type GCPProjectProjects struct {
	ProjectNumber  string           `json:"projectNumber"`
	ProjectID      string           `json:"projectId"`
	LifecycleState string           `json:"lifecycleState"`
	Name           string           `json:"name"`
	Labels         GCPProjectLabels `json:"labels"`
	CreateTime     time.Time        `json:"createTime"`
}

GCPProjectProjects contains details about a single Google Cloud project.

type GenerateContentRequest

type GenerateContentRequest struct {
	Contents         []Content         `json:"contents"`
	Tools            []ToolDeclaration `json:"tools,omitempty"`
	GenerationConfig `json:"generationConfig"`
}

GenerateContentRequest is the top-level request structure for the streamGenerateContent endpoint.

type GenerationConfig

type GenerationConfig struct {
	ThinkingConfig GenerationConfigThinkingConfig `json:"thinkingConfig,omitempty"`
	Temperature    float64                        `json:"temperature,omitempty"`
	TopP           float64                        `json:"topP,omitempty"`
	TopK           float64                        `json:"topK,omitempty"`
}

GenerationConfig defines parameters that control the model's generation behavior.

type GenerationConfigThinkingConfig

type GenerationConfigThinkingConfig struct {
	// IncludeThoughts determines whether the model should output its reasoning process.
	IncludeThoughts bool `json:"include_thoughts,omitempty"`
}

GenerationConfigThinkingConfig specifies configuration for the model's "thinking" process.

type InlineData

type InlineData struct {
	MimeType string `json:"mime_type,omitempty"`
	Data     string `json:"data,omitempty"`
}

InlineData represents base64-encoded data with its MIME type.

type Part

type Part struct {
	Text             string            `json:"text,omitempty"`
	InlineData       *InlineData       `json:"inlineData,omitempty"`
	FunctionCall     *FunctionCall     `json:"functionCall,omitempty"`
	FunctionResponse *FunctionResponse `json:"functionResponse,omitempty"`
}

Part represents a distinct piece of content within a message, which can be text, inline data (like an image), a function call, or a function response.

type ToolDeclaration

type ToolDeclaration struct {
	FunctionDeclarations []interface{} `json:"functionDeclarations"`
}

ToolDeclaration defines the structure for declaring tools (like functions) that the model can call.

Jump to

Keyboard shortcuts

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