dify

package module
v1.0.1 Latest Latest
Warning

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

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

README

Dify Go SDK

基于 Go 语言实现的 Dify API 客户端 SDK,支持 Dify 1.11.2 版本。

功能特性

  • ✅ 对话型应用 (Chat)
  • ✅ 文本生成型应用 (Completion)
  • ✅ 工作流应用 (Workflow)
  • ✅ 文件上传
  • ✅ 流式响应支持
  • ✅ 语音转文字 / 文字转语音

安装

go get github.com/Angbro/dify-go

快速开始

对话型应用
package main

import (
    "context"
    "fmt"
    "log"

    dify "github.com/Angbro/dify-go"
)

func main() {
    client, err := dify.NewChatClient(dify.ClientConfig{
        APIKey:  "your-api-key",
        BaseURL: "http://127.0.0.1/v1",
    })
    if err != nil {
        log.Fatal(err)
    }

    // 阻塞模式
    resp, err := client.SendMessage(context.Background(), &dify.ChatRequest{
        Query: "你好",
        User:  "user-123",
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(resp.Answer)
}
文本生成型应用
client, err := dify.NewCompletionClient(dify.ClientConfig{
    APIKey:  "your-api-key",
    BaseURL: "http://127.0.0.1/v1",
})

resp, err := client.SendMessage(context.Background(), &dify.CompletionRequest{
    Inputs: map[string]interface{}{
        "query": "写一首诗",
    },
    User: "user-123",
})
fmt.Println(resp.Answer)
工作流应用
client, err := dify.NewWorkflowClient(dify.ClientConfig{
    APIKey:  "your-api-key",
    BaseURL: "http://127.0.0.1/v1",
})

resp, err := client.Run(context.Background(), &dify.WorkflowRequest{
    Inputs: map[string]interface{}{
        "input": "分析数据",
    },
    User: "user-123",
})
fmt.Println(resp.Data.Outputs)
流式响应
stream, err := client.SendMessageStream(ctx, &dify.ChatRequest{
    Query: "讲个故事",
    User:  "user-123",
})
defer stream.Close()

for {
    event, err := stream.Read()
    if err == io.EOF {
        break
    }
    if event.Event == "message" {
        var msg dify.MessageStreamEvent
        json.Unmarshal([]byte(event.Data), &msg)
        fmt.Print(msg.Answer)
    }
}

API 参考

ChatClient (对话型应用)
方法 描述
SendMessage 发送消息(阻塞模式)
SendMessageStream 发送消息(流式模式)
StopMessage 停止响应
MessageFeedback 消息反馈
GetSuggestedQuestions 获取建议问题
GetMessages 获取会话历史
GetConversations 获取会话列表
DeleteConversation 删除会话
RenameConversation 重命名会话
GetParameters 获取应用参数
GetMeta 获取应用元信息
CompletionClient (文本生成型应用)
方法 描述
SendMessage 发送消息(阻塞模式)
SendMessageStream 发送消息(流式模式)
StopMessage 停止响应
MessageFeedback 消息反馈
GetParameters 获取应用参数
GetMeta 获取应用元信息
WorkflowClient (工作流应用)
方法 描述
Run 执行工作流(阻塞模式)
RunStream 执行工作流(流式模式)
Stop 停止工作流
GetRunStatus 获取执行状态
GetParameters 获取应用参数
GetMeta 获取应用元信息
通用方法 (Client)
方法 描述
UploadFile 上传文件
UploadFileFromReader 从 Reader 上传文件
TextToAudio 文字转语音
AudioToText 语音转文字

配置选项

type ClientConfig struct {
    APIKey  string        // Dify API Key (必填)
    BaseURL string        // Dify API 地址 (必填)
    Timeout time.Duration // 请求超时时间 (默认 120s)
    SkipTLS bool          // 跳过 TLS 验证
}

流式事件类型

事件 描述
message 消息内容
message_end 消息结束
message_file 文件消息
tts_message TTS 音频
tts_message_end TTS 结束
workflow_started 工作流开始
node_started 节点开始
node_finished 节点完成
workflow_finished 工作流完成
text_chunk 文本块
error 错误
ping 心跳

License

MIT License

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 120 * time.Second
	DefaultUser    = "dify-go-sdk"
)
View Source
const (
	ErrCodeNoAPIKey                 = "no_api_key"
	ErrCodeInvalidAPIKey            = "invalid_api_key"
	ErrCodeAppUnavailable           = "app_unavailable"
	ErrCodeProviderNotInitialize    = "provider_not_initialize"
	ErrCodeProviderQuotaExceeded    = "provider_quota_exceeded"
	ErrCodeModelCurrentlyNotSupport = "model_currently_not_support"
	ErrCodeCompletionRequestError   = "completion_request_error"
	ErrCodeNotFound                 = "not_found"
	ErrCodeNotChatApp               = "not_chat_app"
	ErrCodeNotCompletionApp         = "not_completion_app"
	ErrCodeConversationCompleted    = "conversation_completed"
	ErrCodeFileNotFound             = "file_not_found"
	ErrCodeFileTooLarge             = "file_too_large"
	ErrCodeUnsupportedFileType      = "unsupported_file_type"
	ErrCodeS3ConnectionFailed       = "s3_connection_failed"
	ErrCodeS3PermissionDenied       = "s3_permission_denied"
	ErrCodeS3FileTooLarge           = "s3_file_too_large"
)

常见错误码

Variables

This section is empty.

Functions

func ParseAPIError

func ParseAPIError(statusCode int, body []byte) error

ParseAPIError 解析 API 错误响应

Types

type APIError

type APIError struct {
	StatusCode int    `json:"-"`
	Code       string `json:"code"`
	Message    string `json:"message"`
	Status     int    `json:"status"`
}

APIError Dify API 错误

func (*APIError) Error

func (e *APIError) Error() string

type AnnotationConfig

type AnnotationConfig struct {
	Enabled bool `json:"enabled"`
}

AnnotationConfig 标注回复配置

type AppMetaResponse

type AppMetaResponse struct {
	ToolIcons map[string]interface{} `json:"tool_icons"`
}

AppMetaResponse 应用元信息响应

type AppParametersResponse

type AppParametersResponse struct {
	OpeningStatement              string              `json:"opening_statement"`
	SuggestedQuestions            []string            `json:"suggested_questions"`
	SuggestedQuestionsAfterAnswer SuggestedQAConfig   `json:"suggested_questions_after_answer"`
	SpeechToText                  SpeechToTextConfig  `json:"speech_to_text"`
	TextToSpeech                  TextToSpeechConfig  `json:"text_to_speech"`
	RetrieverResource             RetrieverConfig     `json:"retriever_resource"`
	AnnotationReply               AnnotationConfig    `json:"annotation_reply"`
	UserInputForm                 []UserInputFormItem `json:"user_input_form"`
	FileUpload                    FileUploadConfig    `json:"file_upload"`
	SystemParameters              SystemParamsConfig  `json:"system_parameters"`
}

AppParametersResponse 应用参数响应

type AudioToTextResponse

type AudioToTextResponse struct {
	Text string `json:"text"`
}

AudioToTextResponse 语音转文字响应

type ChatClient

type ChatClient struct {
	*Client
}

ChatClient 对话型应用客户端

func NewChatClient

func NewChatClient(config ClientConfig) (*ChatClient, error)

NewChatClient 创建对话型应用客户端

func (*ChatClient) DeleteConversation

func (c *ChatClient) DeleteConversation(ctx context.Context, conversationID string, user string) error

DeleteConversation 删除会话

func (*ChatClient) GetConversations

func (c *ChatClient) GetConversations(ctx context.Context, user string, lastID string, limit int, pinned *bool) (*ConversationListResponse, error)

GetConversations 获取会话列表

func (*ChatClient) GetMessages

func (c *ChatClient) GetMessages(ctx context.Context, conversationID string, user string, firstID string, limit int) (*MessageListResponse, error)

GetMessages 获取会话历史消息

func (*ChatClient) GetMeta

func (c *ChatClient) GetMeta(ctx context.Context, user string) (*AppMetaResponse, error)

GetMeta 获取应用元信息

func (*ChatClient) GetParameters

func (c *ChatClient) GetParameters(ctx context.Context, user string) (*AppParametersResponse, error)

GetParameters 获取应用参数

func (*ChatClient) GetSuggestedQuestions

func (c *ChatClient) GetSuggestedQuestions(ctx context.Context, messageID string, user string) (*SuggestedResponse, error)

GetSuggestedQuestions 获取下一轮建议问题

func (*ChatClient) MessageFeedback

func (c *ChatClient) MessageFeedback(ctx context.Context, messageID string, req *FeedbackRequest) (*FeedbackResponse, error)

MessageFeedback 消息反馈

func (*ChatClient) RenameConversation

func (c *ChatClient) RenameConversation(ctx context.Context, conversationID string, req *RenameRequest) (*RenameResponse, error)

RenameConversation 重命名会话

func (*ChatClient) SendMessage

func (c *ChatClient) SendMessage(ctx context.Context, req *ChatRequest) (*ChatResponse, error)

SendMessage 发送对话消息 (阻塞模式)

func (*ChatClient) SendMessageStream

func (c *ChatClient) SendMessageStream(ctx context.Context, req *ChatRequest) (*StreamReader, error)

SendMessageStream 发送对话消息 (流式模式)

func (*ChatClient) StopMessage

func (c *ChatClient) StopMessage(ctx context.Context, taskID string, user string) (*StopResponse, error)

StopMessage 停止响应

type ChatRequest

type ChatRequest struct {
	Query            string                 `json:"query"`
	Inputs           map[string]interface{} `json:"inputs,omitempty"`
	ResponseMode     string                 `json:"response_mode"`
	User             string                 `json:"user"`
	ConversationID   string                 `json:"conversation_id,omitempty"`
	Files            []FileInput            `json:"files,omitempty"`
	AutoGenerateName bool                   `json:"auto_generate_name,omitempty"`
}

ChatRequest 对话消息请求

type ChatResponse

type ChatResponse struct {
	MessageID      string   `json:"message_id"`
	ConversationID string   `json:"conversation_id"`
	Mode           string   `json:"mode"`
	Answer         string   `json:"answer"`
	Metadata       Metadata `json:"metadata"`
	CreatedAt      int64    `json:"created_at"`
}

ChatResponse 对话消息响应 (blocking 模式)

type Client

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

Client Dify API 客户端

func NewClient

func NewClient(config ClientConfig) (*Client, error)

NewClient 创建新的 Dify 客户端

func (*Client) AudioToText

func (c *Client) AudioToText(ctx context.Context, audioFilePath string, user string) (*AudioToTextResponse, error)

AudioToText 语音转文字

func (*Client) TextToAudio

func (c *Client) TextToAudio(ctx context.Context, text string, user string, streaming bool) (io.ReadCloser, error)

TextToAudio 文字转语音

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, filePath string, user string) (*FileUploadResponse, error)

UploadFile 上传文件

func (*Client) UploadFileFromReader

func (c *Client) UploadFileFromReader(ctx context.Context, reader io.Reader, filename string, user string) (*FileUploadResponse, error)

UploadFileFromReader 从 Reader 上传文件

type ClientConfig

type ClientConfig struct {
	APIKey  string
	BaseURL string
	Timeout time.Duration
	SkipTLS bool
}

ClientConfig 客户端配置

type CompletionClient

type CompletionClient struct {
	*Client
}

CompletionClient 文本生成型应用客户端

func NewCompletionClient

func NewCompletionClient(config ClientConfig) (*CompletionClient, error)

NewCompletionClient 创建文本生成型应用客户端

func (*CompletionClient) GetMeta

func (c *CompletionClient) GetMeta(ctx context.Context, user string) (*AppMetaResponse, error)

GetMeta 获取应用元信息

func (*CompletionClient) GetParameters

func (c *CompletionClient) GetParameters(ctx context.Context, user string) (*AppParametersResponse, error)

GetParameters 获取应用参数

func (*CompletionClient) MessageFeedback

func (c *CompletionClient) MessageFeedback(ctx context.Context, messageID string, req *FeedbackRequest) (*FeedbackResponse, error)

MessageFeedback 消息反馈

func (*CompletionClient) SendMessage

SendMessage 发送文本生成请求 (阻塞模式)

func (*CompletionClient) SendMessageStream

func (c *CompletionClient) SendMessageStream(ctx context.Context, req *CompletionRequest) (*StreamReader, error)

SendMessageStream 发送文本生成请求 (流式模式)

func (*CompletionClient) StopMessage

func (c *CompletionClient) StopMessage(ctx context.Context, taskID string, user string) (*StopResponse, error)

StopMessage 停止响应

type CompletionRequest

type CompletionRequest struct {
	Inputs       map[string]interface{} `json:"inputs"`
	ResponseMode string                 `json:"response_mode"`
	User         string                 `json:"user"`
	Files        []FileInput            `json:"files,omitempty"`
}

CompletionRequest 文本生成请求

type CompletionResponse

type CompletionResponse struct {
	MessageID string   `json:"message_id"`
	Mode      string   `json:"mode"`
	Answer    string   `json:"answer"`
	Metadata  Metadata `json:"metadata"`
	CreatedAt int64    `json:"created_at"`
}

CompletionResponse 文本生成响应 (blocking 模式)

type Conversation

type Conversation struct {
	ID        string                 `json:"id"`
	Name      string                 `json:"name"`
	Inputs    map[string]interface{} `json:"inputs"`
	Status    string                 `json:"status"`
	CreatedAt int64                  `json:"created_at"`
	UpdatedAt int64                  `json:"updated_at"`
}

Conversation 会话信息

type ConversationListResponse

type ConversationListResponse struct {
	Data    []Conversation `json:"data"`
	HasMore bool           `json:"has_more"`
	Limit   int            `json:"limit"`
}

ConversationListResponse 会话列表响应

type ErrorStreamEvent

type ErrorStreamEvent struct {
	Event     string `json:"event"`
	TaskID    string `json:"task_id"`
	MessageID string `json:"message_id,omitempty"`
	Status    int    `json:"status"`
	Code      string `json:"code"`
	Message   string `json:"message"`
}

ErrorStreamEvent 错误流事件

type Feedback

type Feedback struct {
	Rating string `json:"rating"`
}

Feedback 反馈信息

type FeedbackRequest

type FeedbackRequest struct {
	Rating string `json:"rating"`
	User   string `json:"user"`
}

FeedbackRequest 反馈请求

type FeedbackResponse

type FeedbackResponse struct {
	Result string `json:"result"`
}

FeedbackResponse 反馈响应

type FileInput

type FileInput struct {
	Type           string `json:"type"`
	TransferMethod string `json:"transfer_method"`
	URL            string `json:"url,omitempty"`
	UploadFileID   string `json:"upload_file_id,omitempty"`
}

FileInput 文件输入

type FileUploadConfig

type FileUploadConfig struct {
	Image ImageUploadConfig `json:"image"`
}

FileUploadConfig 文件上传配置

type FileUploadResponse

type FileUploadResponse struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Size      int64  `json:"size"`
	Extension string `json:"extension"`
	MimeType  string `json:"mime_type"`
	CreatedBy string `json:"created_by"`
	CreatedAt int64  `json:"created_at"`
}

FileUploadResponse 文件上传响应

type FormItemConfig

type FormItemConfig struct {
	Label     string   `json:"label"`
	Variable  string   `json:"variable"`
	Required  bool     `json:"required"`
	Default   string   `json:"default"`
	MaxLength int      `json:"max_length,omitempty"`
	Options   []string `json:"options,omitempty"`
}

FormItemConfig 表单项配置

type ImageUploadConfig

type ImageUploadConfig struct {
	Enabled         bool     `json:"enabled"`
	NumberLimits    int      `json:"number_limits"`
	TransferMethods []string `json:"transfer_methods"`
}

ImageUploadConfig 图片上传配置

type Message

type Message struct {
	ID                 string                 `json:"id"`
	ConversationID     string                 `json:"conversation_id"`
	Inputs             map[string]interface{} `json:"inputs"`
	Query              string                 `json:"query"`
	Answer             string                 `json:"answer"`
	MessageFiles       []MessageFile          `json:"message_files"`
	Feedback           *Feedback              `json:"feedback"`
	RetrieverResources []RetrieverResource    `json:"retriever_resources"`
	CreatedAt          int64                  `json:"created_at"`
}

Message 消息信息

type MessageEndStreamEvent

type MessageEndStreamEvent struct {
	Event          string   `json:"event"`
	TaskID         string   `json:"task_id"`
	MessageID      string   `json:"message_id"`
	ConversationID string   `json:"conversation_id,omitempty"`
	Metadata       Metadata `json:"metadata"`
}

MessageEndStreamEvent 消息结束流事件

type MessageFile

type MessageFile struct {
	ID        string `json:"id"`
	Type      string `json:"type"`
	URL       string `json:"url"`
	BelongsTo string `json:"belongs_to"`
}

MessageFile 消息文件

type MessageListResponse

type MessageListResponse struct {
	Data    []Message `json:"data"`
	HasMore bool      `json:"has_more"`
	Limit   int       `json:"limit"`
}

MessageListResponse 消息列表响应

type MessageStreamEvent

type MessageStreamEvent struct {
	Event          string `json:"event"`
	TaskID         string `json:"task_id"`
	MessageID      string `json:"message_id"`
	ConversationID string `json:"conversation_id,omitempty"`
	Answer         string `json:"answer"`
	CreatedAt      int64  `json:"created_at"`
}

MessageStreamEvent 消息流事件

type Metadata

type Metadata struct {
	Usage              Usage               `json:"usage"`
	RetrieverResources []RetrieverResource `json:"retriever_resources,omitempty"`
}

Metadata 响应元数据

type NodeFinishedData

type NodeFinishedData struct {
	ID                string                 `json:"id"`
	NodeID            string                 `json:"node_id"`
	NodeType          string                 `json:"node_type"`
	Title             string                 `json:"title"`
	Index             int                    `json:"index"`
	PredecessorNodeID string                 `json:"predecessor_node_id"`
	Inputs            map[string]interface{} `json:"inputs"`
	ProcessData       map[string]interface{} `json:"process_data"`
	Outputs           map[string]interface{} `json:"outputs"`
	Status            string                 `json:"status"`
	Error             string                 `json:"error,omitempty"`
	ElapsedTime       float64                `json:"elapsed_time"`
	ExecutionMetadata map[string]interface{} `json:"execution_metadata"`
	CreatedAt         int64                  `json:"created_at"`
}

NodeFinishedData 节点完成数据

type NodeFinishedEvent

type NodeFinishedEvent struct {
	Event         string           `json:"event"`
	TaskID        string           `json:"task_id"`
	WorkflowRunID string           `json:"workflow_run_id"`
	Data          NodeFinishedData `json:"data"`
}

NodeFinishedEvent 节点完成事件

type NodeStartedData

type NodeStartedData struct {
	ID                string                 `json:"id"`
	NodeID            string                 `json:"node_id"`
	NodeType          string                 `json:"node_type"`
	Title             string                 `json:"title"`
	Index             int                    `json:"index"`
	PredecessorNodeID string                 `json:"predecessor_node_id"`
	Inputs            map[string]interface{} `json:"inputs"`
	CreatedAt         int64                  `json:"created_at"`
}

NodeStartedData 节点开始数据

type NodeStartedEvent

type NodeStartedEvent struct {
	Event         string          `json:"event"`
	TaskID        string          `json:"task_id"`
	WorkflowRunID string          `json:"workflow_run_id"`
	Data          NodeStartedData `json:"data"`
}

NodeStartedEvent 节点开始事件

type RenameRequest

type RenameRequest struct {
	Name         string `json:"name,omitempty"`
	AutoGenerate bool   `json:"auto_generate,omitempty"`
	User         string `json:"user"`
}

RenameRequest 重命名请求

type RenameResponse

type RenameResponse struct {
	ID        string                 `json:"id"`
	Name      string                 `json:"name"`
	Inputs    map[string]interface{} `json:"inputs"`
	Status    string                 `json:"status"`
	CreatedAt int64                  `json:"created_at"`
	UpdatedAt int64                  `json:"updated_at"`
}

RenameResponse 重命名响应

type RetrieverConfig

type RetrieverConfig struct {
	Enabled bool `json:"enabled"`
}

RetrieverConfig 知识库配置

type RetrieverResource

type RetrieverResource struct {
	Position     int     `json:"position"`
	DatasetID    string  `json:"dataset_id"`
	DatasetName  string  `json:"dataset_name"`
	DocumentID   string  `json:"document_id"`
	DocumentName string  `json:"document_name"`
	SegmentID    string  `json:"segment_id"`
	Score        float64 `json:"score"`
	Content      string  `json:"content"`
}

RetrieverResource 表示知识库引用资源

type SSEMessage

type SSEMessage struct {
	Event string
	Data  string
}

SSEMessage SSE 消息

type SSEReader

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

SSEReader SSE 事件读取器

func NewSSEReader

func NewSSEReader(reader io.Reader) *SSEReader

NewSSEReader 创建 SSE 读取器

func (*SSEReader) Read

func (r *SSEReader) Read() (*SSEMessage, error)

Read 读取下一个 SSE 事件

type SpeechToTextConfig

type SpeechToTextConfig struct {
	Enabled bool `json:"enabled"`
}

SpeechToTextConfig 语音转文字配置

type StopRequest

type StopRequest struct {
	User string `json:"user"`
}

StopRequest 停止响应请求

type StopResponse

type StopResponse struct {
	Result string `json:"result"`
}

StopResponse 停止响应

type StreamEvent

type StreamEvent struct {
	Event string `json:"event"`
}

StreamEvent 流式事件基础结构

type StreamReader

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

StreamReader 流式响应读取器

func NewStreamReader

func NewStreamReader(resp *http.Response) *StreamReader

NewStreamReader 创建流式读取器

func (*StreamReader) Close

func (sr *StreamReader) Close() error

Close 关闭流

func (*StreamReader) Read

func (sr *StreamReader) Read() (*SSEMessage, error)

Read 读取下一个事件

type SuggestedQAConfig

type SuggestedQAConfig struct {
	Enabled bool `json:"enabled"`
}

SuggestedQAConfig 建议问题配置

type SuggestedResponse

type SuggestedResponse struct {
	Result string   `json:"result"`
	Data   []string `json:"data"`
}

SuggestedResponse 建议问题响应

type SystemParamsConfig

type SystemParamsConfig struct {
	FileSizeLimit      int `json:"file_size_limit"`
	ImageFileSizeLimit int `json:"image_file_size_limit"`
	AudioFileSizeLimit int `json:"audio_file_size_limit"`
	VideoFileSizeLimit int `json:"video_file_size_limit"`
}

SystemParamsConfig 系统参数配置

type TextToSpeechConfig

type TextToSpeechConfig struct {
	Enabled  bool   `json:"enabled"`
	Voice    string `json:"voice"`
	Language string `json:"language"`
}

TextToSpeechConfig 文字转语音配置

type Usage

type Usage struct {
	PromptTokens        int     `json:"prompt_tokens"`
	PromptUnitPrice     string  `json:"prompt_unit_price"`
	PromptPriceUnit     string  `json:"prompt_price_unit"`
	PromptPrice         string  `json:"prompt_price"`
	CompletionTokens    int     `json:"completion_tokens"`
	CompletionUnitPrice string  `json:"completion_unit_price"`
	CompletionPriceUnit string  `json:"completion_price_unit"`
	CompletionPrice     string  `json:"completion_price"`
	TotalTokens         int     `json:"total_tokens"`
	TotalPrice          string  `json:"total_price"`
	Currency            string  `json:"currency"`
	Latency             float64 `json:"latency"`
}

Usage 表示 token 使用量

type UserInputFormItem

type UserInputFormItem map[string]FormItemConfig

UserInputFormItem 用户输入表单项

type WorkflowClient

type WorkflowClient struct {
	*Client
}

WorkflowClient 工作流应用客户端

func NewWorkflowClient

func NewWorkflowClient(config ClientConfig) (*WorkflowClient, error)

NewWorkflowClient 创建工作流应用客户端

func (*WorkflowClient) GetMeta

func (c *WorkflowClient) GetMeta(ctx context.Context, user string) (*AppMetaResponse, error)

GetMeta 获取应用元信息

func (*WorkflowClient) GetParameters

func (c *WorkflowClient) GetParameters(ctx context.Context, user string) (*AppParametersResponse, error)

GetParameters 获取应用参数

func (*WorkflowClient) GetRunStatus

func (c *WorkflowClient) GetRunStatus(ctx context.Context, workflowRunID string) (*WorkflowRunResponse, error)

GetRunStatus 获取工作流执行状态

func (*WorkflowClient) Run

Run 执行工作流 (阻塞模式)

func (*WorkflowClient) RunStream

func (c *WorkflowClient) RunStream(ctx context.Context, req *WorkflowRequest) (*StreamReader, error)

RunStream 执行工作流 (流式模式)

func (*WorkflowClient) Stop

func (c *WorkflowClient) Stop(ctx context.Context, taskID string, user string) (*StopResponse, error)

Stop 停止工作流

type WorkflowData

type WorkflowData struct {
	ID          string                 `json:"id"`
	WorkflowID  string                 `json:"workflow_id"`
	Status      string                 `json:"status"`
	Outputs     map[string]interface{} `json:"outputs"`
	Error       string                 `json:"error,omitempty"`
	ElapsedTime float64                `json:"elapsed_time"`
	TotalTokens int                    `json:"total_tokens"`
	TotalSteps  int                    `json:"total_steps"`
	CreatedAt   int64                  `json:"created_at"`
	FinishedAt  int64                  `json:"finished_at"`
}

WorkflowData 工作流数据

type WorkflowFinishedEvent

type WorkflowFinishedEvent struct {
	Event         string       `json:"event"`
	TaskID        string       `json:"task_id"`
	WorkflowRunID string       `json:"workflow_run_id"`
	Data          WorkflowData `json:"data"`
}

WorkflowFinishedEvent 工作流完成事件

type WorkflowRequest

type WorkflowRequest struct {
	Inputs       map[string]interface{} `json:"inputs"`
	ResponseMode string                 `json:"response_mode"`
	User         string                 `json:"user"`
	Files        []FileInput            `json:"files,omitempty"`
}

WorkflowRequest 工作流执行请求

type WorkflowResponse

type WorkflowResponse struct {
	WorkflowRunID string       `json:"workflow_run_id"`
	TaskID        string       `json:"task_id"`
	Data          WorkflowData `json:"data"`
}

WorkflowResponse 工作流执行响应 (blocking 模式)

type WorkflowRunResponse

type WorkflowRunResponse struct {
	ID          string                 `json:"id"`
	WorkflowID  string                 `json:"workflow_id"`
	Status      string                 `json:"status"`
	Inputs      map[string]interface{} `json:"inputs"`
	Outputs     map[string]interface{} `json:"outputs"`
	Error       string                 `json:"error,omitempty"`
	TotalSteps  int                    `json:"total_steps"`
	TotalTokens int                    `json:"total_tokens"`
	CreatedAt   int64                  `json:"created_at"`
	FinishedAt  int64                  `json:"finished_at"`
	ElapsedTime float64                `json:"elapsed_time"`
}

WorkflowRunResponse 工作流执行状态响应

type WorkflowStartedData

type WorkflowStartedData struct {
	ID          string `json:"id"`
	WorkflowID  string `json:"workflow_id"`
	SequenceNum int    `json:"sequence_number"`
	CreatedAt   int64  `json:"created_at"`
}

WorkflowStartedData 工作流开始数据

type WorkflowStartedEvent

type WorkflowStartedEvent struct {
	Event         string              `json:"event"`
	TaskID        string              `json:"task_id"`
	WorkflowRunID string              `json:"workflow_run_id"`
	Data          WorkflowStartedData `json:"data"`
}

WorkflowStartedEvent 工作流开始事件

Directories

Path Synopsis
examples
chat command
completion command
workflow command

Jump to

Keyboard shortcuts

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