groq

package module
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: Apache-2.0 Imports: 17 Imported by: 4

README

Groq Go API Library

Go Reference

The Groq Go library provides convenient access to the Groq REST API from applications written in Go. The full API of this library can be found in api.md.

It is generated with Stainless.

Installation

import (
	"github.com/conneroisu/groq-go" // imported as groq
)

Or to pin the version:

go get -u 'github.com/conneroisu/groq-go@v0.1.0-alpha.1'

Requirements

This library requires Go 1.18+.

Usage

The full API of this library can be found in api.md.

package main

import (
	"context"
	"fmt"

	"github.com/conneroisu/groq-go"
	"github.com/conneroisu/groq-go/option"
)

func main() {
	client := groq.NewClient(
		option.WithBearerToken("My Bearer Token"), // defaults to os.LookupEnv("GROQ_BEARER_TOKEN")
	)
	chatCompletionNewResponse, err := client.Chat.Completions.New(context.TODO(), groq.ChatCompletionNewParams{
		Messages: groq.F([]groq.ChatCompletionNewParamsMessageUnion{groq.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessage{
			Content: groq.F("content"),
			Role:    groq.F(groq.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRoleSystem),
		}}),
		Model: groq.F(groq.ChatCompletionNewParamsModelGemma7bIt),
	})
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", chatCompletionNewResponse.ID)
}

Request fields

All request parameters are wrapped in a generic Field type, which we use to distinguish zero values from null or omitted fields.

This prevents accidentally sending a zero value if you forget a required parameter, and enables explicitly sending null, false, '', or 0 on optional parameters. Any field not specified is not sent.

To construct fields with values, use the helpers String(), Int(), Float(), or most commonly, the generic F[T](). To send a null, use Null[T](), and to send a nonconforming value, use Raw[T](any). For example:

params := FooParams{
	Name: groq.F("hello"),

	// Explicitly send `"description": null`
	Description: groq.Null[string](),

	Point: groq.F(groq.Point{
		X: groq.Int(0),
		Y: groq.Int(1),

		// In cases where the API specifies a given type,
		// but you want to send something else, use `Raw`:
		Z: groq.Raw[int64](0.01), // sends a float
	}),
}
Response objects

All fields in response structs are value types (not pointers or wrappers).

If a given field is null, not present, or invalid, the corresponding field will simply be its zero value.

All response structs also include a special JSON field, containing more detailed information about each property, which you can use like so:

if res.Name == "" {
	// true if `"name"` is either not present or explicitly null
	res.JSON.Name.IsNull()

	// true if the `"name"` key was not present in the repsonse JSON at all
	res.JSON.Name.IsMissing()

	// When the API returns data that cannot be coerced to the expected type:
	if res.JSON.Name.IsInvalid() {
		raw := res.JSON.Name.Raw()

		legacyName := struct{
			First string `json:"first"`
			Last  string `json:"last"`
		}{}
		json.Unmarshal([]byte(raw), &legacyName)
		name = legacyName.First + " " + legacyName.Last
	}
}

These .JSON structs also include an Extras map containing any properties in the json response that were not specified in the struct. This can be useful for API features not yet present in the SDK.

body := res.JSON.ExtraFields["my_unexpected_field"].Raw()
RequestOptions

This library uses the functional options pattern. Functions defined in the option package return a RequestOption, which is a closure that mutates a RequestConfig. These options can be supplied to the client or at individual requests. For example:

client := groq.NewClient(
	// Adds a header to every request made by the client
	option.WithHeader("X-Some-Header", "custom_header_info"),
)

client.Chat.Completions.New(context.TODO(), ...,
	// Override the header
	option.WithHeader("X-Some-Header", "some_other_custom_header_info"),
	// Add an undocumented field to the request body, using sjson syntax
	option.WithJSONSet("some.json.path", map[string]string{"my": "object"}),
)

See the full list of request options.

Pagination

This library provides some conveniences for working with paginated list endpoints.

You can use .ListAutoPaging() methods to iterate through items across all pages:

Or you can use simple .List() methods to fetch a single page and receive a standard response object with additional helper methods like .GetNextPage(), e.g.:

Errors

When the API returns a non-success status code, we return an error with type *groq.Error. This contains the StatusCode, *http.Request, and *http.Response values of the request, as well as the JSON of the error body (much like other response objects in the SDK).

To handle errors, we recommend that you use the errors.As pattern:

_, err := client.Chat.Completions.New(context.TODO(), groq.ChatCompletionNewParams{
	Messages: groq.F([]groq.ChatCompletionNewParamsMessageUnion{groq.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessage{
		Content: groq.F("content"),
		Role:    groq.F(groq.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRoleSystem),
	}}),
	Model: groq.F(groq.ChatCompletionNewParamsModelGemma7bIt),
})
if err != nil {
	var apierr *groq.Error
	if errors.As(err, &apierr) {
		println(string(apierr.DumpRequest(true)))  // Prints the serialized HTTP request
		println(string(apierr.DumpResponse(true))) // Prints the serialized HTTP response
	}
	panic(err.Error()) // GET "/openai/v1/chat/completions": 400 Bad Request { ... }
}

When other errors occur, they are returned unwrapped; for example, if HTTP transport fails, you might receive *url.Error wrapping *net.OpError.

Timeouts

Requests do not time out by default; use context to configure a timeout for a request lifecycle.

Note that if a request is retried, the context timeout does not start over. To set a per-retry timeout, use option.WithRequestTimeout().

// This sets the timeout for the request, including all the retries.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
client.Chat.Completions.New(
	ctx,
	groq.ChatCompletionNewParams{
		Messages: groq.F([]groq.ChatCompletionNewParamsMessageUnion{groq.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessage{
			Content: groq.F("content"),
			Role:    groq.F(groq.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRoleSystem),
		}}),
		Model: groq.F(groq.ChatCompletionNewParamsModelGemma7bIt),
	},
	// This sets the per-retry timeout
	option.WithRequestTimeout(20*time.Second),
)
File uploads

Request parameters that correspond to file uploads in multipart requests are typed as param.Field[io.Reader]. The contents of the io.Reader will by default be sent as a multipart form part with the file name of "anonymous_file" and content-type of "application/octet-stream".

The file name and content-type can be customized by implementing Name() string or ContentType() string on the run-time type of io.Reader. Note that os.File implements Name() string, so a file returned by os.Open will be sent with the file name on disk.

We also provide a helper groq.FileParam(reader io.Reader, filename string, contentType string) which can be used to wrap any io.Reader with the appropriate file name and content type.

Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff. We retry by default all connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors.

You can use the WithMaxRetries option to configure or disable this:

// Configure the default for all requests:
client := groq.NewClient(
	option.WithMaxRetries(0), // default is 2
)

// Override per-request:
client.Chat.Completions.New(
	context.TODO(),
	groq.ChatCompletionNewParams{
		Messages: groq.F([]groq.ChatCompletionNewParamsMessageUnion{groq.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessage{
			Content: groq.F("content"),
			Role:    groq.F(groq.ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRoleSystem),
		}}),
		Model: groq.F(groq.ChatCompletionNewParamsModelGemma7bIt),
	},
	option.WithMaxRetries(5),
)
Making custom/undocumented requests

This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, params, or response properties, the library can still be used.

Undocumented endpoints

To make requests to undocumented endpoints, you can use client.Get, client.Post, and other HTTP verbs. RequestOptions on the client, such as retries, will be respected when making these requests.

var (
    // params can be an io.Reader, a []byte, an encoding/json serializable object,
    // or a "…Params" struct defined in this library.
    params map[string]interface{}

    // result can be an []byte, *http.Response, a encoding/json deserializable object,
    // or a model defined in this library.
    result *http.Response
)
err := client.Post(context.Background(), "/unspecified", params, &result)
if err != nil {
    …
}
Undocumented request params

To make requests using undocumented parameters, you may use either the option.WithQuerySet() or the option.WithJSONSet() methods.

params := FooNewParams{
    ID:   groq.F("id_xxxx"),
    Data: groq.F(FooNewParamsData{
        FirstName: groq.F("John"),
    }),
}
client.Foo.New(context.Background(), params, option.WithJSONSet("data.last_name", "Doe"))
Undocumented response properties

To access undocumented response properties, you may either access the raw JSON of the response as a string with result.JSON.RawJSON(), or get the raw JSON of a particular field on the result with result.JSON.Foo.Raw().

Any fields that are not present on the response struct will be saved and can be accessed by result.JSON.ExtraFields() which returns the extra fields as a map[string]Field.

Middleware

We provide option.WithMiddleware which applies the given middleware to requests.

func Logger(req *http.Request, next option.MiddlewareNext) (res *http.Response, err error) {
	// Before the request
	start := time.Now()
	LogReq(req)

	// Forward the request to the next handler
	res, err = next(req)

	// Handle stuff after the request
	end := time.Now()
	LogRes(res, err, start - end)

    return res, err
}

client := groq.NewClient(
	option.WithMiddleware(Logger),
)

When multiple middlewares are provided as variadic arguments, the middlewares are applied left to right. If option.WithMiddleware is given multiple times, for example first in the client then the method, the middleware in the client will run first and the middleware given in the method will run next.

You may also replace the default http.Client with option.WithHTTPClient(client). Only one http client is accepted (this overwrites any previous client) and receives requests after any middleware has been applied.

Semantic versioning

This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:

  1. Changes to library internals which are technically public but not intended or documented for external use. (Please open a GitHub issue to let us know if you are relying on such internals).
  2. Changes that we do not expect to impact the vast majority of users in practice.

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an issue with questions, bugs, or suggestions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(value bool) param.Field[bool]

Bool is a param field helper which helps specify bools.

func F

func F[T any](value T) param.Field[T]

F is a param field helper used to initialize a param.Field generic struct. This helps specify null, zero values, and overrides, as well as normal values. You can read more about this in our README.

func FileParam

func FileParam(reader io.Reader, filename string, contentType string) param.Field[io.Reader]

FileParam is a param field helper which helps files with a mime content-type.

func Float

func Float(value float64) param.Field[float64]

Float is a param field helper which helps specify floats.

func Int

func Int(value int64) param.Field[int64]

Int is a param field helper which helps specify integers. This is particularly helpful when specifying integer constants for fields.

func Null

func Null[T any]() param.Field[T]

Null is a param field helper which explicitly sends null to the API.

func Raw

func Raw[T any](value any) param.Field[T]

Raw is a param field helper for specifying values for fields when the type you are looking to send is different from the type that is specified in the SDK. For example, if the type of the field is an integer, but you want to send a float, you could do that by setting the corresponding field with Raw[int](0.5).

func String

func String(value string) param.Field[string]

String is a param field helper which helps specify strings.

Types

type AudioService

type AudioService struct {
	Options        []option.RequestOption
	Transcriptions *AudioTranscriptionService
	Translations   *AudioTranslationService
}

AudioService contains methods and other services that help with interacting with the groq API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewAudioService method instead.

func NewAudioService

func NewAudioService(opts ...option.RequestOption) (r *AudioService)

NewAudioService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

type AudioTranscriptionNewParams

type AudioTranscriptionNewParams struct {
	// The audio file object (not file name) to transcribe, in one of these formats:
	// flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
	File param.Field[io.Reader] `json:"file,required" format:"binary"`
	// ID of the model to use. Only `whisper-large-v3` is currently available.
	Model param.Field[AudioTranscriptionNewParamsModel] `json:"model,required"`
	// The language of the input audio. Supplying the input language in
	// [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will
	// improve accuracy and latency.
	Language param.Field[AudioTranscriptionNewParamsLanguage] `json:"language"`
	// An optional text to guide the model's style or continue a previous audio
	// segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the
	// audio language.
	Prompt param.Field[string] `json:"prompt"`
	// The format of the transcript output, in one of these options: `json`, `text`, or
	// `verbose_json`.
	ResponseFormat param.Field[AudioTranscriptionNewParamsResponseFormat] `json:"response_format"`
	// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the
	// output more random, while lower values like 0.2 will make it more focused and
	// deterministic. If set to 0, the model will use
	// [log probability](https://en.wikipedia.org/wiki/Log_probability) to
	// automatically increase the temperature until certain thresholds are hit.
	Temperature param.Field[float64] `json:"temperature"`
	// The timestamp granularities to populate for this transcription.
	// `response_format` must be set `verbose_json` to use timestamp granularities.
	// Either or both of these options are supported: `word`, or `segment`. Note: There
	// is no additional latency for segment timestamps, but generating word timestamps
	// incurs additional latency.
	TimestampGranularities param.Field[[]AudioTranscriptionNewParamsTimestampGranularity] `json:"timestamp_granularities"`
}

func (AudioTranscriptionNewParams) MarshalMultipart

func (r AudioTranscriptionNewParams) MarshalMultipart() (data []byte, contentType string, err error)

type AudioTranscriptionNewParamsLanguage

type AudioTranscriptionNewParamsLanguage string
const (
	AudioTranscriptionNewParamsLanguageEn  AudioTranscriptionNewParamsLanguage = "en"
	AudioTranscriptionNewParamsLanguageZh  AudioTranscriptionNewParamsLanguage = "zh"
	AudioTranscriptionNewParamsLanguageDe  AudioTranscriptionNewParamsLanguage = "de"
	AudioTranscriptionNewParamsLanguageEs  AudioTranscriptionNewParamsLanguage = "es"
	AudioTranscriptionNewParamsLanguageRu  AudioTranscriptionNewParamsLanguage = "ru"
	AudioTranscriptionNewParamsLanguageKo  AudioTranscriptionNewParamsLanguage = "ko"
	AudioTranscriptionNewParamsLanguageFr  AudioTranscriptionNewParamsLanguage = "fr"
	AudioTranscriptionNewParamsLanguageJa  AudioTranscriptionNewParamsLanguage = "ja"
	AudioTranscriptionNewParamsLanguagePt  AudioTranscriptionNewParamsLanguage = "pt"
	AudioTranscriptionNewParamsLanguageTr  AudioTranscriptionNewParamsLanguage = "tr"
	AudioTranscriptionNewParamsLanguagePl  AudioTranscriptionNewParamsLanguage = "pl"
	AudioTranscriptionNewParamsLanguageCa  AudioTranscriptionNewParamsLanguage = "ca"
	AudioTranscriptionNewParamsLanguageNl  AudioTranscriptionNewParamsLanguage = "nl"
	AudioTranscriptionNewParamsLanguageAr  AudioTranscriptionNewParamsLanguage = "ar"
	AudioTranscriptionNewParamsLanguageSv  AudioTranscriptionNewParamsLanguage = "sv"
	AudioTranscriptionNewParamsLanguageIt  AudioTranscriptionNewParamsLanguage = "it"
	AudioTranscriptionNewParamsLanguageID  AudioTranscriptionNewParamsLanguage = "id"
	AudioTranscriptionNewParamsLanguageHi  AudioTranscriptionNewParamsLanguage = "hi"
	AudioTranscriptionNewParamsLanguageFi  AudioTranscriptionNewParamsLanguage = "fi"
	AudioTranscriptionNewParamsLanguageVi  AudioTranscriptionNewParamsLanguage = "vi"
	AudioTranscriptionNewParamsLanguageHe  AudioTranscriptionNewParamsLanguage = "he"
	AudioTranscriptionNewParamsLanguageUk  AudioTranscriptionNewParamsLanguage = "uk"
	AudioTranscriptionNewParamsLanguageEl  AudioTranscriptionNewParamsLanguage = "el"
	AudioTranscriptionNewParamsLanguageMs  AudioTranscriptionNewParamsLanguage = "ms"
	AudioTranscriptionNewParamsLanguageCs  AudioTranscriptionNewParamsLanguage = "cs"
	AudioTranscriptionNewParamsLanguageRo  AudioTranscriptionNewParamsLanguage = "ro"
	AudioTranscriptionNewParamsLanguageDa  AudioTranscriptionNewParamsLanguage = "da"
	AudioTranscriptionNewParamsLanguageHu  AudioTranscriptionNewParamsLanguage = "hu"
	AudioTranscriptionNewParamsLanguageTa  AudioTranscriptionNewParamsLanguage = "ta"
	AudioTranscriptionNewParamsLanguageTh  AudioTranscriptionNewParamsLanguage = "th"
	AudioTranscriptionNewParamsLanguageUr  AudioTranscriptionNewParamsLanguage = "ur"
	AudioTranscriptionNewParamsLanguageHr  AudioTranscriptionNewParamsLanguage = "hr"
	AudioTranscriptionNewParamsLanguageBg  AudioTranscriptionNewParamsLanguage = "bg"
	AudioTranscriptionNewParamsLanguageLt  AudioTranscriptionNewParamsLanguage = "lt"
	AudioTranscriptionNewParamsLanguageLa  AudioTranscriptionNewParamsLanguage = "la"
	AudioTranscriptionNewParamsLanguageMi  AudioTranscriptionNewParamsLanguage = "mi"
	AudioTranscriptionNewParamsLanguageMl  AudioTranscriptionNewParamsLanguage = "ml"
	AudioTranscriptionNewParamsLanguageCy  AudioTranscriptionNewParamsLanguage = "cy"
	AudioTranscriptionNewParamsLanguageSk  AudioTranscriptionNewParamsLanguage = "sk"
	AudioTranscriptionNewParamsLanguageTe  AudioTranscriptionNewParamsLanguage = "te"
	AudioTranscriptionNewParamsLanguageFa  AudioTranscriptionNewParamsLanguage = "fa"
	AudioTranscriptionNewParamsLanguageLv  AudioTranscriptionNewParamsLanguage = "lv"
	AudioTranscriptionNewParamsLanguageBn  AudioTranscriptionNewParamsLanguage = "bn"
	AudioTranscriptionNewParamsLanguageSr  AudioTranscriptionNewParamsLanguage = "sr"
	AudioTranscriptionNewParamsLanguageAz  AudioTranscriptionNewParamsLanguage = "az"
	AudioTranscriptionNewParamsLanguageSl  AudioTranscriptionNewParamsLanguage = "sl"
	AudioTranscriptionNewParamsLanguageKn  AudioTranscriptionNewParamsLanguage = "kn"
	AudioTranscriptionNewParamsLanguageEt  AudioTranscriptionNewParamsLanguage = "et"
	AudioTranscriptionNewParamsLanguageMk  AudioTranscriptionNewParamsLanguage = "mk"
	AudioTranscriptionNewParamsLanguageBr  AudioTranscriptionNewParamsLanguage = "br"
	AudioTranscriptionNewParamsLanguageEu  AudioTranscriptionNewParamsLanguage = "eu"
	AudioTranscriptionNewParamsLanguageIs  AudioTranscriptionNewParamsLanguage = "is"
	AudioTranscriptionNewParamsLanguageHy  AudioTranscriptionNewParamsLanguage = "hy"
	AudioTranscriptionNewParamsLanguageNe  AudioTranscriptionNewParamsLanguage = "ne"
	AudioTranscriptionNewParamsLanguageMn  AudioTranscriptionNewParamsLanguage = "mn"
	AudioTranscriptionNewParamsLanguageBs  AudioTranscriptionNewParamsLanguage = "bs"
	AudioTranscriptionNewParamsLanguageKk  AudioTranscriptionNewParamsLanguage = "kk"
	AudioTranscriptionNewParamsLanguageSq  AudioTranscriptionNewParamsLanguage = "sq"
	AudioTranscriptionNewParamsLanguageSw  AudioTranscriptionNewParamsLanguage = "sw"
	AudioTranscriptionNewParamsLanguageGl  AudioTranscriptionNewParamsLanguage = "gl"
	AudioTranscriptionNewParamsLanguageMr  AudioTranscriptionNewParamsLanguage = "mr"
	AudioTranscriptionNewParamsLanguagePa  AudioTranscriptionNewParamsLanguage = "pa"
	AudioTranscriptionNewParamsLanguageSi  AudioTranscriptionNewParamsLanguage = "si"
	AudioTranscriptionNewParamsLanguageKm  AudioTranscriptionNewParamsLanguage = "km"
	AudioTranscriptionNewParamsLanguageSn  AudioTranscriptionNewParamsLanguage = "sn"
	AudioTranscriptionNewParamsLanguageYo  AudioTranscriptionNewParamsLanguage = "yo"
	AudioTranscriptionNewParamsLanguageSo  AudioTranscriptionNewParamsLanguage = "so"
	AudioTranscriptionNewParamsLanguageAf  AudioTranscriptionNewParamsLanguage = "af"
	AudioTranscriptionNewParamsLanguageOc  AudioTranscriptionNewParamsLanguage = "oc"
	AudioTranscriptionNewParamsLanguageKa  AudioTranscriptionNewParamsLanguage = "ka"
	AudioTranscriptionNewParamsLanguageBe  AudioTranscriptionNewParamsLanguage = "be"
	AudioTranscriptionNewParamsLanguageTg  AudioTranscriptionNewParamsLanguage = "tg"
	AudioTranscriptionNewParamsLanguageSd  AudioTranscriptionNewParamsLanguage = "sd"
	AudioTranscriptionNewParamsLanguageGu  AudioTranscriptionNewParamsLanguage = "gu"
	AudioTranscriptionNewParamsLanguageAm  AudioTranscriptionNewParamsLanguage = "am"
	AudioTranscriptionNewParamsLanguageYi  AudioTranscriptionNewParamsLanguage = "yi"
	AudioTranscriptionNewParamsLanguageLo  AudioTranscriptionNewParamsLanguage = "lo"
	AudioTranscriptionNewParamsLanguageUz  AudioTranscriptionNewParamsLanguage = "uz"
	AudioTranscriptionNewParamsLanguageFo  AudioTranscriptionNewParamsLanguage = "fo"
	AudioTranscriptionNewParamsLanguageHt  AudioTranscriptionNewParamsLanguage = "ht"
	AudioTranscriptionNewParamsLanguagePs  AudioTranscriptionNewParamsLanguage = "ps"
	AudioTranscriptionNewParamsLanguageTk  AudioTranscriptionNewParamsLanguage = "tk"
	AudioTranscriptionNewParamsLanguageNn  AudioTranscriptionNewParamsLanguage = "nn"
	AudioTranscriptionNewParamsLanguageMt  AudioTranscriptionNewParamsLanguage = "mt"
	AudioTranscriptionNewParamsLanguageSa  AudioTranscriptionNewParamsLanguage = "sa"
	AudioTranscriptionNewParamsLanguageLb  AudioTranscriptionNewParamsLanguage = "lb"
	AudioTranscriptionNewParamsLanguageMy  AudioTranscriptionNewParamsLanguage = "my"
	AudioTranscriptionNewParamsLanguageBo  AudioTranscriptionNewParamsLanguage = "bo"
	AudioTranscriptionNewParamsLanguageTl  AudioTranscriptionNewParamsLanguage = "tl"
	AudioTranscriptionNewParamsLanguageMg  AudioTranscriptionNewParamsLanguage = "mg"
	AudioTranscriptionNewParamsLanguageAs  AudioTranscriptionNewParamsLanguage = "as"
	AudioTranscriptionNewParamsLanguageTt  AudioTranscriptionNewParamsLanguage = "tt"
	AudioTranscriptionNewParamsLanguageHaw AudioTranscriptionNewParamsLanguage = "haw"
	AudioTranscriptionNewParamsLanguageLn  AudioTranscriptionNewParamsLanguage = "ln"
	AudioTranscriptionNewParamsLanguageHa  AudioTranscriptionNewParamsLanguage = "ha"
	AudioTranscriptionNewParamsLanguageBa  AudioTranscriptionNewParamsLanguage = "ba"
	AudioTranscriptionNewParamsLanguageJv  AudioTranscriptionNewParamsLanguage = "jv"
	AudioTranscriptionNewParamsLanguageSu  AudioTranscriptionNewParamsLanguage = "su"
	AudioTranscriptionNewParamsLanguageYue AudioTranscriptionNewParamsLanguage = "yue"
)

func (AudioTranscriptionNewParamsLanguage) IsKnown

type AudioTranscriptionNewParamsModel

type AudioTranscriptionNewParamsModel string
const (
	AudioTranscriptionNewParamsModelWhisperLargeV3 AudioTranscriptionNewParamsModel = "whisper-large-v3"
)

func (AudioTranscriptionNewParamsModel) IsKnown

type AudioTranscriptionNewParamsResponseFormat

type AudioTranscriptionNewParamsResponseFormat string

The format of the transcript output, in one of these options: `json`, `text`, or `verbose_json`.

const (
	AudioTranscriptionNewParamsResponseFormatJson        AudioTranscriptionNewParamsResponseFormat = "json"
	AudioTranscriptionNewParamsResponseFormatText        AudioTranscriptionNewParamsResponseFormat = "text"
	AudioTranscriptionNewParamsResponseFormatVerboseJson AudioTranscriptionNewParamsResponseFormat = "verbose_json"
)

func (AudioTranscriptionNewParamsResponseFormat) IsKnown

type AudioTranscriptionNewParamsTimestampGranularity

type AudioTranscriptionNewParamsTimestampGranularity string
const (
	AudioTranscriptionNewParamsTimestampGranularityWord    AudioTranscriptionNewParamsTimestampGranularity = "word"
	AudioTranscriptionNewParamsTimestampGranularitySegment AudioTranscriptionNewParamsTimestampGranularity = "segment"
)

func (AudioTranscriptionNewParamsTimestampGranularity) IsKnown

type AudioTranscriptionNewResponse

type AudioTranscriptionNewResponse struct {
	// The transcribed text.
	Text string                            `json:"text,required"`
	JSON audioTranscriptionNewResponseJSON `json:"-"`
}

Represents a transcription response returned by model, based on the provided input.

func (*AudioTranscriptionNewResponse) UnmarshalJSON

func (r *AudioTranscriptionNewResponse) UnmarshalJSON(data []byte) (err error)

type AudioTranscriptionService

type AudioTranscriptionService struct {
	Options []option.RequestOption
}

AudioTranscriptionService contains methods and other services that help with interacting with the groq API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewAudioTranscriptionService method instead.

func NewAudioTranscriptionService

func NewAudioTranscriptionService(opts ...option.RequestOption) (r *AudioTranscriptionService)

NewAudioTranscriptionService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*AudioTranscriptionService) New

Transcribes audio into the input language.

type AudioTranslationNewParams

type AudioTranslationNewParams struct {
	// The audio file object (not file name) translate, in one of these formats: flac,
	// mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
	File param.Field[io.Reader] `json:"file,required" format:"binary"`
	// ID of the model to use. Only `whisper-large-v3` is currently available.
	Model param.Field[AudioTranslationNewParamsModel] `json:"model,required"`
	// An optional text to guide the model's style or continue a previous audio
	// segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in
	// English.
	Prompt param.Field[string] `json:"prompt"`
	// The format of the transcript output, in one of these options: `json`, `text`, or
	// `verbose_json`.
	ResponseFormat param.Field[AudioTranslationNewParamsResponseFormat] `json:"response_format"`
	// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the
	// output more random, while lower values like 0.2 will make it more focused and
	// deterministic. If set to 0, the model will use
	// [log probability](https://en.wikipedia.org/wiki/Log_probability) to
	// automatically increase the temperature until certain thresholds are hit.
	Temperature param.Field[float64] `json:"temperature"`
}

func (AudioTranslationNewParams) MarshalMultipart

func (r AudioTranslationNewParams) MarshalMultipart() (data []byte, contentType string, err error)

type AudioTranslationNewParamsModel

type AudioTranslationNewParamsModel string
const (
	AudioTranslationNewParamsModelWhisperLargeV3 AudioTranslationNewParamsModel = "whisper-large-v3"
)

func (AudioTranslationNewParamsModel) IsKnown

type AudioTranslationNewParamsResponseFormat

type AudioTranslationNewParamsResponseFormat string

The format of the transcript output, in one of these options: `json`, `text`, or `verbose_json`.

const (
	AudioTranslationNewParamsResponseFormatJson        AudioTranslationNewParamsResponseFormat = "json"
	AudioTranslationNewParamsResponseFormatText        AudioTranslationNewParamsResponseFormat = "text"
	AudioTranslationNewParamsResponseFormatVerboseJson AudioTranslationNewParamsResponseFormat = "verbose_json"
)

func (AudioTranslationNewParamsResponseFormat) IsKnown

type AudioTranslationNewResponse

type AudioTranslationNewResponse struct {
	Text string                          `json:"text,required"`
	JSON audioTranslationNewResponseJSON `json:"-"`
}

func (*AudioTranslationNewResponse) UnmarshalJSON

func (r *AudioTranslationNewResponse) UnmarshalJSON(data []byte) (err error)

type AudioTranslationService

type AudioTranslationService struct {
	Options []option.RequestOption
}

AudioTranslationService contains methods and other services that help with interacting with the groq API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewAudioTranslationService method instead.

func NewAudioTranslationService

func NewAudioTranslationService(opts ...option.RequestOption) (r *AudioTranslationService)

NewAudioTranslationService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*AudioTranslationService) New

Translates audio into English.

type ChatCompletionNewParams

type ChatCompletionNewParams struct {
	// A list of messages comprising the conversation so far.
	Messages param.Field[[]ChatCompletionNewParamsMessageUnion] `json:"messages,required"`
	// ID of the model to use. For details on which models are compatible with the Chat
	// API, see available [models](/docs/models)
	Model param.Field[ChatCompletionNewParamsModel] `json:"model,required"`
	// Number between -2.0 and 2.0. Positive values penalize new tokens based on their
	// existing frequency in the text so far, decreasing the model's likelihood to
	// repeat the same line verbatim.
	FrequencyPenalty param.Field[float64] `json:"frequency_penalty"`
	// Deprecated in favor of `tool_choice`.
	//
	// Controls which (if any) function is called by the model. `none` means the model
	// will not call a function and instead generates a message. `auto` means the model
	// can pick between generating a message or calling a function. Specifying a
	// particular function via `{"name": "my_function"}` forces the model to call that
	// function.
	//
	// `none` is the default when no functions are present. `auto` is the default if
	// functions are present.
	FunctionCall param.Field[ChatCompletionNewParamsFunctionCallUnion] `json:"function_call"`
	// Deprecated in favor of `tools`.
	//
	// A list of functions the model may generate JSON inputs for.
	Functions param.Field[[]ChatCompletionNewParamsFunction] `json:"functions"`
	// This is not yet supported by any of our models. Modify the likelihood of
	// specified tokens appearing in the completion.
	LogitBias param.Field[map[string]int64] `json:"logit_bias"`
	// This is not yet supported by any of our models. 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`.
	Logprobs param.Field[bool] `json:"logprobs"`
	// The maximum number of tokens that can be generated in the chat completion. The
	// total length of input tokens and generated tokens is limited by the model's
	// context length.
	MaxTokens param.Field[int64] `json:"max_tokens"`
	// How many chat completion choices to generate for each input message. Note that
	// the current moment, only n=1 is supported. Other values will result in a 400
	// response.
	N param.Field[int64] `json:"n"`
	// Whether to enable parallel function calling during tool use.
	ParallelToolCalls param.Field[bool] `json:"parallel_tool_calls"`
	// Number between -2.0 and 2.0. Positive values penalize new tokens based on
	// whether they appear in the text so far, increasing the model's likelihood to
	// talk about new topics.
	PresencePenalty param.Field[float64] `json:"presence_penalty"`
	// An object specifying the format that the model must output.
	//
	// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
	// message the model generates is valid JSON.
	//
	// **Important:** when using JSON mode, you **must** also instruct the model to
	// produce JSON yourself via a system or user message.
	ResponseFormat param.Field[ChatCompletionNewParamsResponseFormat] `json:"response_format"`
	// If specified, our system will make a best effort to sample deterministically,
	// such that repeated requests with the same `seed` and parameters should return
	// the same result. Determinism is not guaranteed, and you should refer to the
	// `system_fingerprint` response parameter to monitor changes in the backend.
	Seed param.Field[int64] `json:"seed"`
	// Up to 4 sequences where the API will stop generating further tokens. The
	// returned text will not contain the stop sequence.
	Stop param.Field[ChatCompletionNewParamsStopUnion] `json:"stop"`
	// If set, partial message deltas will be sent. Tokens will be sent as data-only
	// [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
	// as they become available, with the stream terminated by a `data: [DONE]`
	// message. [Example code](/docs/text-chat#streaming-a-chat-completion).
	Stream param.Field[bool] `json:"stream"`
	// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
	// make the output more random, while lower values like 0.2 will make it more
	// focused and deterministic. We generally recommend altering this or top_p but not
	// both
	Temperature param.Field[float64] `json:"temperature"`
	// Controls which (if any) tool is called by the model. `none` means the model will
	// not call any tool and instead generates a message. `auto` means the model can
	// pick between generating a message or calling one or more tools. `required` means
	// the model must call one or more tools. Specifying a particular tool via
	// `{"type": "function", "function": {"name": "my_function"}}` forces the model to
	// call that tool.
	//
	// `none` is the default when no tools are present. `auto` is the default if tools
	// are present.
	ToolChoice param.Field[ChatCompletionNewParamsToolChoiceUnion] `json:"tool_choice"`
	// A list of tools the model may call. Currently, only functions are supported as a
	// tool. Use this to provide a list of functions the model may generate JSON inputs
	// for. A max of 128 functions are supported.
	Tools param.Field[[]ChatCompletionNewParamsTool] `json:"tools"`
	// This is not yet supported by any of our models. An integer between 0 and 20
	// 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 param.Field[int64] `json:"top_logprobs"`
	// An alternative to sampling with temperature, called nucleus sampling, where the
	// model considers the results of the tokens with top_p probability mass. So 0.1
	// means only the tokens comprising the top 10% probability mass are considered. We
	// generally recommend altering this or temperature but not both.
	TopP param.Field[float64] `json:"top_p"`
	// A unique identifier representing your end-user, which can help us monitor and
	// detect abuse.
	User param.Field[string] `json:"user"`
}

func (ChatCompletionNewParams) MarshalJSON

func (r ChatCompletionNewParams) MarshalJSON() (data []byte, err error)

type ChatCompletionNewParamsFunction

type ChatCompletionNewParamsFunction struct {
	// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
	// underscores and dashes, with a maximum length of 64.
	Name param.Field[string] `json:"name,required"`
	// A description of what the function does, used by the model to choose when and
	// how to call the function.
	Description param.Field[string] `json:"description"`
	// The parameters the functions accepts, described as a JSON Schema object. See the
	// docs on [tool use](/docs/tool-use) for examples, and the
	// [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
	// documentation about the format.
	//
	// Omitting `parameters` defines a function with an empty parameter list.
	Parameters param.Field[map[string]interface{}] `json:"parameters"`
}

func (ChatCompletionNewParamsFunction) MarshalJSON

func (r ChatCompletionNewParamsFunction) MarshalJSON() (data []byte, err error)

type ChatCompletionNewParamsFunctionCallChatCompletionFunctionCallOption

type ChatCompletionNewParamsFunctionCallChatCompletionFunctionCallOption struct {
	// The name of the function to call.
	Name param.Field[string] `json:"name,required"`
}

Specifying a particular function via `{"name": "my_function"}` forces the model to call that function.

func (ChatCompletionNewParamsFunctionCallChatCompletionFunctionCallOption) MarshalJSON

type ChatCompletionNewParamsFunctionCallString

type ChatCompletionNewParamsFunctionCallString string

`none` means the model will not call a function and instead generates a message. `auto` means the model can pick between generating a message or calling a function.

const (
	ChatCompletionNewParamsFunctionCallStringNone     ChatCompletionNewParamsFunctionCallString = "none"
	ChatCompletionNewParamsFunctionCallStringAuto     ChatCompletionNewParamsFunctionCallString = "auto"
	ChatCompletionNewParamsFunctionCallStringRequired ChatCompletionNewParamsFunctionCallString = "required"
)

func (ChatCompletionNewParamsFunctionCallString) IsKnown

type ChatCompletionNewParamsFunctionCallUnion

type ChatCompletionNewParamsFunctionCallUnion interface {
	// contains filtered or unexported methods
}

Deprecated in favor of `tool_choice`.

Controls which (if any) function is called by the model. `none` means the model will not call a function and instead generates a message. `auto` means the model can pick between generating a message or calling a function. Specifying a particular function via `{"name": "my_function"}` forces the model to call that function.

`none` is the default when no functions are present. `auto` is the default if functions are present.

Satisfied by ChatCompletionNewParamsFunctionCallString, ChatCompletionNewParamsFunctionCallChatCompletionFunctionCallOption.

type ChatCompletionNewParamsMessage

type ChatCompletionNewParamsMessage struct {
	Content param.Field[interface{}] `json:"content,required"`
	// An optional name for the participant. Provides the model information to
	// differentiate between participants of the same role.
	Name param.Field[string] `json:"name"`
	// The role of the messages author, in this case `system`.
	Role         param.Field[ChatCompletionNewParamsMessagesRole] `json:"role,required"`
	FunctionCall param.Field[interface{}]                         `json:"function_call,required"`
	ToolCalls    param.Field[interface{}]                         `json:"tool_calls,required"`
	// Tool call that this message is responding to.
	ToolCallID param.Field[string] `json:"tool_call_id"`
}

func (ChatCompletionNewParamsMessage) MarshalJSON

func (r ChatCompletionNewParamsMessage) MarshalJSON() (data []byte, err error)

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessage

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessage struct {
	// The role of the messages author, in this case `assistant`.
	Role param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageRole] `json:"role,required"`
	// The contents of the assistant message. Required unless `tool_calls` or
	// `function_call` is specified.
	Content param.Field[string] `json:"content"`
	// Deprecated and replaced by `tool_calls`. The name and arguments of a function
	// that should be called, as generated by the model.
	FunctionCall param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageFunctionCall] `json:"function_call"`
	// An optional name for the participant. Provides the model information to
	// differentiate between participants of the same role.
	Name param.Field[string] `json:"name"`
	// The tool calls generated by the model, such as function calls.
	ToolCalls param.Field[[]ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCall] `json:"tool_calls"`
}

func (ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessage) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageFunctionCall

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageFunctionCall struct {
	// The arguments to call the function with, as generated by the model in JSON
	// format. Note that the model does not always generate valid JSON, and may
	// hallucinate parameters not defined by your function schema. Validate the
	// arguments in your code before calling your function.
	Arguments param.Field[string] `json:"arguments"`
	// The name of the function to call.
	Name param.Field[string] `json:"name"`
}

Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.

func (ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageFunctionCall) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageRole

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageRole string

The role of the messages author, in this case `assistant`.

const (
	ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageRoleAssistant ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageRole = "assistant"
)

func (ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageRole) IsKnown

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCall

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCall struct {
	// The ID of the tool call.
	ID param.Field[string] `json:"id,required"`
	// The function that the model called.
	Function param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsFunction] `json:"function,required"`
	// The type of the tool. Currently, only `function` is supported.
	Type param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsType] `json:"type,required"`
}

func (ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCall) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsFunction

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsFunction struct {
	// The arguments to call the function with, as generated by the model in JSON
	// format. Note that the model does not always generate valid JSON, and may
	// hallucinate parameters not defined by your function schema. Validate the
	// arguments in your code before calling your function.
	Arguments param.Field[string] `json:"arguments,required"`
	// The name of the function to call.
	Name param.Field[string] `json:"name,required"`
}

The function that the model called.

func (ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsFunction) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsType

type ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsType string

The type of the tool. Currently, only `function` is supported.

const (
	ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsTypeFunction ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsType = "function"
)

func (ChatCompletionNewParamsMessagesChatCompletionRequestAssistantMessageToolCallsType) IsKnown

type ChatCompletionNewParamsMessagesChatCompletionRequestFunctionMessage

type ChatCompletionNewParamsMessagesChatCompletionRequestFunctionMessage struct {
	// The contents of the function message.
	Content param.Field[string] `json:"content,required"`
	// The name of the function to call.
	Name param.Field[string] `json:"name,required"`
	// The role of the messages author, in this case `function`.
	Role param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestFunctionMessageRole] `json:"role,required"`
}

func (ChatCompletionNewParamsMessagesChatCompletionRequestFunctionMessage) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestFunctionMessageRole

type ChatCompletionNewParamsMessagesChatCompletionRequestFunctionMessageRole string

The role of the messages author, in this case `function`.

const (
	ChatCompletionNewParamsMessagesChatCompletionRequestFunctionMessageRoleFunction ChatCompletionNewParamsMessagesChatCompletionRequestFunctionMessageRole = "function"
)

func (ChatCompletionNewParamsMessagesChatCompletionRequestFunctionMessageRole) IsKnown

type ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessage

type ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessage struct {
	// The contents of the system message.
	Content param.Field[string] `json:"content,required"`
	// The role of the messages author, in this case `system`.
	Role param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRole] `json:"role,required"`
	// An optional name for the participant. Provides the model information to
	// differentiate between participants of the same role.
	Name param.Field[string] `json:"name"`
}

func (ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessage) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRole

type ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRole string

The role of the messages author, in this case `system`.

const (
	ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRoleSystem ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRole = "system"
)

func (ChatCompletionNewParamsMessagesChatCompletionRequestSystemMessageRole) IsKnown

type ChatCompletionNewParamsMessagesChatCompletionRequestToolMessage

type ChatCompletionNewParamsMessagesChatCompletionRequestToolMessage struct {
	// The contents of the tool message.
	Content param.Field[string] `json:"content,required"`
	// The role of the messages author, in this case `tool`.
	Role param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageRole] `json:"role,required"`
	// Tool call that this message is responding to.
	ToolCallID param.Field[string] `json:"tool_call_id,required"`
}

func (ChatCompletionNewParamsMessagesChatCompletionRequestToolMessage) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageRole

type ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageRole string

The role of the messages author, in this case `tool`.

const (
	ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageRoleTool ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageRole = "tool"
)

func (ChatCompletionNewParamsMessagesChatCompletionRequestToolMessageRole) IsKnown

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessage

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessage struct {
	// The contents of the user message.
	Content param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentUnion] `json:"content,required"`
	// The role of the messages author, in this case `user`.
	Role param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageRole] `json:"role,required"`
	// An optional name for the participant. Provides the model information to
	// differentiate between participants of the same role.
	Name param.Field[string] `json:"name"`
}

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessage) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPart

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPart struct {
	// The text content.
	Text param.Field[string] `json:"text"`
	// The type of the content part.
	Type     param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsType] `json:"type,required"`
	ImageURL param.Field[interface{}]                                                                                   `json:"image_url,required"`
}

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPart) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentParts

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentParts []ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartUnion

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentParts) ImplementsChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentUnion

func (r ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentParts) ImplementsChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentUnion()

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImage

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImage struct {
	ImageURL param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURL] `json:"image_url,required"`
	// The type of the content part.
	Type param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageType] `json:"type,required"`
}

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImage) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURL

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURL struct {
	// Either a URL of the image or the base64 encoded image data.
	URL param.Field[string] `json:"url,required" format:"uri"`
	// Specifies the detail level of the image.
	Detail param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURLDetail] `json:"detail"`
}

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURL) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURLDetail

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURLDetail string

Specifies the detail level of the image.

const (
	ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURLDetailAuto ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURLDetail = "auto"
	ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURLDetailLow  ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURLDetail = "low"
	ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURLDetailHigh ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURLDetail = "high"
)

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageImageURLDetail) IsKnown

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageType

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageType string

The type of the content part.

const (
	ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageTypeImageURL ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageType = "image_url"
)

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartImageType) IsKnown

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartText

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartText struct {
	// The text content.
	Text param.Field[string] `json:"text,required"`
	// The type of the content part.
	Type param.Field[ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartTextType] `json:"type,required"`
}

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartText) MarshalJSON

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartTextType

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartTextType string

The type of the content part.

const (
	ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartTextTypeText ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartTextType = "text"
)

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsChatCompletionRequestMessageContentPartTextType) IsKnown

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsType

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsType string

The type of the content part.

const (
	ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsTypeText     ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsType = "text"
	ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsTypeImageURL ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsType = "image_url"
)

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentPartsType) IsKnown

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentUnion

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentUnion interface {
	ImplementsChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentUnion()
}

The contents of the user message.

Satisfied by shared.UnionString, ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageContentArrayOfContentParts.

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageRole

type ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageRole string

The role of the messages author, in this case `user`.

const (
	ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageRoleUser ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageRole = "user"
)

func (ChatCompletionNewParamsMessagesChatCompletionRequestUserMessageRole) IsKnown

type ChatCompletionNewParamsMessagesRole

type ChatCompletionNewParamsMessagesRole string

The role of the messages author, in this case `system`.

const (
	ChatCompletionNewParamsMessagesRoleSystem    ChatCompletionNewParamsMessagesRole = "system"
	ChatCompletionNewParamsMessagesRoleUser      ChatCompletionNewParamsMessagesRole = "user"
	ChatCompletionNewParamsMessagesRoleAssistant ChatCompletionNewParamsMessagesRole = "assistant"
	ChatCompletionNewParamsMessagesRoleTool      ChatCompletionNewParamsMessagesRole = "tool"
	ChatCompletionNewParamsMessagesRoleFunction  ChatCompletionNewParamsMessagesRole = "function"
)

func (ChatCompletionNewParamsMessagesRole) IsKnown

type ChatCompletionNewParamsModel

type ChatCompletionNewParamsModel string
const (
	ChatCompletionNewParamsModelGemma7bIt        ChatCompletionNewParamsModel = "gemma-7b-it"
	ChatCompletionNewParamsModelLlama3_70b8192   ChatCompletionNewParamsModel = "llama3-70b-8192"
	ChatCompletionNewParamsModelLlama3_8b8192    ChatCompletionNewParamsModel = "llama3-8b-8192"
	ChatCompletionNewParamsModelMixtral8x7b32768 ChatCompletionNewParamsModel = "mixtral-8x7b-32768"
)

func (ChatCompletionNewParamsModel) IsKnown

func (r ChatCompletionNewParamsModel) IsKnown() bool

type ChatCompletionNewParamsResponseFormat

type ChatCompletionNewParamsResponseFormat struct {
	// Must be one of `text` or `json_object`.
	Type param.Field[ChatCompletionNewParamsResponseFormatType] `json:"type"`
}

An object specifying the format that the model must output.

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message.

func (ChatCompletionNewParamsResponseFormat) MarshalJSON

func (r ChatCompletionNewParamsResponseFormat) MarshalJSON() (data []byte, err error)

type ChatCompletionNewParamsResponseFormatType

type ChatCompletionNewParamsResponseFormatType string

Must be one of `text` or `json_object`.

const (
	ChatCompletionNewParamsResponseFormatTypeText       ChatCompletionNewParamsResponseFormatType = "text"
	ChatCompletionNewParamsResponseFormatTypeJsonObject ChatCompletionNewParamsResponseFormatType = "json_object"
)

func (ChatCompletionNewParamsResponseFormatType) IsKnown

type ChatCompletionNewParamsStopArray

type ChatCompletionNewParamsStopArray []string

func (ChatCompletionNewParamsStopArray) ImplementsChatCompletionNewParamsStopUnion

func (r ChatCompletionNewParamsStopArray) ImplementsChatCompletionNewParamsStopUnion()

type ChatCompletionNewParamsStopUnion

type ChatCompletionNewParamsStopUnion interface {
	ImplementsChatCompletionNewParamsStopUnion()
}

Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.

Satisfied by shared.UnionString, ChatCompletionNewParamsStopArray.

type ChatCompletionNewParamsTool

type ChatCompletionNewParamsTool struct {
	Function param.Field[ChatCompletionNewParamsToolsFunction] `json:"function,required"`
	// The type of the tool. Currently, only `function` is supported.
	Type param.Field[ChatCompletionNewParamsToolsType] `json:"type,required"`
}

func (ChatCompletionNewParamsTool) MarshalJSON

func (r ChatCompletionNewParamsTool) MarshalJSON() (data []byte, err error)

type ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoice

type ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoice struct {
	Function param.Field[ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceFunction] `json:"function,required"`
	// The type of the tool. Currently, only `function` is supported.
	Type param.Field[ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceType] `json:"type,required"`
}

Specifies a tool the model should use. Use to force the model to call a specific function.

func (ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoice) MarshalJSON

type ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceFunction

type ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceFunction struct {
	// The name of the function to call.
	Name param.Field[string] `json:"name,required"`
}

func (ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceFunction) MarshalJSON

type ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceType

type ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceType string

The type of the tool. Currently, only `function` is supported.

const (
	ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceTypeFunction ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceType = "function"
)

func (ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoiceType) IsKnown

type ChatCompletionNewParamsToolChoiceString

type ChatCompletionNewParamsToolChoiceString string

`none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools.

const (
	ChatCompletionNewParamsToolChoiceStringNone     ChatCompletionNewParamsToolChoiceString = "none"
	ChatCompletionNewParamsToolChoiceStringAuto     ChatCompletionNewParamsToolChoiceString = "auto"
	ChatCompletionNewParamsToolChoiceStringRequired ChatCompletionNewParamsToolChoiceString = "required"
)

func (ChatCompletionNewParamsToolChoiceString) IsKnown

type ChatCompletionNewParamsToolChoiceUnion

type ChatCompletionNewParamsToolChoiceUnion interface {
	// contains filtered or unexported methods
}

Controls which (if any) tool is called by the model. `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `required` means the model must call one or more tools. Specifying a particular tool via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool.

`none` is the default when no tools are present. `auto` is the default if tools are present.

Satisfied by ChatCompletionNewParamsToolChoiceString, ChatCompletionNewParamsToolChoiceChatCompletionNamedToolChoice.

type ChatCompletionNewParamsToolsFunction

type ChatCompletionNewParamsToolsFunction struct {
	// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
	// underscores and dashes, with a maximum length of 64.
	Name param.Field[string] `json:"name,required"`
	// A description of what the function does, used by the model to choose when and
	// how to call the function.
	Description param.Field[string] `json:"description"`
	// The parameters the functions accepts, described as a JSON Schema object. See the
	// docs on [tool use](/docs/tool-use) for examples, and the
	// [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
	// documentation about the format.
	//
	// Omitting `parameters` defines a function with an empty parameter list.
	Parameters param.Field[map[string]interface{}] `json:"parameters"`
}

func (ChatCompletionNewParamsToolsFunction) MarshalJSON

func (r ChatCompletionNewParamsToolsFunction) MarshalJSON() (data []byte, err error)

type ChatCompletionNewParamsToolsType

type ChatCompletionNewParamsToolsType string

The type of the tool. Currently, only `function` is supported.

const (
	ChatCompletionNewParamsToolsTypeFunction ChatCompletionNewParamsToolsType = "function"
)

func (ChatCompletionNewParamsToolsType) IsKnown

type ChatCompletionNewResponse

type ChatCompletionNewResponse struct {
	// A unique identifier for the chat completion.
	ID string `json:"id,required"`
	// A list of chat completion choices. Can be more than one if `n` is greater
	// than 1.
	Choices []ChatCompletionNewResponseChoice `json:"choices,required"`
	// The Unix timestamp (in seconds) of when the chat completion was created.
	Created int64 `json:"created,required"`
	// The model used for the chat completion.
	Model string `json:"model,required"`
	// The object type, which is always `chat.completion`.
	Object ChatCompletionNewResponseObject `json:"object,required"`
	// This fingerprint represents the backend configuration that the model runs with.
	//
	// Can be used in conjunction with the `seed` request parameter to understand when
	// backend changes have been made that might impact determinism.
	SystemFingerprint string `json:"system_fingerprint"`
	// Usage statistics for the completion request.
	Usage ChatCompletionNewResponseUsage `json:"usage"`
	JSON  chatCompletionNewResponseJSON  `json:"-"`
}

Represents a chat completion response returned by model, based on the provided input.

func (*ChatCompletionNewResponse) UnmarshalJSON

func (r *ChatCompletionNewResponse) UnmarshalJSON(data []byte) (err error)

type ChatCompletionNewResponseChoice

type ChatCompletionNewResponseChoice struct {
	// The reason the model stopped generating tokens. This will be `stop` if the model
	// hit a natural stop point or a provided stop sequence, `length` if the maximum
	// number of tokens specified in the request was reached, `tool_calls` if the model
	// called a tool, or `function_call` (deprecated) if the model called a function.
	FinishReason ChatCompletionNewResponseChoicesFinishReason `json:"finish_reason,required"`
	// The index of the choice in the list of choices.
	Index int64 `json:"index,required"`
	// Log probability information for the choice.
	Logprobs ChatCompletionNewResponseChoicesLogprobs `json:"logprobs,required,nullable"`
	// A chat completion message generated by the model.
	Message ChatCompletionNewResponseChoicesMessage `json:"message,required"`
	JSON    chatCompletionNewResponseChoiceJSON     `json:"-"`
}

func (*ChatCompletionNewResponseChoice) UnmarshalJSON

func (r *ChatCompletionNewResponseChoice) UnmarshalJSON(data []byte) (err error)

type ChatCompletionNewResponseChoicesFinishReason

type ChatCompletionNewResponseChoicesFinishReason string

The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, `length` if the maximum number of tokens specified in the request was reached, `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.

const (
	ChatCompletionNewResponseChoicesFinishReasonStop         ChatCompletionNewResponseChoicesFinishReason = "stop"
	ChatCompletionNewResponseChoicesFinishReasonLength       ChatCompletionNewResponseChoicesFinishReason = "length"
	ChatCompletionNewResponseChoicesFinishReasonToolCalls    ChatCompletionNewResponseChoicesFinishReason = "tool_calls"
	ChatCompletionNewResponseChoicesFinishReasonFunctionCall ChatCompletionNewResponseChoicesFinishReason = "function_call"
)

func (ChatCompletionNewResponseChoicesFinishReason) IsKnown

type ChatCompletionNewResponseChoicesLogprobs

type ChatCompletionNewResponseChoicesLogprobs struct {
	// A list of message content tokens with log probability information.
	Content []ChatCompletionNewResponseChoicesLogprobsContent `json:"content,required,nullable"`
	JSON    chatCompletionNewResponseChoicesLogprobsJSON      `json:"-"`
}

Log probability information for the choice.

func (*ChatCompletionNewResponseChoicesLogprobs) UnmarshalJSON

func (r *ChatCompletionNewResponseChoicesLogprobs) UnmarshalJSON(data []byte) (err error)

type ChatCompletionNewResponseChoicesLogprobsContent

type ChatCompletionNewResponseChoicesLogprobsContent struct {
	// The token.
	Token string `json:"token,required"`
	// A list of integers representing the UTF-8 bytes representation of the token.
	// Useful in instances where characters are represented by multiple tokens and
	// their byte representations must be combined to generate the correct text
	// representation. Can be `null` if there is no bytes representation for the token.
	Bytes []int64 `json:"bytes,required,nullable"`
	// The log probability of this token, if it is within the top 20 most likely
	// tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
	// unlikely.
	Logprob float64 `json:"logprob,required"`
	// List of the most likely tokens and their log probability, at this token
	// position. In rare cases, there may be fewer than the number of requested
	// `top_logprobs` returned.
	TopLogprobs []ChatCompletionNewResponseChoicesLogprobsContentTopLogprob `json:"top_logprobs,required"`
	JSON        chatCompletionNewResponseChoicesLogprobsContentJSON         `json:"-"`
}

func (*ChatCompletionNewResponseChoicesLogprobsContent) UnmarshalJSON

func (r *ChatCompletionNewResponseChoicesLogprobsContent) UnmarshalJSON(data []byte) (err error)

type ChatCompletionNewResponseChoicesLogprobsContentTopLogprob

type ChatCompletionNewResponseChoicesLogprobsContentTopLogprob struct {
	// The token.
	Token string `json:"token,required"`
	// A list of integers representing the UTF-8 bytes representation of the token.
	// Useful in instances where characters are represented by multiple tokens and
	// their byte representations must be combined to generate the correct text
	// representation. Can be `null` if there is no bytes representation for the token.
	Bytes []int64 `json:"bytes,required,nullable"`
	// The log probability of this token, if it is within the top 20 most likely
	// tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
	// unlikely.
	Logprob float64                                                       `json:"logprob,required"`
	JSON    chatCompletionNewResponseChoicesLogprobsContentTopLogprobJSON `json:"-"`
}

func (*ChatCompletionNewResponseChoicesLogprobsContentTopLogprob) UnmarshalJSON

type ChatCompletionNewResponseChoicesMessage

type ChatCompletionNewResponseChoicesMessage struct {
	// The contents of the message.
	Content string `json:"content,required,nullable"`
	// The role of the author of this message.
	Role ChatCompletionNewResponseChoicesMessageRole `json:"role,required"`
	// Deprecated and replaced by `tool_calls`. The name and arguments of a function
	// that should be called, as generated by the model.
	FunctionCall ChatCompletionNewResponseChoicesMessageFunctionCall `json:"function_call"`
	// The tool calls generated by the model, such as function calls.
	ToolCalls []ChatCompletionNewResponseChoicesMessageToolCall `json:"tool_calls"`
	JSON      chatCompletionNewResponseChoicesMessageJSON       `json:"-"`
}

A chat completion message generated by the model.

func (*ChatCompletionNewResponseChoicesMessage) UnmarshalJSON

func (r *ChatCompletionNewResponseChoicesMessage) UnmarshalJSON(data []byte) (err error)

type ChatCompletionNewResponseChoicesMessageFunctionCall

type ChatCompletionNewResponseChoicesMessageFunctionCall struct {
	// The arguments to call the function with, as generated by the model in JSON
	// format. Note that the model does not always generate valid JSON, and may
	// hallucinate parameters not defined by your function schema. Validate the
	// arguments in your code before calling your function.
	Arguments string `json:"arguments,required"`
	// The name of the function to call.
	Name string                                                  `json:"name,required"`
	JSON chatCompletionNewResponseChoicesMessageFunctionCallJSON `json:"-"`
}

Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.

func (*ChatCompletionNewResponseChoicesMessageFunctionCall) UnmarshalJSON

func (r *ChatCompletionNewResponseChoicesMessageFunctionCall) UnmarshalJSON(data []byte) (err error)

type ChatCompletionNewResponseChoicesMessageRole

type ChatCompletionNewResponseChoicesMessageRole string

The role of the author of this message.

const (
	ChatCompletionNewResponseChoicesMessageRoleAssistant ChatCompletionNewResponseChoicesMessageRole = "assistant"
)

func (ChatCompletionNewResponseChoicesMessageRole) IsKnown

type ChatCompletionNewResponseChoicesMessageToolCall

type ChatCompletionNewResponseChoicesMessageToolCall struct {
	// The ID of the tool call.
	ID string `json:"id,required"`
	// The function that the model called.
	Function ChatCompletionNewResponseChoicesMessageToolCallsFunction `json:"function,required"`
	// The type of the tool. Currently, only `function` is supported.
	Type ChatCompletionNewResponseChoicesMessageToolCallsType `json:"type,required"`
	JSON chatCompletionNewResponseChoicesMessageToolCallJSON  `json:"-"`
}

func (*ChatCompletionNewResponseChoicesMessageToolCall) UnmarshalJSON

func (r *ChatCompletionNewResponseChoicesMessageToolCall) UnmarshalJSON(data []byte) (err error)

type ChatCompletionNewResponseChoicesMessageToolCallsFunction

type ChatCompletionNewResponseChoicesMessageToolCallsFunction struct {
	// The arguments to call the function with, as generated by the model in JSON
	// format. Note that the model does not always generate valid JSON, and may
	// hallucinate parameters not defined by your function schema. Validate the
	// arguments in your code before calling your function.
	Arguments string `json:"arguments,required"`
	// The name of the function to call.
	Name string                                                       `json:"name,required"`
	JSON chatCompletionNewResponseChoicesMessageToolCallsFunctionJSON `json:"-"`
}

The function that the model called.

func (*ChatCompletionNewResponseChoicesMessageToolCallsFunction) UnmarshalJSON

type ChatCompletionNewResponseChoicesMessageToolCallsType

type ChatCompletionNewResponseChoicesMessageToolCallsType string

The type of the tool. Currently, only `function` is supported.

const (
	ChatCompletionNewResponseChoicesMessageToolCallsTypeFunction ChatCompletionNewResponseChoicesMessageToolCallsType = "function"
)

func (ChatCompletionNewResponseChoicesMessageToolCallsType) IsKnown

type ChatCompletionNewResponseObject

type ChatCompletionNewResponseObject string

The object type, which is always `chat.completion`.

const (
	ChatCompletionNewResponseObjectChatCompletion ChatCompletionNewResponseObject = "chat.completion"
)

func (ChatCompletionNewResponseObject) IsKnown

type ChatCompletionNewResponseUsage

type ChatCompletionNewResponseUsage struct {
	// Number of tokens in the generated completion.
	CompletionTokens int64 `json:"completion_tokens,required"`
	// Number of tokens in the prompt.
	PromptTokens int64 `json:"prompt_tokens,required"`
	// Total number of tokens used in the request (prompt + completion).
	TotalTokens int64 `json:"total_tokens,required"`
	// Time spent generating tokens
	CompletionTime float64 `json:"completion_time"`
	// Time spent processing input tokens
	PromptTime float64 `json:"prompt_time"`
	// Time the requests was spent queued
	QueueTime float64 `json:"queue_time"`
	// completion time and prompt time combined
	TotalTime float64                            `json:"total_time"`
	JSON      chatCompletionNewResponseUsageJSON `json:"-"`
}

Usage statistics for the completion request.

func (*ChatCompletionNewResponseUsage) UnmarshalJSON

func (r *ChatCompletionNewResponseUsage) UnmarshalJSON(data []byte) (err error)

type ChatCompletionService

type ChatCompletionService struct {
	Options []option.RequestOption
}

ChatCompletionService contains methods and other services that help with interacting with the groq API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewChatCompletionService method instead.

func NewChatCompletionService

func NewChatCompletionService(opts ...option.RequestOption) (r *ChatCompletionService)

NewChatCompletionService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*ChatCompletionService) New

Creates a model response for the given chat conversation.

type ChatService

type ChatService struct {
	Options     []option.RequestOption
	Completions *ChatCompletionService
}

ChatService contains methods and other services that help with interacting with the groq API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewChatService method instead.

func NewChatService

func NewChatService(opts ...option.RequestOption) (r *ChatService)

NewChatService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

type Client

type Client struct {
	Options    []option.RequestOption
	Audio      *AudioService
	Chat       *ChatService
	Embeddings *EmbeddingService
	Models     *ModelService
}

Client creates a struct with services and top level methods that help with interacting with the groq API. You should not instantiate this client directly, and instead use the NewClient method instead.

func NewClient

func NewClient(opts ...option.RequestOption) (r *Client)

NewClient generates a new client with the default option read from the environment (GROQ_BEARER_TOKEN). The option passed in as arguments are applied after these default arguments, and all option will be passed down to the services and requests that this client makes.

func (*Client) Delete

func (r *Client) Delete(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Delete makes a DELETE request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Execute

func (r *Client) Execute(ctx context.Context, method string, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Execute makes a request with the given context, method, URL, request params, response, and request options. This is useful for hitting undocumented endpoints while retaining the base URL, auth, retries, and other options from the client.

If a byte slice or an io.Reader is supplied to params, it will be used as-is for the request body.

The params is by default serialized into the body using encoding/json. If your type implements a MarshalJSON function, it will be used instead to serialize the request. If a URLQuery method is implemented, the returned [url.Values] will be used as query strings to the url.

If your params struct uses param.Field, you must provide either [MarshalJSON], [URLQuery], and/or [MarshalForm] functions. It is undefined behavior to use a struct uses param.Field without specifying how it is serialized.

Any "…Params" object defined in this library can be used as the request argument. Note that 'path' arguments will not be forwarded into the url.

The response body will be deserialized into the res variable, depending on its type:

  • A pointer to a *http.Response is populated by the raw response.
  • A pointer to a byte array will be populated with the contents of the request body.
  • A pointer to any other type uses this library's default JSON decoding, which respects UnmarshalJSON if it is defined on the type.
  • A nil value will not read the response body.

For even greater flexibility, see option.WithResponseInto and option.WithResponseBodyInto.

func (*Client) Get

func (r *Client) Get(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Get makes a GET request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Patch

func (r *Client) Patch(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Patch makes a PATCH request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Post

func (r *Client) Post(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Post makes a POST request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Put

func (r *Client) Put(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Put makes a PUT request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

type EmbeddingNewParams

type EmbeddingNewParams struct {
	// Input text to embed, encoded as a string or array of tokens. To embed multiple
	// inputs in a single request, pass an array of strings or array of token arrays.
	// The input must not exceed the max input tokens for the model, cannot be an empty
	// string, and any array must be 2048 dimensions or less.
	Input param.Field[EmbeddingNewParamsInputUnion] `json:"input,required"`
	// ID of the model to use.
	Model param.Field[EmbeddingNewParamsModel] `json:"model,required"`
	// The format to return the embeddings in. Can only be `float` or `base64`.
	EncodingFormat param.Field[EmbeddingNewParamsEncodingFormat] `json:"encoding_format"`
	// A unique identifier representing your end-user, which can help us monitor and
	// detect abuse.
	User param.Field[string] `json:"user"`
}

func (EmbeddingNewParams) MarshalJSON

func (r EmbeddingNewParams) MarshalJSON() (data []byte, err error)

type EmbeddingNewParamsEncodingFormat

type EmbeddingNewParamsEncodingFormat string

The format to return the embeddings in. Can only be `float` or `base64`.

const (
	EmbeddingNewParamsEncodingFormatFloat  EmbeddingNewParamsEncodingFormat = "float"
	EmbeddingNewParamsEncodingFormatBase64 EmbeddingNewParamsEncodingFormat = "base64"
)

func (EmbeddingNewParamsEncodingFormat) IsKnown

type EmbeddingNewParamsInputArray

type EmbeddingNewParamsInputArray []string

func (EmbeddingNewParamsInputArray) ImplementsEmbeddingNewParamsInputUnion

func (r EmbeddingNewParamsInputArray) ImplementsEmbeddingNewParamsInputUnion()

type EmbeddingNewParamsInputUnion

type EmbeddingNewParamsInputUnion interface {
	ImplementsEmbeddingNewParamsInputUnion()
}

Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model, cannot be an empty string, and any array must be 2048 dimensions or less.

Satisfied by shared.UnionString, EmbeddingNewParamsInputArray.

type EmbeddingNewParamsModel

type EmbeddingNewParamsModel string
const (
	EmbeddingNewParamsModelNomicEmbedTextV1_5 EmbeddingNewParamsModel = "nomic-embed-text-v1_5"
)

func (EmbeddingNewParamsModel) IsKnown

func (r EmbeddingNewParamsModel) IsKnown() bool

type EmbeddingNewResponse

type EmbeddingNewResponse struct {
	// The list of embeddings generated by the model.
	Data []EmbeddingNewResponseData `json:"data,required"`
	// The name of the model used to generate the embedding.
	Model string `json:"model,required"`
	// The object type, which is always "list".
	Object EmbeddingNewResponseObject `json:"object,required"`
	// The usage information for the request.
	Usage EmbeddingNewResponseUsage `json:"usage,required"`
	JSON  embeddingNewResponseJSON  `json:"-"`
}

func (*EmbeddingNewResponse) UnmarshalJSON

func (r *EmbeddingNewResponse) UnmarshalJSON(data []byte) (err error)

type EmbeddingNewResponseData

type EmbeddingNewResponseData struct {
	// The embedding vector, which is a list of floats. The length of vector depends on
	// the model as listed in the [embedding guide](/docs/guides/embeddings).
	Embedding EmbeddingNewResponseDataEmbeddingUnion `json:"embedding,required"`
	// The index of the embedding in the list of embeddings.
	Index int64 `json:"index,required"`
	// The object type, which is always "embedding".
	Object EmbeddingNewResponseDataObject `json:"object,required"`
	JSON   embeddingNewResponseDataJSON   `json:"-"`
}

Represents an embedding vector returned by embedding endpoint.

func (*EmbeddingNewResponseData) UnmarshalJSON

func (r *EmbeddingNewResponseData) UnmarshalJSON(data []byte) (err error)

type EmbeddingNewResponseDataEmbeddingArray

type EmbeddingNewResponseDataEmbeddingArray []float64

func (EmbeddingNewResponseDataEmbeddingArray) ImplementsEmbeddingNewResponseDataEmbeddingUnion

func (r EmbeddingNewResponseDataEmbeddingArray) ImplementsEmbeddingNewResponseDataEmbeddingUnion()

type EmbeddingNewResponseDataEmbeddingUnion

type EmbeddingNewResponseDataEmbeddingUnion interface {
	ImplementsEmbeddingNewResponseDataEmbeddingUnion()
}

The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the [embedding guide](/docs/guides/embeddings).

Union satisfied by EmbeddingNewResponseDataEmbeddingArray or shared.UnionString.

type EmbeddingNewResponseDataObject

type EmbeddingNewResponseDataObject string

The object type, which is always "embedding".

const (
	EmbeddingNewResponseDataObjectEmbedding EmbeddingNewResponseDataObject = "embedding"
)

func (EmbeddingNewResponseDataObject) IsKnown

type EmbeddingNewResponseObject

type EmbeddingNewResponseObject string

The object type, which is always "list".

const (
	EmbeddingNewResponseObjectList EmbeddingNewResponseObject = "list"
)

func (EmbeddingNewResponseObject) IsKnown

func (r EmbeddingNewResponseObject) IsKnown() bool

type EmbeddingNewResponseUsage

type EmbeddingNewResponseUsage struct {
	// The number of tokens used by the prompt.
	PromptTokens int64 `json:"prompt_tokens,required"`
	// The total number of tokens used by the request.
	TotalTokens int64                         `json:"total_tokens,required"`
	JSON        embeddingNewResponseUsageJSON `json:"-"`
}

The usage information for the request.

func (*EmbeddingNewResponseUsage) UnmarshalJSON

func (r *EmbeddingNewResponseUsage) UnmarshalJSON(data []byte) (err error)

type EmbeddingService

type EmbeddingService struct {
	Options []option.RequestOption
}

EmbeddingService contains methods and other services that help with interacting with the groq API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewEmbeddingService method instead.

func NewEmbeddingService

func NewEmbeddingService(opts ...option.RequestOption) (r *EmbeddingService)

NewEmbeddingService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*EmbeddingService) New

Creates an embedding vector representing the input text.

type Error

type Error = apierror.Error

type Model added in v0.9.0

type Model struct {
	// The model identifier, which can be referenced in the API endpoints.
	ID string `json:"id,required"`
	// The Unix timestamp (in seconds) when the model was created.
	Created int64 `json:"created,required"`
	// The object type, which is always "model".
	Object ModelObject `json:"object,required"`
	// The organization that owns the model.
	OwnedBy string    `json:"owned_by,required"`
	JSON    modelJSON `json:"-"`
}

Describes an OpenAI model offering that can be used with the API.

func (*Model) UnmarshalJSON

func (r *Model) UnmarshalJSON(data []byte) (err error)

type ModelDeleteResponse

type ModelDeleteResponse struct {
	ID      string                  `json:"id,required"`
	Deleted bool                    `json:"deleted,required"`
	Object  string                  `json:"object,required"`
	JSON    modelDeleteResponseJSON `json:"-"`
}

func (*ModelDeleteResponse) UnmarshalJSON

func (r *ModelDeleteResponse) UnmarshalJSON(data []byte) (err error)

type ModelListResponse

type ModelListResponse struct {
	Data   []Model                 `json:"data,required"`
	Object ModelListResponseObject `json:"object,required"`
	JSON   modelListResponseJSON   `json:"-"`
}

func (*ModelListResponse) UnmarshalJSON

func (r *ModelListResponse) UnmarshalJSON(data []byte) (err error)

type ModelListResponseObject

type ModelListResponseObject string
const (
	ModelListResponseObjectList ModelListResponseObject = "list"
)

func (ModelListResponseObject) IsKnown

func (r ModelListResponseObject) IsKnown() bool

type ModelObject

type ModelObject string

The object type, which is always "model".

const (
	ModelObjectModel ModelObject = "model"
)

func (ModelObject) IsKnown

func (r ModelObject) IsKnown() bool

type ModelService

type ModelService struct {
	Options []option.RequestOption
}

ModelService contains methods and other services that help with interacting with the groq API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewModelService method instead.

func NewModelService

func NewModelService(opts ...option.RequestOption) (r *ModelService)

NewModelService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*ModelService) Delete

func (r *ModelService) Delete(ctx context.Context, model string, opts ...option.RequestOption) (res *ModelDeleteResponse, err error)

Delete a model

func (*ModelService) Get

func (r *ModelService) Get(ctx context.Context, model string, opts ...option.RequestOption) (res *Model, err error)

Get a specific model

func (*ModelService) List

func (r *ModelService) List(ctx context.Context, opts ...option.RequestOption) (res *ModelListResponse, err error)

get all available models

Directories

Path Synopsis
examples
terminal-chat module
extensions
toolhouse module
scripts
models module

Jump to

Keyboard shortcuts

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