chatcompletionunified

package
v9.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Perform chat completion inference

The chat completion inference API enables real-time responses for chat completion tasks by delivering answers incrementally, reducing response times during computation. It only works with the `chat_completion` task type for `openai` and `elastic` inference services.

NOTE: The `chat_completion` task type is only available within the _stream API and only supports streaming. The Chat completion inference API and the Stream inference API differ in their response structure and capabilities. The Chat completion inference API provides more comprehensive customization options through more fields and function calling support. If you use the `openai`, `hugging_face` or the `elastic` service, use the Chat completion inference API.

Index

Constants

This section is empty.

Variables

View Source
var ErrBuildPath = errors.New("cannot build path, check for missing path parameters")

ErrBuildPath is returned in case of missing parameters within the build of the request.

Functions

This section is empty.

Types

type ChatCompletionUnified

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

func New

Perform chat completion inference

The chat completion inference API enables real-time responses for chat completion tasks by delivering answers incrementally, reducing response times during computation. It only works with the `chat_completion` task type for `openai` and `elastic` inference services.

NOTE: The `chat_completion` task type is only available within the _stream API and only supports streaming. The Chat completion inference API and the Stream inference API differ in their response structure and capabilities. The Chat completion inference API provides more comprehensive customization options through more fields and function calling support. If you use the `openai`, `hugging_face` or the `elastic` service, use the Chat completion inference API.

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-unified-inference

func (ChatCompletionUnified) Do

func (r ChatCompletionUnified) Do(providedCtx context.Context) (Response, error)

Do runs the request through the transport, handle the response and returns a chatcompletionunified.Response

func (*ChatCompletionUnified) ErrorTrace

func (r *ChatCompletionUnified) ErrorTrace(errortrace bool) *ChatCompletionUnified

ErrorTrace When set to `true` Elasticsearch will include the full stack trace of errors when they occur. API name: error_trace

func (*ChatCompletionUnified) FilterPath

func (r *ChatCompletionUnified) FilterPath(filterpaths ...string) *ChatCompletionUnified

FilterPath Comma-separated list of filters in dot notation which reduce the response returned by Elasticsearch. API name: filter_path

func (*ChatCompletionUnified) Header

func (r *ChatCompletionUnified) Header(key, value string) *ChatCompletionUnified

Header set a key, value pair in the ChatCompletionUnified headers map.

func (*ChatCompletionUnified) HttpRequest

func (r *ChatCompletionUnified) HttpRequest(ctx context.Context) (*http.Request, error)

HttpRequest returns the http.Request object built from the given parameters.

func (*ChatCompletionUnified) Human

Human When set to `true` will return statistics in a format suitable for humans. For example `"exists_time": "1h"` for humans and `"exists_time_in_millis": 3600000` for computers. When disabled the human readable values will be omitted. This makes sense for responses being consumed only by machines. API name: human

func (*ChatCompletionUnified) MaxCompletionTokens

func (r *ChatCompletionUnified) MaxCompletionTokens(maxcompletiontokens int64) *ChatCompletionUnified

The upper bound limit for the number of tokens that can be generated for a completion request. API name: max_completion_tokens

func (*ChatCompletionUnified) Messages

A list of objects representing the conversation. Requests should generally only add new messages from the user (role `user`). The other message roles (`assistant`, `system`, or `tool`) should generally only be copied from the response to a previous completion request, such that the messages array is built up throughout a conversation. API name: messages

func (*ChatCompletionUnified) Model

The ID of the model to use. API name: model

func (ChatCompletionUnified) Perform

func (r ChatCompletionUnified) Perform(providedCtx context.Context) (*http.Response, error)

Perform runs the http.Request through the provided transport and returns an http.Response.

func (*ChatCompletionUnified) Pretty

Pretty If set to `true` the returned JSON will be "pretty-formatted". Only use this option for debugging only. API name: pretty

func (*ChatCompletionUnified) Raw

Raw takes a json payload as input which is then passed to the http.Request If specified Raw takes precedence on Request method.

func (*ChatCompletionUnified) Request

Request allows to set the request property with the appropriate payload.

func (*ChatCompletionUnified) Stop

A sequence of strings to control when the model should stop generating additional tokens. API name: stop

func (*ChatCompletionUnified) Temperature

func (r *ChatCompletionUnified) Temperature(temperature float32) *ChatCompletionUnified

The sampling temperature to use. API name: temperature

func (*ChatCompletionUnified) Timeout

func (r *ChatCompletionUnified) Timeout(duration string) *ChatCompletionUnified

Timeout Specifies the amount of time to wait for the inference request to complete. API name: timeout

func (*ChatCompletionUnified) ToolChoice

Controls which tool is called by the model. String representation: One of `auto`, `none`, or `requrired`. `auto` allows the model to choose between calling tools and generating a message. `none` causes the model to not call any tools. `required` forces the model to call one or more tools. Example (object representation): ```

{
  "tool_choice": {
      "type": "function",
      "function": {
          "name": "get_current_weather"
      }
  }
}

``` API name: tool_choice

func (*ChatCompletionUnified) Tools

A list of tools that the model can call. Example: ```

{
  "tools": [
      {
          "type": "function",
          "function": {
              "name": "get_price_of_item",
              "description": "Get the current price of an item",
              "parameters": {
                  "type": "object",
                  "properties": {
                      "item": {
                          "id": "12345"
                      },
                      "unit": {
                          "type": "currency"
                      }
                  }
              }
          }
      }
  ]
}

``` API name: tools

func (*ChatCompletionUnified) TopP

Nucleus sampling, an alternative to sampling with temperature. API name: top_p

type NewChatCompletionUnified

type NewChatCompletionUnified func(inferenceid string) *ChatCompletionUnified

NewChatCompletionUnified type alias for index.

func NewChatCompletionUnifiedFunc

func NewChatCompletionUnifiedFunc(tp elastictransport.Interface) NewChatCompletionUnified

NewChatCompletionUnifiedFunc returns a new instance of ChatCompletionUnified with the provided transport. Used in the index of the library this allows to retrieve every apis in once place.

type Request

type Request = types.RequestChatCompletion

Request holds the request body struct for the package chatcompletionunified

https://github.com/elastic/elasticsearch-specification/blob/907d11a72a6bfd37b777d526880c56202889609e/specification/inference/chat_completion_unified/UnifiedRequest.ts#L24-L61

func NewRequest

func NewRequest() *Request

NewRequest returns a Request

type Response

type Response = []byte

func NewResponse

func NewResponse() Response

NewResponse returns a Response

Jump to

Keyboard shortcuts

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