modelservingquery

package
v0.0.1-dev.8 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRouteOptimizationUnavailable = errors.New("modelservingquery: route optimization unavailable for this endpoint")

ErrRouteOptimizationUnavailable is returned by QueryOptimized when the query cannot be routed to the data plane: the client is not configured with OAuth-capable credentials, the request has no endpoint name, or the endpoint does not advertise data-plane query info. A caller that wants best-effort behavior can detect this with errors.Is and fall back to Query:

resp, err := c.QueryOptimized(ctx, req)
if errors.Is(err, ErrRouteOptimizationUnavailable) {
    resp, err = c.Query(ctx, req)
}

Functions

This section is empty.

Types

type ChatMessage

type ChatMessage struct {
	// The role of the message. One of [system, user, assistant].
	Role ChatMessageRole
	// The content of the message.
	Content *string
}

type ChatMessageRole

type ChatMessageRole string

The role of the message. One of [system, user, assistant].

const (
	ChatMessageRole_Unspecified ChatMessageRole = ""
	ChatMessageRole_System      ChatMessageRole = "system"
	ChatMessageRole_User        ChatMessageRole = "user"
	ChatMessageRole_Assistant   ChatMessageRole = "assistant"
)

type Client

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

func NewClient

func NewClient(ctx context.Context, opts ...client.Option) (*Client, error)

func (*Client) Query

func (c *Client) Query(ctx context.Context, req QueryEndpointRequest, opts ...call.Option) (*QueryEndpointResponse, error)

Query a serving endpoint

func (*Client) QueryOptimized

func (c *Client) QueryOptimized(ctx context.Context, req QueryEndpointRequest, opts ...ops.Option) (*QueryEndpointResponse, error)

QueryOptimized queries a serving endpoint directly on the data plane, bypassing the control plane for lower latency.

It requires OAuth-capable credentials and an endpoint that advertises data-plane query info. When either is missing, or the request has no endpoint name, it returns an error wrapping ErrRouteOptimizationUnavailable; callers that want to fall back can test for it with errors.Is and call Query.

Unlike Query, it never falls back to the control plane once the data-plane call is made: an error from that call is returned as is, so a billed inference is not silently retried elsewhere. It otherwise behaves like Query.

type DataframeSplitInput

type DataframeSplitInput struct {
	// Index array for the dataframe
	Index []int
	// Columns array for the dataframe
	Columns []json.RawMessage
	// Data array for the dataframe
	Data []json.RawMessage
}

type EmbeddingsV1ResponseEmbeddingElement

type EmbeddingsV1ResponseEmbeddingElement struct {
	// The embedding vector
	Embedding []float64
	// The index of the embedding in the response.
	Index *int
	// This will always be 'embedding'.
	Object EmbeddingsV1ResponseEmbeddingElementObject
}

type EmbeddingsV1ResponseEmbeddingElementObject

type EmbeddingsV1ResponseEmbeddingElementObject string

This will always be 'embedding'.

const (
	EmbeddingsV1ResponseEmbeddingElementObject_Unspecified EmbeddingsV1ResponseEmbeddingElementObject = ""
	EmbeddingsV1ResponseEmbeddingElementObject_Embedding   EmbeddingsV1ResponseEmbeddingElementObject = "embedding"
)

type ExternalModelUsageElement

type ExternalModelUsageElement struct {
	// The number of tokens in the prompt.
	PromptTokens *int
	// The number of tokens in the chat/completions response.
	CompletionTokens *int
	// The total number of tokens in the prompt and response.
	TotalTokens *int
}

type QueryEndpointRequest

type QueryEndpointRequest struct {
	// The name of the serving endpoint. This field is required and is provided via
	// the path parameter.
	Name *string
	// The prompt string (or array of strings) field used ONLY for __completions
	// external & foundation model__ serving endpoints and should only be used with
	// other completions query fields.
	Prompt json.RawMessage
	// The input string (or array of strings) field used ONLY for __embeddings
	// external & foundation model__ serving endpoints and is the only field (along
	// with extra_params if needed) used by embeddings queries.
	Input json.RawMessage
	// The messages field used ONLY for __chat external & foundation model__ serving
	// endpoints. This is an array of ChatMessage objects and should only be used
	// with other chat query fields.
	Messages []ChatMessage
	// The temperature field used ONLY for __completions__ and __chat external &
	// foundation model__ serving endpoints. This is a float between 0.0 and 2.0
	// with a default of 1.0 and should only be used with other chat/completions
	// query fields.
	Temperature *float64
	// The stop sequences field used ONLY for __completions__ and __chat external &
	// foundation model__ serving endpoints. This is a list of strings and should
	// only be used with other chat/completions query fields.
	Stop []string
	// The max tokens field used ONLY for __completions__ and __chat external &
	// foundation model__ serving endpoints. This is an integer and should only be
	// used with other chat/completions query fields.
	MaxTokens *int
	// The n (number of candidates) field used ONLY for __completions__ and __chat
	// external & foundation model__ serving endpoints. This is an integer between 1
	// and 5 with a default of 1 and should only be used with other chat/completions
	// query fields.
	N *int
	// The stream field used ONLY for __completions__ and __chat external &
	// foundation model__ serving endpoints. This is a boolean defaulting to false
	// and should only be used with other chat/completions query fields.
	Stream *bool
	// The extra parameters field used ONLY for __completions, chat,__ and
	// __embeddings external & foundation model__ serving endpoints. This is a map
	// of strings and should only be used with other external/foundation model query
	// fields.
	ExtraParams map[string]string
	// Pandas Dataframe input in the records orientation.
	DataframeRecords []json.RawMessage
	// Pandas Dataframe input in the split orientation.
	DataframeSplit *DataframeSplitInput
	// Tensor-based input in row format.
	Instances []json.RawMessage
	// Tensor-based input in columnar format.
	Inputs json.RawMessage
	// Optional user-provided request identifier that will be recorded in the
	// inference table and the usage tracking table.
	ClientRequestId *string
	// Optional user-provided context that will be recorded in the usage tracking
	// table.
	UsageContext map[string]string
}

type QueryEndpointResponse

type QueryEndpointResponse struct {
	// The list of choices returned by the __chat or completions external/foundation
	// model__ serving endpoint.
	Choices []V1ResponseChoiceElement
	// The list of the embeddings returned by the __embeddings external/foundation
	// model__ serving endpoint.
	Data []EmbeddingsV1ResponseEmbeddingElement
	// The name of the __external/foundation model__ used for querying. This is the
	// name of the model that was specified in the endpoint config.
	Model *string
	// The usage object that may be returned by the __external/foundation model__
	// serving endpoint. This contains information about the number of tokens used
	// in the prompt and response.
	Usage *ExternalModelUsageElement
	// The ID of the query that may be returned by a __completions or chat
	// external/foundation model__ serving endpoint.
	Id *string
	// The timestamp in seconds when the query was created in Unix time returned by
	// a __completions or chat external/foundation model__ serving endpoint.
	Created *int64
	// The type of object returned by the __external/foundation model__ serving
	// endpoint, one of [text_completion, chat.completion, list (of embeddings)].
	Object QueryEndpointResponseObject
	// The predictions returned by the serving endpoint.
	Predictions []json.RawMessage
	// The outputs of the feature serving endpoint.
	Outputs []json.RawMessage
	// The name of the served model that served the request. This is useful when
	// there are multiple models behind the same endpoint with traffic split.
	ServedModelName *string
}

type QueryEndpointResponseObject

type QueryEndpointResponseObject string

The type of object returned by the __external/foundation model__ serving endpoint, one of [text_completion, chat.completion, list (of embeddings)].

const (
	QueryEndpointResponseObject_Unspecified    QueryEndpointResponseObject = ""
	QueryEndpointResponseObject_TextCompletion QueryEndpointResponseObject = "text_completion"
	QueryEndpointResponseObject_ChatCompletion QueryEndpointResponseObject = "chat.completion"
	QueryEndpointResponseObject_List           QueryEndpointResponseObject = "list"
)

type V1ResponseChoiceElement

type V1ResponseChoiceElement struct {
	// The text response from the __completions__ endpoint.
	Text *string
	// The message response from the __chat__ endpoint.
	Message *ChatMessage
	// The index of the choice in the __chat or completions__ response.
	Index *int
	// The finish reason returned by the endpoint.
	FinishReason *string
	// The logprobs returned only by the __completions__ endpoint.
	Logprobs *int
}

Jump to

Keyboard shortcuts

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