From 67ec5516e4ac5e0cc0310445dd1d3ac54161b81b Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 11 Nov 2025 17:46:45 +0800 Subject: [PATCH] Refactor assistant and context types for clarity and compatibility - Removed commented-out methods from the API interface in assistant types to enhance code cleanliness. - Introduced a new Response type in context types, ensuring compatibility with the OpenAI API. --- agent/assistant/agent.go | 13 +++++++++++++ agent/assistant/js/js.go | 3 +++ agent/assistant/types.go | 4 ---- agent/context/interfaces.go | 14 ++++++++++++++ agent/context/types.go | 4 ++++ 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 agent/assistant/agent.go create mode 100644 agent/assistant/js/js.go create mode 100644 agent/context/interfaces.go diff --git a/agent/assistant/agent.go b/agent/assistant/agent.go new file mode 100644 index 00000000..8ad10082 --- /dev/null +++ b/agent/assistant/agent.go @@ -0,0 +1,13 @@ +package assistant + +import "github.com/yaoapp/yao/agent/context" + +// Stream stream the agent +func (ast *Assistant) Stream(ctx context.Context, messages []context.Message, handler context.StreamFunc) error { + return nil +} + +// Run run the agent +func (ast *Assistant) Run(ctx context.Context, messages []context.Message) (*context.Response, error) { + return &context.Response{}, nil +} diff --git a/agent/assistant/js/js.go b/agent/assistant/js/js.go new file mode 100644 index 00000000..63ff0ccc --- /dev/null +++ b/agent/assistant/js/js.go @@ -0,0 +1,3 @@ +package js + +// JSAPI Register the JavaScript API diff --git a/agent/assistant/types.go b/agent/assistant/types.go index 3461a855..fc188482 100644 --- a/agent/assistant/types.go +++ b/agent/assistant/types.go @@ -20,10 +20,6 @@ const ( // API the assistant API interface type API interface { Chat(ctx context.Context, messages []message.Message, option map[string]interface{}, cb func(data []byte) int) error - // Upload(ctx context.Context, file *multipart.FileHeader, reader io.Reader, option map[string]interface{}) (*File, error) - // Download(ctx context.Context, fileID string) (*FileResponse, error) - // ReadBase64(ctx context.Context, fileID string) (string, error) - GetPlaceholder(locale string) *store.Placeholder Execute(c *gin.Context, ctx chatctx.Context, input interface{}, options map[string]interface{}, callback ...interface{}) (interface{}, error) Call(c *gin.Context, payload APIPayload) (interface{}, error) diff --git a/agent/context/interfaces.go b/agent/context/interfaces.go new file mode 100644 index 00000000..20683fbf --- /dev/null +++ b/agent/context/interfaces.go @@ -0,0 +1,14 @@ +package context + +// StreamFunc the streaming function +type StreamFunc func(data []byte) int + +// Agent the agent interface +type Agent interface { + + // Stream stream the agent + Stream(ctx Context, messages []Message, handler StreamFunc) error + + // Run run the agent + Run(ctx Context, messages []Message) (*Response, error) +} diff --git a/agent/context/types.go b/agent/context/types.go index 64023e99..d1737f5d 100644 --- a/agent/context/types.go +++ b/agent/context/types.go @@ -124,6 +124,10 @@ type Context struct { Silent bool `json:"silent,omitempty"` // Silent mode (Deprecated, use Referer instead) } +// Response the response +// 100% compatible with the OpenAI API +type Response struct{} + // Message Structure ( OpenAI Chat Completion Input Message Structure, https://platform.openai.com/docs/api-reference/chat/create#chat/create-messages ) // ===============================