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 ¶
- Variables
- type ChatCompletionUnified
- func (r ChatCompletionUnified) Do(providedCtx context.Context) (Response, error)
- func (r *ChatCompletionUnified) ErrorTrace(errortrace bool) *ChatCompletionUnified
- func (r *ChatCompletionUnified) FilterPath(filterpaths ...string) *ChatCompletionUnified
- func (r *ChatCompletionUnified) Header(key, value string) *ChatCompletionUnified
- func (r *ChatCompletionUnified) HttpRequest(ctx context.Context) (*http.Request, error)
- func (r *ChatCompletionUnified) Human(human bool) *ChatCompletionUnified
- func (r *ChatCompletionUnified) MaxCompletionTokens(maxcompletiontokens int64) *ChatCompletionUnified
- func (r *ChatCompletionUnified) Messages(messages ...types.MessageVariant) *ChatCompletionUnified
- func (r *ChatCompletionUnified) Model(model string) *ChatCompletionUnified
- func (r ChatCompletionUnified) Perform(providedCtx context.Context) (*http.Response, error)
- func (r *ChatCompletionUnified) Pretty(pretty bool) *ChatCompletionUnified
- func (r *ChatCompletionUnified) Raw(raw io.Reader) *ChatCompletionUnified
- func (r *ChatCompletionUnified) Request(req *Request) *ChatCompletionUnified
- func (r *ChatCompletionUnified) Stop(stops ...string) *ChatCompletionUnified
- func (r *ChatCompletionUnified) Temperature(temperature float32) *ChatCompletionUnified
- func (r *ChatCompletionUnified) Timeout(duration string) *ChatCompletionUnified
- func (r *ChatCompletionUnified) ToolChoice(completiontooltype types.CompletionToolTypeVariant) *ChatCompletionUnified
- func (r *ChatCompletionUnified) Tools(tools ...types.CompletionToolVariant) *ChatCompletionUnified
- func (r *ChatCompletionUnified) TopP(topp float32) *ChatCompletionUnified
- type NewChatCompletionUnified
- type Request
- type Response
Constants ¶
This section is empty.
Variables ¶
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 ¶
func New(tp elastictransport.Interface) *ChatCompletionUnified
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 ¶
HttpRequest returns the http.Request object built from the given parameters.
func (*ChatCompletionUnified) Human ¶
func (r *ChatCompletionUnified) Human(human bool) *ChatCompletionUnified
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 ¶
func (r *ChatCompletionUnified) Messages(messages ...types.MessageVariant) *ChatCompletionUnified
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 ¶
func (r *ChatCompletionUnified) Model(model string) *ChatCompletionUnified
The ID of the model to use. API name: model
func (ChatCompletionUnified) Perform ¶
Perform runs the http.Request through the provided transport and returns an http.Response.
func (*ChatCompletionUnified) Pretty ¶
func (r *ChatCompletionUnified) Pretty(pretty bool) *ChatCompletionUnified
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 ¶
func (r *ChatCompletionUnified) Raw(raw io.Reader) *ChatCompletionUnified
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 ¶
func (r *ChatCompletionUnified) Request(req *Request) *ChatCompletionUnified
Request allows to set the request property with the appropriate payload.
func (*ChatCompletionUnified) Stop ¶
func (r *ChatCompletionUnified) Stop(stops ...string) *ChatCompletionUnified
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 ¶
func (r *ChatCompletionUnified) ToolChoice(completiontooltype types.CompletionToolTypeVariant) *ChatCompletionUnified
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 ¶
func (r *ChatCompletionUnified) Tools(tools ...types.CompletionToolVariant) *ChatCompletionUnified
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 ¶
func (r *ChatCompletionUnified) TopP(topp float32) *ChatCompletionUnified
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