From 88898740bc68808da2755ebb521631fa882368b7 Mon Sep 17 00:00:00 2001 From: conneroisu Date: Tue, 10 Sep 2024 21:51:21 -0400 Subject: [PATCH] make docs --- README.md | 533 +++++++++--------------------------------------------- 1 file changed, 90 insertions(+), 443 deletions(-) diff --git a/README.md b/README.md index 5c14c1f..26c17c7 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,6 @@ Features: - [Constants](<#constants>) - [Variables](<#variables>) -- [func NewProperties\(\) \*orderedmap.OrderedMap\[string, \*Schema\]](<#NewProperties>) - [func ToSnakeCase\(str string\) string](<#ToSnakeCase>) - [type APIError](<#APIError>) - [func \(e \*APIError\) Error\(\) string](<#APIError.Error>) @@ -97,7 +96,7 @@ Features: - [type Client](<#Client>) - [func NewClient\(groqAPIKey string, opts ...Opts\) \(\*Client, error\)](<#NewClient>) - [func \(c \*Client\) CreateChatCompletion\(ctx context.Context, request ChatCompletionRequest\) \(response ChatCompletionResponse, err error\)](<#Client.CreateChatCompletion>) - - [func \(c \*Client\) CreateChatCompletionJSON\(ctx context.Context, request ChatCompletionRequest, output json.Marshaler\) \(err error\)](<#Client.CreateChatCompletionJSON>) + - [func \(c \*Client\) CreateChatCompletionJSON\(ctx context.Context, request ChatCompletionRequest, output any\) \(err error\)](<#Client.CreateChatCompletionJSON>) - [func \(c \*Client\) CreateChatCompletionStream\(ctx context.Context, request ChatCompletionRequest\) \(stream \*ChatCompletionStream, err error\)](<#Client.CreateChatCompletionStream>) - [func \(c \*Client\) CreateCompletion\(ctx context.Context, request CompletionRequest\) \(response CompletionResponse, err error\)](<#Client.CreateCompletion>) - [func \(c \*Client\) CreateCompletionStream\(ctx context.Context, request CompletionRequest\) \(\*CompletionStream, error\)](<#Client.CreateCompletionStream>) @@ -112,7 +111,6 @@ Features: - [type DefaultErrorAccumulator](<#DefaultErrorAccumulator>) - [func \(e \*DefaultErrorAccumulator\) Bytes\(\) \(errBytes \[\]byte\)](<#DefaultErrorAccumulator.Bytes>) - [func \(e \*DefaultErrorAccumulator\) Write\(p \[\]byte\) error](<#DefaultErrorAccumulator.Write>) -- [type Definitions](<#Definitions>) - [type Endpoint](<#Endpoint>) - [type ErrChatCompletionInvalidModel](<#ErrChatCompletionInvalidModel>) - [func \(e ErrChatCompletionInvalidModel\) Error\(\) string](<#ErrChatCompletionInvalidModel.Error>) @@ -134,13 +132,6 @@ Features: - [type FunctionCall](<#FunctionCall>) - [type FunctionDefinition](<#FunctionDefinition>) - [type HarmfulCategory](<#HarmfulCategory>) -- [type ID](<#ID>) - - [func \(id ID\) Add\(path string\) ID](<#ID.Add>) - - [func \(id ID\) Anchor\(name string\) ID](<#ID.Anchor>) - - [func \(id ID\) Base\(\) ID](<#ID.Base>) - - [func \(id ID\) Def\(name string\) ID](<#ID.Def>) - - [func \(id ID\) String\(\) string](<#ID.String>) - - [func \(id ID\) Validate\(\) error](<#ID.Validate>) - [type ImageURLDetail](<#ImageURLDetail>) - [type LogProb](<#LogProb>) - [type LogProbs](<#LogProbs>) @@ -156,19 +147,10 @@ Features: - [type PromptFilterResult](<#PromptFilterResult>) - [type RateLimitHeaders](<#RateLimitHeaders>) - [type RawResponse](<#RawResponse>) -- [type Reflector](<#Reflector>) - - [func \(r \*Reflector\) Reflect\(v any\) \*Schema](<#Reflector.Reflect>) - - [func \(r \*Reflector\) ReflectFromType\(t reflect.Type\) \*Schema](<#Reflector.ReflectFromType>) - - [func \(r \*Reflector\) SetBaseSchemaID\(id string\)](<#Reflector.SetBaseSchemaID>) - [type ResetTime](<#ResetTime>) - [func \(r ResetTime\) String\(\) string](<#ResetTime.String>) - [func \(r ResetTime\) Time\(\) time.Time](<#ResetTime.Time>) - [type Role](<#Role>) -- [type Schema](<#Schema>) - - [func Reflect\(v any\) \*Schema](<#Reflect>) - - [func ReflectFromType\(t reflect.Type\) \*Schema](<#ReflectFromType>) - - [func \(t \*Schema\) MarshalJSON\(\) \(\[\]byte, error\)](<#Schema.MarshalJSON>) - - [func \(t \*Schema\) UnmarshalJSON\(data \[\]byte\) error](<#Schema.UnmarshalJSON>) - [type Segments](<#Segments>) - [type StreamOptions](<#StreamOptions>) - [type Tool](<#Tool>) @@ -242,17 +224,6 @@ const ( ## Variables - - -```go -var ( - // TrueSchema defines a schema with a true value - TrueSchema = &Schema{boolean: &[]bool{true}[0]} - // FalseSchema defines a schema with a false value - FalseSchema = &Schema{boolean: &[]bool{false}[0]} -) -``` - ```go @@ -352,23 +323,8 @@ var ( ) ``` -Version is the JSON Schema version. - -```go -var Version = "https://json-schema.org/draft/2020-12/schema" -``` - - -## func [NewProperties]() - -```go -func NewProperties() *orderedmap.OrderedMap[string, *Schema] -``` - -NewProperties is a helper method to instantiate a new properties ordered map. - -## func [ToSnakeCase]() +## func [ToSnakeCase]() ```go func ToSnakeCase(str string) string @@ -468,13 +424,14 @@ type AudioResponseFormat string ``` -## type [ChatCompletionChoice]() +## type [ChatCompletionChoice]() ChatCompletionChoice represents the chat completion choice. ```go type ChatCompletionChoice struct { - Index int `json:"index"` // Index is the index of the choice. + Index int `json:"index"` // Index is the index of the choice. + // Message is the chat completion message of the choice. Message ChatCompletionMessage `json:"message"` // Message is the chat completion message of the choice. // FinishReason is the finish reason of the choice. // @@ -484,13 +441,16 @@ type ChatCompletionChoice struct { // function_call: The model decided to call a function // content_filter: Omitted content due to a flag from our content filters // null: API response still in progress or incomplete - FinishReason FinishReason `json:"finish_reason"` // FinishReason is the finish reason of the choice. - LogProbs *LogProbs `json:"logprobs,omitempty"` // LogProbs is the log probs of the choice. + FinishReason FinishReason `json:"finish_reason"` // FinishReason is the finish reason of the choice. + // LogProbs is the log probs of the choice. + // + // This is basically the probability of the model choosing the token. + LogProbs *LogProbs `json:"logprobs,omitempty"` // LogProbs is the log probs of the choice. } ``` -## type [ChatCompletionMessage]() +## type [ChatCompletionMessage]() ChatCompletionMessage represents the chat completion message. @@ -518,67 +478,55 @@ type ChatCompletionMessage struct { ``` -### func \(ChatCompletionMessage\) [MarshalJSON]() +### func \(ChatCompletionMessage\) [MarshalJSON]() ```go func (m ChatCompletionMessage) MarshalJSON() ([]byte, error) ``` -MarshalJSON implements the json.Marshaler interface. +MarshalJSON method implements the json.Marshaler interface. -### func \(\*ChatCompletionMessage\) [UnmarshalJSON]() +### func \(\*ChatCompletionMessage\) [UnmarshalJSON]() ```go func (m *ChatCompletionMessage) UnmarshalJSON(bs []byte) (err error) ``` -UnmarshalJSON implements the json.Unmarshaler interface. +UnmarshalJSON method implements the json.Unmarshaler interface. -## type [ChatCompletionRequest]() +## type [ChatCompletionRequest]() ChatCompletionRequest represents a request structure for the chat completion API. ```go type ChatCompletionRequest struct { - Model Model `json:"model"` // Model is the model of the chat completion request. - Messages []ChatCompletionMessage `json:"messages"` // Messages is the messages of the chat completion request. - MaxTokens int `json:"max_tokens,omitempty"` // MaxTokens is the max tokens of the chat completion request. - Temperature float32 `json:"temperature,omitempty"` // Temperature is the temperature of the chat completion request. - TopP float32 `json:"top_p,omitempty"` // TopP is the top p of the chat completion request. - N int `json:"n,omitempty"` // N is the n of the chat completion request. - Stream bool `json:"stream,omitempty"` // Stream is the stream of the chat completion request. - Stop []string `json:"stop,omitempty"` // Stop is the stop of the chat completion request. - PresencePenalty float32 `json:"presence_penalty,omitempty"` // PresencePenalty is the presence penalty of the chat completion request. - ResponseFormat *ChatCompletionResponseFormat `json:"response_format,omitempty"` // ResponseFormat is the response format of the chat completion request. - Seed *int `json:"seed,omitempty"` // Seed is the seed of the chat completion request. - FrequencyPenalty float32 `json:"frequency_penalty,omitempty"` // FrequencyPenalty is the frequency penalty of the chat completion request. - // LogitBias is must be a token id string (specified by their token ID in the tokenizer), not a word string. - // incorrect: `"logit_bias":{"You": 6}`, correct: `"logit_bias":{"1639": 6}` - // refs: https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias - LogitBias map[string]int `json:"logit_bias,omitempty"` - // LogProbs indicates whether to return log probabilities of the output tokens or not. - // If true, returns the log probabilities of each output token returned in the content of message. - // This option is currently not available on the gpt-4-vision-preview model. - LogProbs bool `json:"logprobs,omitempty"` - // TopLogProbs is an integer between 0 and 5 specifying the number of most likely tokens to return at each - // token position, each with an associated log probability. - // logprobs must be set to true if this parameter is used. - TopLogProbs int `json:"top_logprobs,omitempty"` - User string `json:"user,omitempty"` - Tools []Tool `json:"tools,omitempty"` - // This can be either a string or an ToolChoice object. - ToolChoice any `json:"tool_choice,omitempty"` - // Options for streaming response. Only set this when you set stream: true. - StreamOptions *StreamOptions `json:"stream_options,omitempty"` - // Disable the default behavior of parallel tool calls by setting it: false. - ParallelToolCalls any `json:"parallel_tool_calls,omitempty"` + Model Model `json:"model"` // Model is the model of the chat completion request. + Messages []ChatCompletionMessage `json:"messages"` // Messages is the messages of the chat completion request. These act as the prompt for the model. + MaxTokens int `json:"max_tokens,omitempty"` // MaxTokens is the max tokens of the chat completion request. + Temperature float32 `json:"temperature,omitempty"` // Temperature is the temperature of the chat completion request. + TopP float32 `json:"top_p,omitempty"` // TopP is the top p of the chat completion request. + N int `json:"n,omitempty"` // N is the n of the chat completion request. + Stream bool `json:"stream,omitempty"` // Stream is the stream of the chat completion request. + Stop []string `json:"stop,omitempty"` // Stop is the stop of the chat completion request. + PresencePenalty float32 `json:"presence_penalty,omitempty"` // PresencePenalty is the presence penalty of the chat completion request. + ResponseFormat *ChatCompletionResponseFormat `json:"response_format,omitempty"` // ResponseFormat is the response format of the chat completion request. + Seed *int `json:"seed,omitempty"` // Seed is the seed of the chat completion request. + FrequencyPenalty float32 `json:"frequency_penalty,omitempty"` // FrequencyPenalty is the frequency penalty of the chat completion request. + LogitBias map[string]int `json:"logit_bias,omitempty"` // LogitBias is must be a token id string (specified by their token ID in the tokenizer), not a word string. incorrect: `"logit_bias":{ "You": 6}`, correct: `"logit_bias":{"1639": 6}` refs: https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias + LogProbs bool `json:"logprobs,omitempty"` // LogProbs indicates whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message. This option is currently not available on the gpt-4-vision-preview model. + TopLogProbs int `json:"top_logprobs,omitempty"` // TopLogProbs is an integer between 0 and 5 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used. + User string `json:"user,omitempty"` // User is the user of the chat completion request. + Tools []Tool `json:"tools,omitempty"` // Tools is the tools of the chat completion request. + ToolChoice any `json:"tool_choice,omitempty"` // This can be either a string or an ToolChoice object. + StreamOptions *StreamOptions `json:"stream_options,omitempty"` // Options for streaming response. Only set this when you set stream: true. + ParallelToolCalls any `json:"parallel_tool_calls,omitempty"` // Disable the default behavior of parallel tool calls by setting it: false. } ``` -## type [ChatCompletionResponse]() +## type [ChatCompletionResponse]() ChatCompletionResponse represents a response structure for chat completion API. @@ -597,7 +545,7 @@ type ChatCompletionResponse struct { ``` -### func \(\*ChatCompletionResponse\) [SetHeader]() +### func \(\*ChatCompletionResponse\) [SetHeader]() ```go func (r *ChatCompletionResponse) SetHeader(h http.Header) @@ -606,33 +554,45 @@ func (r *ChatCompletionResponse) SetHeader(h http.Header) SetHeader sets the header of the response. -## type [ChatCompletionResponseFormat]() +## type [ChatCompletionResponseFormat]() ChatCompletionResponseFormat is the chat completion response format. ```go type ChatCompletionResponseFormat struct { - Type ChatCompletionResponseFormatType `json:"type,omitempty"` // Type is the type of the chat completion response format. - JSONSchema *ChatCompletionResponseFormatJSONSchema `json:"json_schema,omitempty"` // JSONSchema is the json schema of the chat completion response format. + // Type is the type of the chat completion response format. + Type ChatCompletionResponseFormatType `json:"type,omitempty"` + // JSONSchema is the json schema of the chat completion response format. + JSONSchema *ChatCompletionResponseFormatJSONSchema `json:"json_schema,omitempty"` } ``` -## type [ChatCompletionResponseFormatJSONSchema]() +## type [ChatCompletionResponseFormatJSONSchema]() ChatCompletionResponseFormatJSONSchema is the chat completion response format json schema. ```go type ChatCompletionResponseFormatJSONSchema struct { - Name string `json:"name"` // Name is the name of the chat completion response format json schema. - Description string `json:"description,omitempty"` // Description is the description of the chat completion response format json schema. - Schema json.Marshaler `json:"schema"` // Schema is the schema of the chat completion response format json schema. - Strict bool `json:"strict"` // Strict is the strict of the chat completion response format json schema. + // Name is the name of the chat completion response format json schema. + // + // it is used to further identify the schema in the response. + Name string `json:"name"` + // response format json schema. + // Description is the description of the chat completion response format + // json schema. + Description string `json:"description,omitempty"` + // description of the chat completion response format json schema. + // Schema is the schema of the chat completion response format json schema. + Schema schema `json:"schema"` + // Strict determines whether to enforce the schema upon the generated + // content. + Strict bool `json:"strict"` } ``` -## type [ChatCompletionResponseFormatType]() +## type [ChatCompletionResponseFormatType]() ChatCompletionResponseFormatType is the chat completion response format type. @@ -643,7 +603,7 @@ type ChatCompletionResponseFormatType string ``` -## type [ChatCompletionStream]() +## type [ChatCompletionStream]() ChatCompletionStream is a stream of ChatCompletionStreamResponse. @@ -656,7 +616,7 @@ type ChatCompletionStream struct { ``` -## type [ChatCompletionStreamChoice]() +## type [ChatCompletionStreamChoice]() ChatCompletionStreamChoice represents a response structure for chat completion API. @@ -669,7 +629,7 @@ type ChatCompletionStreamChoice struct { ``` -## type [ChatCompletionStreamChoiceDelta]() +## type [ChatCompletionStreamChoiceDelta]() ChatCompletionStreamChoiceDelta represents a response structure for chat completion API. @@ -683,7 +643,7 @@ type ChatCompletionStreamChoiceDelta struct { ``` -## type [ChatCompletionStreamResponse]() +## type [ChatCompletionStreamResponse]() ChatCompletionStreamResponse represents a response structure for chat completion API. @@ -706,7 +666,7 @@ type ChatCompletionStreamResponse struct { ``` -## type [ChatMessageImageURL]() +## type [ChatMessageImageURL]() ChatMessageImageURL represents the chat message image url. @@ -718,7 +678,7 @@ type ChatMessageImageURL struct { ``` -## type [ChatMessagePart]() +## type [ChatMessagePart]() ChatMessagePart represents the chat message part of a chat completion message. @@ -731,7 +691,7 @@ type ChatMessagePart struct { ``` -## type [ChatMessagePartType]() +## type [ChatMessagePartType]() ChatMessagePartType is the chat message part type. @@ -763,31 +723,31 @@ func NewClient(groqAPIKey string, opts ...Opts) (*Client, error) NewClient creates a new Groq client. -### func \(\*Client\) [CreateChatCompletion]() +### func \(\*Client\) [CreateChatCompletion]() ```go func (c *Client) CreateChatCompletion(ctx context.Context, request ChatCompletionRequest) (response ChatCompletionResponse, err error) ``` -CreateChatCompletion is an API call to create a chat completion. +CreateChatCompletion method is an API call to create a chat completion. -### func \(\*Client\) [CreateChatCompletionJSON]() +### func \(\*Client\) [CreateChatCompletionJSON]() ```go -func (c *Client) CreateChatCompletionJSON(ctx context.Context, request ChatCompletionRequest, output json.Marshaler) (err error) +func (c *Client) CreateChatCompletionJSON(ctx context.Context, request ChatCompletionRequest, output any) (err error) ``` -CreateChatCompletionJSON is an API call to create a chat completion w/ object output. +CreateChatCompletionJSON method is an API call to create a chat completion w/ object output. -### func \(\*Client\) [CreateChatCompletionStream]() +### func \(\*Client\) [CreateChatCompletionStream]() ```go func (c *Client) CreateChatCompletionStream(ctx context.Context, request ChatCompletionRequest) (stream *ChatCompletionStream, err error) ``` -CreateChatCompletionStream is an API call to create a chat completion w/ streaming support. +CreateChatCompletionStream method is an API call to create a chat completion w/ streaming support. If set, tokens will be sent as data\-only server\-sent events as they become available, with the stream terminated by a data: \[DONE\] message. @@ -954,15 +914,6 @@ func (e *DefaultErrorAccumulator) Write(p []byte) error Write writes bytes to the error accumulator. - -## type [Definitions]() - -Definitions hold schema definitions. http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.26 RFC draft\-wright\-json\-schema\-validation\-00, section 5.26 - -```go -type Definitions map[string]*Schema -``` - ## type [Endpoint]() @@ -1106,7 +1057,7 @@ func (e ErrTooManyEmptyStreamMessages) Error() string Error returns the error message. -## type [FinishReason]() +## type [FinishReason]() FinishReason is the finish reason. string @@ -1115,7 +1066,7 @@ type FinishReason string ``` -### func \(FinishReason\) [MarshalJSON]() +### func \(FinishReason\) [MarshalJSON]() ```go func (r FinishReason) MarshalJSON() ([]byte, error) @@ -1146,7 +1097,7 @@ const ( ``` -## type [FunctionCall]() +## type [FunctionCall]() FunctionCall represents a function call. @@ -1158,7 +1109,7 @@ type FunctionCall struct { ``` -## type [FunctionDefinition]() +## type [FunctionDefinition]() FunctionDefinition represents the function definition. @@ -1231,77 +1182,8 @@ const ( ) ``` - -## type [ID]() - -ID represents a Schema ID type which should always be a URI. See draft\-bhutton\-json\-schema\-00 section 8.2.1 - -```go -type ID string -``` - -EmptyID is used to explicitly define an ID with no value. - -```go -const EmptyID ID = "" -``` - - -### func \(ID\) [Add]() - -```go -func (id ID) Add(path string) ID -``` - -Add appends the provided path to the id, and removes any anchor data that might be there. - - -### func \(ID\) [Anchor]() - -```go -func (id ID) Anchor(name string) ID -``` - -Anchor sets the anchor part of the schema URI. - - -### func \(ID\) [Base]() - -```go -func (id ID) Base() ID -``` - -Base removes any anchor information from the schema - - -### func \(ID\) [Def]() - -```go -func (id ID) Def(name string) ID -``` - -Def adds or replaces a definition identifier. - - -### func \(ID\) [String]() - -```go -func (id ID) String() string -``` - -String provides string version of ID - - -### func \(ID\) [Validate]() - -```go -func (id ID) Validate() error -``` - -Validate is used to check if the ID looks like a proper schema. This is done by parsing the ID as a URL and checking it has all the relevant parts. - -## type [ImageURLDetail]() +## type [ImageURLDetail]() ImageURLDetail is the image url detail. @@ -1312,7 +1194,7 @@ type ImageURLDetail string ``` -## type [LogProb]() +## type [LogProb]() LogProb represents the probability information for a token. @@ -1326,7 +1208,7 @@ type LogProb struct { ``` -## type [LogProbs]() +## type [LogProbs]() LogProbs is the top\-level structure containing the log probability information. @@ -1420,7 +1302,7 @@ func WithLogger(logger zerolog.Logger) Opts WithLogger sets the logger for the Groq client. -## type [PromptAnnotation]() +## type [PromptAnnotation]() PromptAnnotation represents the prompt annotation. @@ -1431,7 +1313,7 @@ type PromptAnnotation struct { ``` -## type [PromptFilterResult]() +## type [PromptFilterResult]() PromptFilterResult represents a response structure for chat completion API. @@ -1470,130 +1352,6 @@ type RawResponse struct { } ``` - -## type [Reflector]() - -A Reflector reflects values into a Schema. - -```go -type Reflector struct { - // BaseSchemaID defines the URI that will be used as a base to determine Schema - // IDs for models. For example, a base Schema ID of `https://invopop.com/schemas` - // when defined with a struct called `User{}`, will result in a schema with an - // ID set to `https://invopop.com/schemas/user`. - // - // If no `BaseSchemaID` is provided, we'll take the type's complete package path - // and use that as a base instead. Set `Anonymous` to try if you do not want to - // include a schema ID. - BaseSchemaID ID - - // Anonymous when true will hide the auto-generated Schema ID and provide what is - // known as an "anonymous schema". As a rule, this is not recommended. - Anonymous bool - - // AssignAnchor when true will use the original struct's name as an anchor inside - // every definition, including the root schema. These can be useful for having a - // reference to the original struct's name in CamelCase instead of the snake-case used - // by default for URI compatibility. - // - // Anchors do not appear to be widely used out in the wild, so at this time the - // anchors themselves will not be used inside generated schema. - AssignAnchor bool - - // AllowAdditionalProperties will cause the Reflector to generate a schema - // without additionalProperties set to 'false' for all struct types. This means - // the presence of additional keys in JSON objects will not cause validation - // to fail. Note said additional keys will simply be dropped when the - // validated JSON is unmarshaled. - AllowAdditionalProperties bool - - // RequiredFromJSONSchemaTags will cause the Reflector to generate a schema - // that requires any key tagged with `jsonschema:required`, overriding the - // default of requiring any key *not* tagged with `json:,omitempty`. - RequiredFromJSONSchemaTags bool - - // Do not reference definitions. This will remove the top-level $defs map and - // instead cause the entire structure of types to be output in one tree. The - // list of type definitions (`$defs`) will not be included. - DoNotReference bool - - // ExpandedStruct when true will include the reflected type's definition in the - // root as opposed to a definition with a reference. - ExpandedStruct bool - - // FieldNameTag will change the tag used to get field names. json tags are used by default. - FieldNameTag string - - // IgnoredTypes defines a slice of types that should be ignored in the schema, - // switching to just allowing additional properties instead. - IgnoredTypes []any - - // Lookup allows a function to be defined that will provide a custom mapping of - // types to Schema IDs. This allows existing schema documents to be referenced - // by their ID instead of being embedded into the current schema definitions. - // Reflected types will never be pointers, only underlying elements. - Lookup func(reflect.Type) ID - - // Mapper is a function that can be used to map custom Go types to jsonschema schemas. - Mapper func(reflect.Type) *Schema - - // Namer allows customizing of type names. The default is to use the type's name - // provided by the reflect package. - Namer func(reflect.Type) string - - // KeyNamer allows customizing of key names. - // The default is to use the key's name as is, or the json tag if present. - // If a json tag is present, KeyNamer will receive the tag's name as an argument, not the original key name. - KeyNamer func(string) string - - // AdditionalFields allows adding structfields for a given type - AdditionalFields func(reflect.Type) []reflect.StructField - - // CommentMap is a dictionary of fully qualified go types and fields to comment - // strings that will be used if a description has not already been provided in - // the tags. Types and fields are added to the package path using "." as a - // separator. - // - // Type descriptions should be defined like: - // - // map[string]string{"github.com/conneroisu/groq.Reflector": "A Reflector reflects values into a Schema."} - // - // And Fields defined as: - // - // map[string]string{"github.com/conneroisu/groq.Reflector.DoNotReference": "Do not reference definitions."} - // - // See also: AddGoComments - CommentMap map[string]string -} -``` - - -### func \(\*Reflector\) [Reflect]() - -```go -func (r *Reflector) Reflect(v any) *Schema -``` - -Reflect reflects to Schema from a value. - - -### func \(\*Reflector\) [ReflectFromType]() - -```go -func (r *Reflector) ReflectFromType(t reflect.Type) *Schema -``` - -ReflectFromType generates root schema - - -### func \(\*Reflector\) [SetBaseSchemaID]() - -```go -func (r *Reflector) SetBaseSchemaID(id string) -``` - -SetBaseSchemaID is a helper use to be able to set the reflectors base schema ID from a string as opposed to then ID instance. - ## type [ResetTime]() @@ -1622,7 +1380,7 @@ func (r ResetTime) Time() time.Time Time returns the time.Time representation of the ResetTime. -## type [Role]() +## type [Role]() Role is the role of the chat completion message. @@ -1632,117 +1390,6 @@ string type Role string ``` - -## type [Schema]() - -Schema represents a JSON Schema object type. RFC draft\-bhutton\-json\-schema\-00 section 4.3 - -```go -type Schema struct { - // RFC draft-bhutton-json-schema-00 - Version string `json:"$schema,omitempty"` // section 8.1.1 - ID ID `json:"$id,omitempty"` // section 8.2.1 - Anchor string `json:"$anchor,omitempty"` // section 8.2.2 - Ref string `json:"$ref,omitempty"` // section 8.2.3.1 - DynamicRef string `json:"$dynamicRef,omitempty"` // section 8.2.3.2 - Definitions Definitions `json:"$defs,omitempty"` // section 8.2.4 - Comments string `json:"$comment,omitempty"` // section 8.3 - // RFC draft-bhutton-json-schema-00 section 10.2.1 (Sub-schemas with logic) - AllOf []*Schema `json:"allOf,omitempty"` // section 10.2.1.1 - AnyOf []*Schema `json:"anyOf,omitempty"` // section 10.2.1.2 - OneOf []*Schema `json:"oneOf,omitempty"` // section 10.2.1.3 - Not *Schema `json:"not,omitempty"` // section 10.2.1.4 - // RFC draft-bhutton-json-schema-00 section 10.2.2 (Apply sub-schemas conditionally) - If *Schema `json:"if,omitempty"` // section 10.2.2.1 - Then *Schema `json:"then,omitempty"` // section 10.2.2.2 - Else *Schema `json:"else,omitempty"` // section 10.2.2.3 - DependentSchemas map[string]*Schema `json:"dependentSchemas,omitempty"` // section 10.2.2.4 - // RFC draft-bhutton-json-schema-00 section 10.3.1 (arrays) - PrefixItems []*Schema `json:"prefixItems,omitempty"` // section 10.3.1.1 - Items *Schema `json:"items,omitempty"` // section 10.3.1.2 (replaces additionalItems) - Contains *Schema `json:"contains,omitempty"` // section 10.3.1.3 - // RFC draft-bhutton-json-schema-00 section 10.3.2 (sub-schemas) - Properties *orderedmap.OrderedMap[string, *Schema] `json:"properties,omitempty"` // section 10.3.2.1 - PatternProperties map[string]*Schema `json:"patternProperties,omitempty"` // section 10.3.2.2 - AdditionalProperties *Schema `json:"additionalProperties,omitempty"` // section 10.3.2.3 - PropertyNames *Schema `json:"propertyNames,omitempty"` // section 10.3.2.4 - // RFC draft-bhutton-json-schema-validation-00, section 6 - Type string `json:"type,omitempty"` // section 6.1.1 - Enum []any `json:"enum,omitempty"` // section 6.1.2 - Const any `json:"const,omitempty"` // section 6.1.3 - MultipleOf json.Number `json:"multipleOf,omitempty"` // section 6.2.1 - Maximum json.Number `json:"maximum,omitempty"` // section 6.2.2 - ExclusiveMaximum json.Number `json:"exclusiveMaximum,omitempty"` // section 6.2.3 - Minimum json.Number `json:"minimum,omitempty"` // section 6.2.4 - ExclusiveMinimum json.Number `json:"exclusiveMinimum,omitempty"` // section 6.2.5 - MaxLength *uint64 `json:"maxLength,omitempty"` // section 6.3.1 - MinLength *uint64 `json:"minLength,omitempty"` // section 6.3.2 - Pattern string `json:"pattern,omitempty"` // section 6.3.3 - MaxItems *uint64 `json:"maxItems,omitempty"` // section 6.4.1 - MinItems *uint64 `json:"minItems,omitempty"` // section 6.4.2 - UniqueItems bool `json:"uniqueItems,omitempty"` // section 6.4.3 - MaxContains *uint64 `json:"maxContains,omitempty"` // section 6.4.4 - MinContains *uint64 `json:"minContains,omitempty"` // section 6.4.5 - MaxProperties *uint64 `json:"maxProperties,omitempty"` // section 6.5.1 - MinProperties *uint64 `json:"minProperties,omitempty"` // section 6.5.2 - Required []string `json:"required,omitempty"` // section 6.5.3 - DependentRequired map[string][]string `json:"dependentRequired,omitempty"` // section 6.5.4 - // RFC draft-bhutton-json-schema-validation-00, section 7 - Format string `json:"format,omitempty"` - // RFC draft-bhutton-json-schema-validation-00, section 8 - ContentEncoding string `json:"contentEncoding,omitempty"` // section 8.3 - ContentMediaType string `json:"contentMediaType,omitempty"` // section 8.4 - ContentSchema *Schema `json:"contentSchema,omitempty"` // section 8.5 - // RFC draft-bhutton-json-schema-validation-00, section 9 - Title string `json:"title,omitempty"` // section 9.1 - Description string `json:"description,omitempty"` // section 9.1 - Default any `json:"default,omitempty"` // section 9.2 - Deprecated bool `json:"deprecated,omitempty"` // section 9.3 - ReadOnly bool `json:"readOnly,omitempty"` // section 9.4 - WriteOnly bool `json:"writeOnly,omitempty"` // section 9.4 - Examples []any `json:"examples,omitempty"` // section 9.5 - - Extras map[string]any `json:"-"` - // contains filtered or unexported fields -} -``` - - -### func [Reflect]() - -```go -func Reflect(v any) *Schema -``` - -Reflect reflects to Schema from a value using the default Reflector - - -### func [ReflectFromType]() - -```go -func ReflectFromType(t reflect.Type) *Schema -``` - -ReflectFromType generates root schema using the default Reflector - - -### func \(\*Schema\) [MarshalJSON]() - -```go -func (t *Schema) MarshalJSON() ([]byte, error) -``` - -MarshalJSON is used to serialize a schema object or boolean. - - -### func \(\*Schema\) [UnmarshalJSON]() - -```go -func (t *Schema) UnmarshalJSON(data []byte) error -``` - -UnmarshalJSON is used to parse a schema object or boolean. - ## type [Segments]() @@ -1765,7 +1412,7 @@ type Segments []struct { ``` -## type [StreamOptions]() +## type [StreamOptions]() StreamOptions represents the stream options. @@ -1780,7 +1427,7 @@ type StreamOptions struct { ``` -## type [Tool]() +## type [Tool]() Tool represents the tool. @@ -1792,7 +1439,7 @@ type Tool struct { ``` -## type [ToolCall]() +## type [ToolCall]() ToolCall represents a tool call. @@ -1807,7 +1454,7 @@ type ToolCall struct { ``` -## type [ToolChoice]() +## type [ToolChoice]() ToolChoice represents the tool choice. @@ -1819,7 +1466,7 @@ type ToolChoice struct { ``` -## type [ToolFunction]() +## type [ToolFunction]() ToolFunction represents the tool function. @@ -1830,7 +1477,7 @@ type ToolFunction struct { ``` -## type [ToolType]() +## type [ToolType]() ToolType is the tool type. @@ -1841,7 +1488,7 @@ type ToolType string ``` -## type [TopLogProbs]() +## type [TopLogProbs]() TopLogProbs represents the top log probs.