inference

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package inference provides primitives to interact with the openapi HTTP API.

Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.3.0 DO NOT EDIT.

Index

Constants

View Source
const (
	ApiKeyAuthScopes = "ApiKeyAuth.Scopes"
)

Variables

This section is empty.

Functions

func NewEmbedRequest

func NewEmbedRequest(server string, body EmbedJSONRequestBody) (*http.Request, error)

NewEmbedRequest calls the generic Embed builder with application/json body

func NewEmbedRequestWithBody

func NewEmbedRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewEmbedRequestWithBody generates requests for Embed with any type of body

func NewRerankRequest

func NewRerankRequest(server string, body RerankJSONRequestBody) (*http.Request, error)

NewRerankRequest calls the generic Rerank builder with application/json body

func NewRerankRequestWithBody

func NewRerankRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewRerankRequestWithBody generates requests for Rerank with any type of body

Types

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

Creates a new Client, with reasonable defaults

func (*Client) Embed

func (c *Client) Embed(ctx context.Context, body EmbedJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) EmbedWithBody

func (c *Client) EmbedWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) Rerank

func (c *Client) Rerank(ctx context.Context, body RerankJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) RerankWithBody

func (c *Client) RerankWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

type ClientInterface

type ClientInterface interface {
	// EmbedWithBody request with any body
	EmbedWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	Embed(ctx context.Context, body EmbedJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// RerankWithBody request with any body
	RerankWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	Rerank(ctx context.Context, body RerankJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
}

The interface specification for the client above.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type ClientWithResponses

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses

func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)

NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling

func (*ClientWithResponses) EmbedWithBodyWithResponse

func (c *ClientWithResponses) EmbedWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*EmbedResponse, error)

EmbedWithBodyWithResponse request with arbitrary body returning *EmbedResponse

func (*ClientWithResponses) EmbedWithResponse

func (c *ClientWithResponses) EmbedWithResponse(ctx context.Context, body EmbedJSONRequestBody, reqEditors ...RequestEditorFn) (*EmbedResponse, error)

func (*ClientWithResponses) RerankWithBodyWithResponse

func (c *ClientWithResponses) RerankWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RerankResponse, error)

RerankWithBodyWithResponse request with arbitrary body returning *RerankResponse

func (*ClientWithResponses) RerankWithResponse

func (c *ClientWithResponses) RerankWithResponse(ctx context.Context, body RerankJSONRequestBody, reqEditors ...RequestEditorFn) (*RerankResponse, error)

type ClientWithResponsesInterface

type ClientWithResponsesInterface interface {
	// EmbedWithBodyWithResponse request with any body
	EmbedWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*EmbedResponse, error)

	EmbedWithResponse(ctx context.Context, body EmbedJSONRequestBody, reqEditors ...RequestEditorFn) (*EmbedResponse, error)

	// RerankWithBodyWithResponse request with any body
	RerankWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RerankResponse, error)

	RerankWithResponse(ctx context.Context, body RerankJSONRequestBody, reqEditors ...RequestEditorFn) (*RerankResponse, error)
}

ClientWithResponsesInterface is the interface specification for the client with responses above.

type Document

type Document map[string]string

Document Document for reranking

type EmbedJSONRequestBody

type EmbedJSONRequestBody = EmbedRequest

EmbedJSONRequestBody defines body for Embed for application/json ContentType.

type EmbedRequest

type EmbedRequest struct {
	// Inputs List of inputs to generate embeddings for.
	Inputs []struct {
		Text *string `json:"text,omitempty"`
	} `json:"inputs"`

	// Model The [model](https://docs.pinecone.io/guides/inference/understanding-inference#models) to use for embedding generation.
	Model string `json:"model"`

	// Parameters Model-specific parameters.
	Parameters *struct {
		// InputType Common property used to distinguish between types of data.
		InputType *string `json:"input_type,omitempty"`

		// Truncate How to handle inputs longer than those supported by the model. If `"END"`, truncate the input sequence at the token limit. If `"NONE"`, return an error when the input exceeds the token limit.
		Truncate *string `json:"truncate,omitempty"`
	} `json:"parameters,omitempty"`
}

EmbedRequest defines model for EmbedRequest.

type EmbedResponse

type EmbedResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *EmbeddingsList
	JSON400      *ErrorResponse
	JSON401      *ErrorResponse
	JSON500      *ErrorResponse
}

func ParseEmbedResponse

func ParseEmbedResponse(rsp *http.Response) (*EmbedResponse, error)

ParseEmbedResponse parses an HTTP response from a EmbedWithResponse call

func (EmbedResponse) Status

func (r EmbedResponse) Status() string

Status returns HTTPResponse.Status

func (EmbedResponse) StatusCode

func (r EmbedResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type Embedding

type Embedding struct {
	// Values The embedding values.
	Values *[]float32 `json:"values,omitempty"`
}

Embedding Embedding of a single input

type EmbeddingsList

type EmbeddingsList struct {
	// Data The embeddings generated for the inputs.
	Data []Embedding `json:"data"`

	// Model The model used to generate the embeddings
	Model string `json:"model"`

	// Usage Usage statistics for the model inference.
	Usage struct {
		// TotalTokens Total number of tokens consumed across all inputs.
		TotalTokens *int `json:"total_tokens,omitempty"`
	} `json:"usage"`
}

EmbeddingsList Embeddings generated for the input

type ErrorResponse

type ErrorResponse struct {
	// Error Detailed information about the error that occurred.
	Error struct {
		Code ErrorResponseErrorCode `json:"code"`

		// Details Additional information about the error. This field is not guaranteed to be present.
		Details *map[string]interface{} `json:"details,omitempty"`
		Message string                  `json:"message"`
	} `json:"error"`

	// Status The HTTP status code of the error.
	Status int `json:"status"`
}

ErrorResponse The response shape used for all error responses.

type ErrorResponseErrorCode

type ErrorResponseErrorCode string

ErrorResponseErrorCode defines model for ErrorResponse.Error.Code.

const (
	ABORTED            ErrorResponseErrorCode = "ABORTED"
	ALREADYEXISTS      ErrorResponseErrorCode = "ALREADY_EXISTS"
	DATALOSS           ErrorResponseErrorCode = "DATA_LOSS"
	DEADLINEEXCEEDED   ErrorResponseErrorCode = "DEADLINE_EXCEEDED"
	FAILEDPRECONDITION ErrorResponseErrorCode = "FAILED_PRECONDITION"
	FORBIDDEN          ErrorResponseErrorCode = "FORBIDDEN"
	INTERNAL           ErrorResponseErrorCode = "INTERNAL"
	INVALIDARGUMENT    ErrorResponseErrorCode = "INVALID_ARGUMENT"
	NOTFOUND           ErrorResponseErrorCode = "NOT_FOUND"
	OK                 ErrorResponseErrorCode = "OK"
	OUTOFRANGE         ErrorResponseErrorCode = "OUT_OF_RANGE"
	PERMISSIONDENIED   ErrorResponseErrorCode = "PERMISSION_DENIED"
	QUOTAEXCEEDED      ErrorResponseErrorCode = "QUOTA_EXCEEDED"
	RESOURCEEXHAUSTED  ErrorResponseErrorCode = "RESOURCE_EXHAUSTED"
	UNAUTHENTICATED    ErrorResponseErrorCode = "UNAUTHENTICATED"
	UNAVAILABLE        ErrorResponseErrorCode = "UNAVAILABLE"
	UNIMPLEMENTED      ErrorResponseErrorCode = "UNIMPLEMENTED"
	UNKNOWN            ErrorResponseErrorCode = "UNKNOWN"
)

Defines values for ErrorResponseErrorCode.

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer performs HTTP requests.

The standard http.Client implements this interface.

type RankedDocument

type RankedDocument struct {
	// Document Document for reranking
	Document *Document `json:"document,omitempty"`

	// Index The index of the document
	Index int `json:"index"`

	// Score The relevance score of the document normalized between 0 and 1.
	Score float32 `json:"score"`
}

RankedDocument A ranked document with a relevance score and an index position.

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function

type RerankJSONBody

type RerankJSONBody struct {
	// Documents The documents to rerank.
	Documents []Document `json:"documents"`

	// Model The [model](https://docs.pinecone.io/guides/inference/understanding-inference#models) to use for reranking.
	Model string `json:"model"`

	// Parameters Additional model-specific parameters for the reranker.
	Parameters *map[string]string `json:"parameters,omitempty"`

	// Query The query to rerank documents against.
	Query string `json:"query"`

	// RankFields The fields to rank the documents by. If not provided, the default is `"text"`.
	RankFields *[]string `json:"rank_fields,omitempty"`

	// ReturnDocuments Whether to return the documents in the response.
	ReturnDocuments *bool `json:"return_documents,omitempty"`

	// TopN The number of results to return sorted by relevance. Defaults to the number of inputs.
	TopN *int `json:"top_n,omitempty"`
}

RerankJSONBody defines parameters for Rerank.

type RerankJSONRequestBody

type RerankJSONRequestBody RerankJSONBody

RerankJSONRequestBody defines body for Rerank for application/json ContentType.

type RerankResponse

type RerankResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *RerankResult
	JSON400      *ErrorResponse
	JSON401      *ErrorResponse
	JSON500      *ErrorResponse
}

func ParseRerankResponse

func ParseRerankResponse(rsp *http.Response) (*RerankResponse, error)

ParseRerankResponse parses an HTTP response from a RerankWithResponse call

func (RerankResponse) Status

func (r RerankResponse) Status() string

Status returns HTTPResponse.Status

func (RerankResponse) StatusCode

func (r RerankResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type RerankResult

type RerankResult struct {
	// Data The reranked documents.
	Data []RankedDocument `json:"data"`

	// Model The model used to rerank documents.
	Model string `json:"model"`

	// Usage Usage statistics for the model inference.
	Usage struct {
		RerankUnits *int `json:"rerank_units,omitempty"`
	} `json:"usage"`
}

RerankResult The result of a reranking request.

Jump to

Keyboard shortcuts

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