Documentation
¶
Index ¶
- func ContextResults() []string
- type Context
- func (c *Context) AddCallBack(cb func(fc *FinishContext))
- func (c *Context) Callbacks() []func(fc *FinishContext)
- func (c *Context) GetResponse() *Response
- func (c *Context) IsStopped() bool
- func (c *Context) Result() ResultError
- func (c *Context) SetResponse(resp *Response)
- func (c *Context) Stop(result ResultError)
- type FinishContext
- type ProviderSpec
- type Response
- type ResponseType
- type ResultError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextResults ¶
func ContextResults() []string
Types ¶
type Context ¶
type Context struct {
Ctx *context.Context
Provider *ProviderSpec
// Req is the original request from the user. It's body is in ReqBody.
Req *httpprot.Request
ReqBody []byte
ReqInfo *protocol.GeneralRequest
OpenAIReq map[string]any
RespType ResponseType
// ParseMetricFn is a function that parses the response body to a metric.
// If it is sent, it will be called to parse the response body to a metric.
// Otherwise, default ParseMetricFn will be used.
ParseMetricFn func(fc *FinishContext) *metricshub.Metric
// contains filtered or unexported fields
}
func (*Context) AddCallBack ¶
func (c *Context) AddCallBack(cb func(fc *FinishContext))
AddCallBack adds a callback function to the context. The callback will be called when the reponse is sent to the user.
func (*Context) Callbacks ¶
func (c *Context) Callbacks() []func(fc *FinishContext)
CallBacks returns all callback functions registered in the context.
func (*Context) GetResponse ¶
GetResponse returns the response of the context.
func (*Context) Result ¶
func (c *Context) Result() ResultError
Result returns the result of the context execution.
func (*Context) SetResponse ¶
SetResponse sets the response of the context. If you need to close the response body, you should add a callback function to the context using AddCallBack method.
func (*Context) Stop ¶
func (c *Context) Stop(result ResultError)
Stop stops the context execution and sets the result to be returned.
type FinishContext ¶
type ProviderSpec ¶
type ProviderSpec struct {
Name string `json:"name"`
ProviderType string `json:"providerType"`
BaseURL string `json:"baseURL"`
APIKey string `json:"apiKey"`
Headers map[string]string `json:"headers,omitempty"`
// Optional parameters for specific providers, such as Azure.
Endpoint string `json:"endpoint,omitempty"` // It is used for Azure OpenAI.
DeploymentID string `json:"deploymentID,omitempty"` // It is used for Azure OpenAI.
APIVersion string `json:"apiVersion,omitempty"` // It is used for Azure OpenAI.
}
ProviderSpec defines the specification for an AI provider.
type Response ¶
type Response struct {
StatusCode int
// ContentLength records the length of the associated content. The
// value -1 indicates that the length is unknown. Unless Request.Method
// is "HEAD", values >= 0 indicate that the given number of bytes may
// be read from Body.
ContentLength int64
Header http.Header
// BodyReader is the response body reader. Only one of BodyReader or BodyBytes should be set.
BodyReader io.Reader
// BodyBytes is the response body bytes. Only one of BodyReader or BodyBytes should be set.
BodyBytes []byte
}
type ResponseType ¶
type ResponseType string
ResponseType defines the type of response for AI requests.
const ( // ResponseTypeCompletions is used for standard completion requests. ResponseTypeCompletions ResponseType = "/v1/completions" // ResponseTypeChatCompletions is used for chat completion requests. ResponseTypeChatCompletions ResponseType = "/v1/chat/completions" // ResponseTypeEmbeddings is used for embedding requests. ResponseTypeEmbeddings ResponseType = "/v1/embeddings" // ResponseTypeModels is used for model listing requests. ResponseTypeModels ResponseType = "/v1/models" // ResponseTypeImageGenerations is used for image generation requests. ResponseTypeImageGenerations ResponseType = "/v1/images/generations" )
type ResultError ¶
type ResultError string
const ( // ResultOk indicates a successful request with no errors. // In easegress, it is represented as an empty string. ResultOk ResultError = "" ResultInternalError ResultError = "internalError" ResultClientError ResultError = "clientError" ResultServerError ResultError = "serverError" ResultFailureCodeError ResultError = "failureCodeError" ResultProviderError ResultError = "providerError" ResultMiddlewareError ResultError = "middlewareError" )
Click to show internal directories.
Click to hide internal directories.