Documentation
¶
Overview ¶
Example (JsonOutput_outputSchema) ¶
ctx := context.TODO() gen, err := GenerateJSON( ctx, UseModel("gemini-2.5-pro-exp-03-25"), UseTemperature(0.2), UseJSONOutput(Object{ Description: "result of each", Properties: Properties{ "resultA": Int{ Description: "result 1", Required: true, }, "resultB": Int{ Description: "result 2", Required: true, }, }, }), ) if err != nil { panic(err) } prompt := ` execute this task: 1. Sum 35 and 21 2. multiply by 88 using one previous answer. ` resp, err := gen(prompt) if err != nil { panic(err) } fmt.Println("resultA=", resp["resultA"]) fmt.Println("resultB=", resp["resultB"])
Output: resultA= 56 resultB= 4928
Example (JsonOutput_promptInstruction) ¶
ctx := context.TODO() session, err := Generate( ctx, UseModel("gemini-2.5-pro-exp-03-25"), UseTemperature(0.2), UseJSONOutput(nil), ) if err != nil { panic(err) } defer session.Close() prompt := ` execute this task: 1. Sum 35 and 21 2. multiply by 88 using one previous answer. 3. Return the result by following "JSONSchema" format. output(JSONSchema): ret={ "resultA": int, "resultB": int, } Return: ret ` it, err := session.SendText(prompt) if err != nil { panic(err) } for msg, err := range it { if err != nil { panic(err) } fmt.Println(msg) }
Output: { "resultA": 56, "resultB": 4928 }
Index ¶
- Constants
- func AddBinarySystemInstruction(data []byte, mimeType string) func() []genai.Part
- func AddTextSystemInstruction(values ...string) func() []genai.Part
- func GobEncoder[T any]() *gobEncoder[T]
- func JSONEncoder[T any]() *jsonEncoder[T]
- type Array
- type Bool
- type BoolArray
- type Conn
- func (c *Conn) Call(ctx context.Context, name string, req Req) (Resp, error)
- func (c *Conn) Close()
- func (c *Conn) RegisterSSEMCPTools(baseURL string, initReq mcp.InitializeRequest, ...) error
- func (c *Conn) RegisterTool(t Tool) error
- func (c *Conn) Tool(name string) (Tool, bool)
- func (c *Conn) UnregisterTools() error
- func (c *Conn) Use(ctx context.Context, options ...UseOptionFunc) (Session, error)
- type ConnectOption
- type ConnectOptionFunc
- func AllowReconnect(allowReconnect bool) ConnectOptionFunc
- func ConnectAddress(host, port string) ConnectOptionFunc
- func ConnectAuth(user, password string) ConnectOptionFunc
- func ConnectNoEcho(noEcho bool) ConnectOptionFunc
- func ConnectNoRandomize(noRandomize bool) ConnectOptionFunc
- func ConnectTLS(useTLS bool) ConnectOptionFunc
- func ConnectTimeout(timeout time.Duration) ConnectOptionFunc
- func MaxReconnects(maxReconnects int) ConnectOptionFunc
- func Name(name string) ConnectOptionFunc
- func NatsURL(url ...string) ConnectOptionFunc
- func ReconnectWait(reconnectWait time.Duration) ConnectOptionFunc
- func RequestTimeout(timeout time.Duration) ConnectOptionFunc
- type Encoder
- type ErrorHandler
- type Float
- type FloatArray
- type GenerateJSONFunc
- type Int
- type IntArray
- type IntEnum
- type LiveSession
- type Logger
- type NullableType
- type Object
- type ObjectArray
- type Properties
- type Registry
- type RegistryClusterOption
- type RegistryOption
- type Req
- type ReqCtx
- func (c *ReqCtx) Bool(key string) bool
- func (c *ReqCtx) Float64(key string) float64
- func (c *ReqCtx) FloatArray(key string) []float64
- func (c *ReqCtx) Int(key string) int
- func (c *ReqCtx) IntArray(key string) []int
- func (c *ReqCtx) Object(key string) *ReqCtx
- func (c *ReqCtx) ObjectArray(key string) []*ReqCtx
- func (c *ReqCtx) Req() Req
- func (c *ReqCtx) String(key string) string
- func (c *ReqCtx) StringArray(key string) []string
- type Resp
- type RespError
- type Session
- type String
- type StringArray
- type StringEnum
- type SystemInstructionOptfion
- type Tool
- type ToolHandler
- type TypeDef
- type UseOption
- type UseOptionFunc
- func UseDebugMode(enable bool) UseOptionFunc
- func UseDefaultArgs(fn func() map[string]any) UseOptionFunc
- func UseJSONOutput(schema TypeDef) UseOptionFunc
- func UseLocalTool(enable bool) UseOptionFunc
- func UseLogger(lg Logger) UseOptionFunc
- func UseMaxOutputTokens(size int32) UseOptionFunc
- func UseModel(name string) UseOptionFunc
- func UseSystemInstruction(sysInstructionOptions ...SystemInstructionOptfion) UseOptionFunc
- func UseTemperature(v float32) UseOptionFunc
- func UseToolJSONOutput(conn *Conn, toolName string) UseOptionFunc
- func UseTopP(v float32) UseOptionFunc
Examples ¶
Constants ¶
View Source
const ( TopicRegisterTool string = "polaris:tool:register" TopicUnregisterTool string = "polaris:tool:unregister" TopicToolKeepalive string = "polaris:tool:keepalive" TopicListTool string = "polaris:tool:list" )
View Source
const ( AppName string = "polaris" Version string = "1.3.1" )
Variables ¶
This section is empty.
Functions ¶
func GobEncoder ¶
func GobEncoder[T any]() *gobEncoder[T]
cloud.google.com/go/vertexai/genai are not support json
Types ¶
type Array ¶
type Array struct { Description string Items TypeDef Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeArray, Description: "...", Items: &genai.Schema{...}, }
func (Array) IsRequired ¶
type Bool ¶
type Bool struct { Description string Default bool Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeBoolean, Description: "...", }
func (Bool) IsRequired ¶
type BoolArray ¶
type BoolArray struct { Description string ItemDescription string Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeArray, Description: "...", Items: &genai.Schema{ Type: genai.TypeBoolean, Description: "...", }, }
func (BoolArray) IsRequired ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func Connect ¶
func Connect(options ...ConnectOptionFunc) (*Conn, error)
func (*Conn) RegisterSSEMCPTools ¶ added in v1.2.4
func (c *Conn) RegisterSSEMCPTools(baseURL string, initReq mcp.InitializeRequest, options ...transport.ClientOption) error
func (*Conn) RegisterTool ¶
func (*Conn) UnregisterTools ¶
type ConnectOption ¶
type ConnectOptionFunc ¶
type ConnectOptionFunc func(*ConnectOption)
func AllowReconnect ¶
func AllowReconnect(allowReconnect bool) ConnectOptionFunc
func ConnectAddress ¶
func ConnectAddress(host, port string) ConnectOptionFunc
func ConnectAuth ¶
func ConnectAuth(user, password string) ConnectOptionFunc
func ConnectNoEcho ¶
func ConnectNoEcho(noEcho bool) ConnectOptionFunc
func ConnectNoRandomize ¶
func ConnectNoRandomize(noRandomize bool) ConnectOptionFunc
func ConnectTLS ¶
func ConnectTLS(useTLS bool) ConnectOptionFunc
func ConnectTimeout ¶
func ConnectTimeout(timeout time.Duration) ConnectOptionFunc
func MaxReconnects ¶
func MaxReconnects(maxReconnects int) ConnectOptionFunc
func Name ¶
func Name(name string) ConnectOptionFunc
func NatsURL ¶
func NatsURL(url ...string) ConnectOptionFunc
func ReconnectWait ¶
func ReconnectWait(reconnectWait time.Duration) ConnectOptionFunc
func RequestTimeout ¶ added in v1.2.2
func RequestTimeout(timeout time.Duration) ConnectOptionFunc
type ErrorHandler ¶ added in v1.2.3
type ErrorHandler func(error)
type Float ¶
type Float struct { Description string Default float64 Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeNumber, Description: "...", }
func (Float) IsRequired ¶
type FloatArray ¶
type FloatArray struct { Description string ItemDescription string Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeArray, Description: "...", Items: &genai.Schema{ Type: genai.TypeNumber, Description: "...", }, }
func (FloatArray) IsRequired ¶
func (fa FloatArray) IsRequired() bool
func (FloatArray) Schema ¶
func (fa FloatArray) Schema() *genai.Schema
type GenerateJSONFunc ¶ added in v1.2.0
func GenerateJSON ¶ added in v1.1.0
func GenerateJSON(ctx context.Context, options ...UseOptionFunc) (GenerateJSONFunc, error)
type Int ¶
type Int struct { Description string Default int Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeInteger, Description: "...", }
func (Int) IsRequired ¶
type IntArray ¶
type IntArray struct { Description string ItemDescription string Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeArray, Description: "...", Items: &genai.Schema{ Type: genai.TypeInteger, Description: "...", }, }
func (IntArray) IsRequired ¶
type IntEnum ¶
type IntEnum struct { Description string Values []string Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeInteger, Description: "...", Enum: []string{"100", "200", "300"}, Format: "enum", }
func (IntEnum) IsRequired ¶
type LiveSession ¶
type LiveSession struct {
// contains filtered or unexported fields
}
func (*LiveSession) Close ¶
func (s *LiveSession) Close() error
func (*LiveSession) JSONOutput ¶ added in v1.1.0
func (s *LiveSession) JSONOutput() bool
type NullableType ¶
type NullableType string
const ( NullableYes NullableType = "yes" NullableNo NullableType = "no" )
func (NullableType) Nullable ¶
func (n NullableType) Nullable() bool
type Object ¶
type Object struct { Description string Properties Properties Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeObject, Description: "...", Properties: map[string]*genai.Schema{...}, }
func (Object) IsRequired ¶
type ObjectArray ¶
type ObjectArray struct { Description string ItemDescription string Required bool Nullable NullableType Items Properties }
*genai.Schema{ Type: genai.TypeArray, Description: "...", Items: &genai.Schema{ Type: genai.TypeObject, Properties: map[string]*genai.Schema{ ... }, }, }
func (ObjectArray) IsRequired ¶
func (oa ObjectArray) IsRequired() bool
func (ObjectArray) Schema ¶
func (oa ObjectArray) Schema() *genai.Schema
type Properties ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func CreateRegistry ¶
func CreateRegistry(opts ...RegistryOption) (*Registry, error)
type RegistryClusterOption ¶
type RegistryClusterOption func(*server.ClusterOpts)
func WithClussterAdvertise ¶
func WithClussterAdvertise(advertise string) RegistryClusterOption
func WithClusterHost ¶
func WithClusterHost(host string) RegistryClusterOption
func WithClusterName ¶
func WithClusterName(name string) RegistryClusterOption
func WithClusterPort ¶
func WithClusterPort(port int) RegistryClusterOption
type RegistryOption ¶
func WithBind ¶
func WithBind(host string, port int) RegistryOption
func WithClusterOption ¶
func WithClusterOption(opts ...RegistryClusterOption) RegistryOption
func WithMaxPayload ¶
func WithMaxPayload(size int32) RegistryOption
func WithRoutes ¶
func WithRoutes(routesStr string) RegistryOption
type ReqCtx ¶ added in v1.3.0
type ReqCtx struct {
// contains filtered or unexported fields
}
func (*ReqCtx) FloatArray ¶ added in v1.3.0
func (*ReqCtx) ObjectArray ¶ added in v1.3.0
func (*ReqCtx) StringArray ¶ added in v1.3.0
type Session ¶
type String ¶
type String struct { Description string Default string Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeString, Description "...", }
func (String) IsRequired ¶
type StringArray ¶
type StringArray struct { Description string ItemDescription string Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeArray, Description: "...", Items: &genai.Schema{ Type: genai.TypeString, Description: "...", }, }
func (StringArray) IsRequired ¶
func (sa StringArray) IsRequired() bool
func (StringArray) Schema ¶
func (sa StringArray) Schema() *genai.Schema
type StringEnum ¶
type StringEnum struct { Description string Values []string Required bool Nullable NullableType }
*genai.Schema{ Type: genai.TypeString, Description: "...", Enum: []string{"north", "east", "south", "west"}, Format: "enum", }
func (StringEnum) IsRequired ¶
func (se StringEnum) IsRequired() bool
func (StringEnum) Schema ¶
func (se StringEnum) Schema() *genai.Schema
type Tool ¶
type Tool struct { Name string Description string Parameters Object Response Object Handler ToolHandler ErrorHandler ErrorHandler }
func (Tool) FunctionDeclaration ¶
func (t Tool) FunctionDeclaration() genai.FunctionDeclaration
type ToolHandler ¶
type UseOptionFunc ¶
type UseOptionFunc func(*UseOption)
func UseDebugMode ¶
func UseDebugMode(enable bool) UseOptionFunc
func UseDefaultArgs ¶
func UseDefaultArgs(fn func() map[string]any) UseOptionFunc
func UseJSONOutput ¶
func UseJSONOutput(schema TypeDef) UseOptionFunc
func UseLocalTool ¶
func UseLocalTool(enable bool) UseOptionFunc
func UseLogger ¶
func UseLogger(lg Logger) UseOptionFunc
func UseMaxOutputTokens ¶
func UseMaxOutputTokens(size int32) UseOptionFunc
func UseModel ¶
func UseModel(name string) UseOptionFunc
func UseSystemInstruction ¶
func UseSystemInstruction(sysInstructionOptions ...SystemInstructionOptfion) UseOptionFunc
func UseTemperature ¶
func UseTemperature(v float32) UseOptionFunc
func UseToolJSONOutput ¶ added in v1.1.0
func UseToolJSONOutput(conn *Conn, toolName string) UseOptionFunc
func UseTopP ¶
func UseTopP(v float32) UseOptionFunc
Click to show internal directories.
Click to hide internal directories.