prompt

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToSpanPartType added in v0.1.10

func ToSpanPartType(partType entity.ContentType) tracespec.ModelMessagePartType

Types

type CacheOption

type CacheOption struct {
	EnableAsyncUpdate bool          // Whether to enable asynchronous updates
	UpdateInterval    time.Duration // Update interval, if 0, use default value
	MaxCacheSize      int
}

type ContentPart added in v0.1.10

type ContentPart struct {
	Type       *ContentType `json:"type"`
	Text       *string      `json:"text,omitempty"`
	ImageURL   *string      `json:"image_url,omitempty"`
	Base64Data *string      `json:"base64_data,omitempty"`
}

type ContentType added in v0.1.10

type ContentType string
const (
	ContentTypeText              ContentType = "text"
	ContentTypeImageURL          ContentType = "image_url"
	ContentTypeBase64Data        ContentType = "base64_data"
	ContentTypeMultiPartVariable ContentType = "multi_part_variable"
)

type ExecuteData added in v0.1.12

type ExecuteData struct {
	Message      *Message    `json:"message,omitempty"`
	FinishReason *string     `json:"finish_reason,omitempty"`
	Usage        *TokenUsage `json:"usage,omitempty"`
}

type ExecuteOption added in v0.1.12

type ExecuteOption func(option *ExecuteOptions)

ExecuteOption Execute选项函数

type ExecuteOptions added in v0.1.12

type ExecuteOptions struct{}

ExecuteOptions Execute选项

type ExecuteRequest added in v0.1.12

type ExecuteRequest struct {
	WorkspaceID      string         `json:"workspace_id"`
	PromptIdentifier *PromptQuery   `json:"prompt_identifier,omitempty"`
	VariableVals     []*VariableVal `json:"variable_vals,omitempty"`
	Messages         []*Message     `json:"messages,omitempty"`
}

type ExecuteResponse added in v0.1.12

type ExecuteResponse struct {
	httpclient.BaseResponse
	Data *ExecuteData `json:"data"`
}

type ExecuteSSEParser added in v0.1.12

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

ExecuteSSEParser implements SSEParser for ExecuteResult

func NewExecuteSSEParser added in v0.1.12

func NewExecuteSSEParser(logID string) *ExecuteSSEParser

NewExecuteSSEParser creates a new ExecuteSSEParser

func (*ExecuteSSEParser) HandleError added in v0.1.12

func (p *ExecuteSSEParser) HandleError(sse *stream.ServerSentEvent) error

HandleError checks if the SSE event contains an error

func (*ExecuteSSEParser) Parse added in v0.1.12

Parse parses SSE event into ExecuteResult

type ExecuteStreamReader added in v0.1.12

type ExecuteStreamReader struct {
	*stream.BaseStreamReader[entity.ExecuteResult]
}

ExecuteStreamReader wraps BaseStreamReader for ExecuteResult

func NewExecuteStreamReader added in v0.1.12

func NewExecuteStreamReader(ctx context.Context, resp *http.Response) (*ExecuteStreamReader, error)

NewExecuteStreamReader creates a new ExecuteStreamReader

type ExecuteStreamingData added in v0.1.12

type ExecuteStreamingData struct {
	Code         *int32      `json:"code,omitempty"`
	Msg          *string     `json:"msg,omitempty"`
	Message      *Message    `json:"message,omitempty"`
	FinishReason *string     `json:"finish_reason,omitempty"`
	Usage        *TokenUsage `json:"usage,omitempty"`
}

ExecuteStreamingData 流式执行响应数据结构体

type ExecuteStreamingOption added in v0.1.12

type ExecuteStreamingOption func(option *ExecuteStreamingOptions)

ExecuteStreamingOption ExecuteStreaming选项函数

type ExecuteStreamingOptions added in v0.1.12

type ExecuteStreamingOptions struct{}

ExecuteStreamingOptions ExecuteStreaming选项

type Function

type Function struct {
	Name        string  `json:"name"`
	Description *string `json:"description,omitempty"`
	Parameters  *string `json:"parameters,omitempty"`
}

type FunctionCall added in v0.1.12

type FunctionCall struct {
	Name      string  `json:"name"`
	Arguments *string `json:"arguments,omitempty"`
}

type GetPromptOptions

type GetPromptOptions struct{}

type GetPromptParam

type GetPromptParam struct {
	PromptKey string
	Version   string
	Label     string
}

type LLMConfig

type LLMConfig struct {
	Temperature      *float64 `json:"temperature,omitempty"`
	MaxTokens        *int32   `json:"max_tokens,omitempty"`
	TopK             *int32   `json:"top_k,omitempty"`
	TopP             *float64 `json:"top_p,omitempty"`
	FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"`
	PresencePenalty  *float64 `json:"presence_penalty,omitempty"`
	JSONMode         *bool    `json:"json_mode,omitempty"`
}

type MPullPromptRequest

type MPullPromptRequest struct {
	WorkSpaceID string        `json:"workspace_id"`
	Queries     []PromptQuery `json:"queries"`
}

type MPullPromptResponse

type MPullPromptResponse struct {
	httpclient.BaseResponse
	Data PromptResultData `json:"data"`
}

type Message

type Message struct {
	Role             Role           `json:"role"`
	ReasoningContent *string        `json:"reasoning_content,omitempty"`
	Content          *string        `json:"content,omitempty"`
	Parts            []*ContentPart `json:"parts,omitempty"`
	ToolCallID       *string        `json:"tool_call_id,omitempty"`
	ToolCalls        []*ToolCall    `json:"tool_calls,omitempty"`
}

type OpenAPIClient

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

func (*OpenAPIClient) Execute added in v0.1.12

func (o *OpenAPIClient) Execute(ctx context.Context, req ExecuteRequest) (*ExecuteData, error)

Execute 执行Prompt请求

func (*OpenAPIClient) ExecuteStreaming added in v0.1.12

func (o *OpenAPIClient) ExecuteStreaming(ctx context.Context, req ExecuteRequest) (*http.Response, error)

ExecuteStreaming 流式执行Prompt请求

func (*OpenAPIClient) MPullPrompt

func (o *OpenAPIClient) MPullPrompt(ctx context.Context, req MPullPromptRequest) ([]*PromptResult, error)

type Option

type Option func(*CacheOption)

type Options

type Options struct {
	WorkspaceID                string
	PromptCacheMaxCount        int
	PromptCacheRefreshInterval time.Duration
	PromptTrace                bool
}

type Prompt

type Prompt struct {
	WorkspaceID    string          `json:"workspace_id"`
	PromptKey      string          `json:"prompt_key"`
	Version        string          `json:"version"`
	PromptTemplate *PromptTemplate `json:"prompt_template,omitempty"`
	Tools          []*Tool         `json:"tools,omitempty"`
	ToolCallConfig *ToolCallConfig `json:"tool_call_config,omitempty"`
	LLMConfig      *LLMConfig      `json:"llm_config,omitempty"`
}

type PromptCache

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

func (*PromptCache) Get

func (c *PromptCache) Get(promptKey, version, label string) (*entity.Prompt, bool)

func (*PromptCache) GetAllPromptQueries

func (c *PromptCache) GetAllPromptQueries() []PromptQuery

GetAllPromptQueries gets all cached Prompt query conditions

func (*PromptCache) Set

func (c *PromptCache) Set(promptKey, version, label string, prompt *entity.Prompt)

func (*PromptCache) Start

func (c *PromptCache) Start()

func (*PromptCache) Stop

func (c *PromptCache) Stop()

type PromptFormatOptions

type PromptFormatOptions struct{}

type PromptQuery

type PromptQuery struct {
	PromptKey string `json:"prompt_key"`
	Version   string `json:"version"`
	Label     string `json:"label,omitempty"`
}

type PromptResult

type PromptResult struct {
	Query  PromptQuery `json:"query"`
	Prompt *Prompt     `json:"prompt,omitempty"`
}

type PromptResultData

type PromptResultData struct {
	Items []*PromptResult `json:"items,omitempty"`
}

type PromptTemplate

type PromptTemplate struct {
	TemplateType TemplateType   `json:"template_type"`
	Messages     []*Message     `json:"messages,omitempty"`
	VariableDefs []*VariableDef `json:"variable_defs,omitempty"`
}

type Provider

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

func NewPromptProvider

func NewPromptProvider(httpClient *httpclient.Client, traceProvider *trace.Provider, options Options) *Provider

func (*Provider) Execute added in v0.1.12

func (p *Provider) Execute(ctx context.Context, req *entity.ExecuteParam, options ...ExecuteOption) (entity.ExecuteResult, error)

Execute 执行Prompt并返回结果

func (*Provider) ExecuteStreaming added in v0.1.12

ExecuteStreaming 流式执行Prompt并返回流式读取器

func (*Provider) GetPrompt

func (p *Provider) GetPrompt(ctx context.Context, param GetPromptParam, options GetPromptOptions) (prompt *entity.Prompt, err error)

func (*Provider) PromptFormat

func (p *Provider) PromptFormat(ctx context.Context, prompt *entity.Prompt, variables map[string]any, options PromptFormatOptions) (messages []*entity.Message, err error)

type Role

type Role string
const (
	RoleSystem      Role = "system"
	RoleUser        Role = "user"
	RoleAssistant   Role = "assistant"
	RoleTool        Role = "tool"
	RolePlaceholder Role = "placeholder"
)

type TemplateType

type TemplateType string
const (
	TemplateTypeNormal TemplateType = "normal"
	TemplateTypeJinja2 TemplateType = "jinja2"
)

type TokenUsage added in v0.1.12

type TokenUsage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

type Tool

type Tool struct {
	Type     ToolType  `json:"type"`
	Function *Function `json:"function,omitempty"`
}

type ToolCall added in v0.1.12

type ToolCall struct {
	Index        *int32        `json:"index,omitempty"`
	ID           *string       `json:"id,omitempty"`
	Type         ToolType      `json:"type"`
	FunctionCall *FunctionCall `json:"function_call,omitempty"`
}

type ToolCallConfig

type ToolCallConfig struct {
	ToolChoice ToolChoiceType `json:"tool_choice"`
}

type ToolChoiceType

type ToolChoiceType string
const (
	ToolChoiceTypeAuto ToolChoiceType = "auto"
	ToolChoiceTypeNone ToolChoiceType = "none"
)

type ToolType

type ToolType string
const (
	ToolTypeFunction ToolType = "function"
)

type VariableDef

type VariableDef struct {
	Key  string       `json:"key"`
	Desc string       `json:"desc"`
	Type VariableType `json:"type"`
}

type VariableType

type VariableType string
const (
	VariableTypeString       VariableType = "string"
	VariableTypePlaceholder  VariableType = "placeholder"
	VariableTypeBoolean      VariableType = "boolean"
	VariableTypeInteger      VariableType = "integer"
	VariableTypeFloat        VariableType = "float"
	VariableTypeObject       VariableType = "object"
	VariableTypeArrayString  VariableType = "array<string>"
	VariableTypeArrayBoolean VariableType = "array<boolean>"
	VariableTypeArrayInteger VariableType = "array<integer>"
	VariableTypeArrayFloat   VariableType = "array<float>"
	VariableTypeArrayObject  VariableType = "array<object>"
	VariableTypeMultiPart    VariableType = "multi_part"
)

type VariableVal added in v0.1.12

type VariableVal struct {
	Key                 string         `json:"key"`
	Value               *string        `json:"value,omitempty"`
	PlaceholderMessages []*Message     `json:"placeholder_messages,omitempty"`
	MultiPartValues     []*ContentPart `json:"multi_part_values,omitempty"`
}

Jump to

Keyboard shortcuts

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