ai

package
v1.18.4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ai contains the model for LLM Function Calling features

Index

Constants

This section is empty.

Variables

View Source
var ErrNoFunctionCall = errors.New("no function call")

ErrNoFunctionCall is the error when no function call

View Source
var ReducerTag uint32 = 0x61

ReducerTag is the observed tag of the reducer

Functions

This section is empty.

Types

type FunctionCall

type FunctionCall struct {
	// TransID is the transaction id of the function calling chain, it is used for
	// multi-turn llm request.
	TransID string `json:"tid,omitempty"`
	// ReqID is the request id of the current function calling chain. Because multiple
	// function calling invokes may be occurred in the same request chain.
	ReqID string `json:"req_id"`
	// Arguments is the arguments of the function calling. This should be kept in this
	// context for next llm request in multi-turn request scenario.
	Arguments string `json:"arguments"`
	// Result is the struct result of the function calling.
	Result string `json:"result,omitempty"`
	// RetrievalResult is the string result of the function calling.
	RetrievalResult string `json:"retrieval_result,omitempty"`
	// ctx is the serverless context used in sfn.
	ToolCallID string `json:"tool_call_id,omitempty"`
	// FunctionName is the name of the function
	FunctionName string `json:"function_name,omitempty"`
	// IsOK is the flag to indicate the function calling is ok or not
	IsOK bool `json:"is_ok"`
	// Error is the error message
	Error string `json:"error,omitempty"`
	// contains filtered or unexported fields
}

FunctionCall describes the data structure when invoking the sfn function

func ParseFunctionCallContext

func ParseFunctionCallContext(ctx serverless.Context) (*FunctionCall, error)

ParseFunctionCallContext creates a new unctionCallObject from the given context

func (*FunctionCall) Bytes

func (fco *FunctionCall) Bytes() ([]byte, error)

Bytes serialize the []byte of FunctionCallObject

func (*FunctionCall) FromBytes

func (fco *FunctionCall) FromBytes(b []byte) error

FromBytes deserialize the FunctionCallObject from the given []byte

func (*FunctionCall) JSONString

func (fco *FunctionCall) JSONString() string

JSONString returns the JSON string of FunctionCallObject

func (*FunctionCall) SetRetrievalResult

func (fco *FunctionCall) SetRetrievalResult(retrievalResult string)

SetRetrievalResult sets the retrieval result

func (*FunctionCall) UnmarshalArguments

func (fco *FunctionCall) UnmarshalArguments(v any) error

UnmarshalArguments deserialize Arguments to the parameter object

func (*FunctionCall) Write

func (fco *FunctionCall) Write(result string) error

Write writes the result to zipper

func (*FunctionCall) WriteErrors

func (fco *FunctionCall) WriteErrors(err error) error

WriteErrors writes the error to reducer

type FunctionDefinition

type FunctionDefinition struct {
	Name        string              `json:"name"`
	Description string              `json:"description"`
	Parameters  *FunctionParameters `json:"parameters,omitempty"` // chatCompletionFunctionParameters
	Arguments   string              `json:"arguments,omitempty"`
}

FunctionDefinition is the function definition

type FunctionParameters

type FunctionParameters struct {
	Type       string                        `json:"type"`
	Properties map[string]*ParameterProperty `json:"properties"`
	Required   []string                      `json:"required"`
}

FunctionParameters defines the parameters the functions accepts. from API doc: "The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/gpt/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format."

type InvokeRequest

type InvokeRequest struct {
	ReqID  string `json:"req_id"` // req_id is the request id of the request
	Prompt string `json:"prompt"` // prompt is user input text for chat completion
}

InvokeRequest is the request from user to BasicAPIServer

type InvokeResponse

type InvokeResponse struct {
	Functions map[uint32][]*FunctionDefinition // key is the tag of yomo
	Content   string
	// ToolCalls is the toolCalls from llm api response
	ToolCalls map[uint32][]*ToolCall
}

InvokeResponse is the response for chat completions

type OverviewResponse

type OverviewResponse struct {
	Functions map[uint32]*FunctionDefinition // key is the tag of yomo
}

OverviewResponse is the response for overview

type ParameterProperty

type ParameterProperty struct {
	Type        string   `json:"type"`
	Description string   `json:"description"`
	Enum        []string `json:"enum,omitempty"`
}

ParameterProperty defines the property of the parameter

type ToolCall

type ToolCall struct {
	ID       string              `json:"id,omitempty"` // ID present in Response only
	Type     string              `json:"type"`
	Function *FunctionDefinition `json:"function"`
}

ToolCall is the tool call in Request and Response

func (*ToolCall) Equal

func (t *ToolCall) Equal(tool *ToolCall) bool

Equal compares two ToolCall function return true if type and function name are same

Jump to

Keyboard shortcuts

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