更新若干功能
This commit is contained in:
24
service/ai/provider.go
Normal file
24
service/ai/provider.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Package ai 定义 AI 聊天 Provider 抽象与工厂:
|
||||
// 上层只依赖 Provider 接口,通过 New 按设置创建讯飞星火 Lite 或 DeepSeek 实例。
|
||||
package ai
|
||||
|
||||
import "context"
|
||||
|
||||
// Message 是一条对话消息(role: system | user | assistant)。
|
||||
type Message struct {
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// Chunk 是流式返回的一段增量内容;Err 非空表示流异常中止。
|
||||
type Chunk struct {
|
||||
Content string
|
||||
Err error
|
||||
}
|
||||
|
||||
// Provider 是 AI 服务商的统一抽象。
|
||||
type Provider interface {
|
||||
Name() string
|
||||
// ChatStream 发起流式对话,返回增量内容通道;通道关闭即流结束。
|
||||
ChatStream(ctx context.Context, messages []Message) (<-chan Chunk, error)
|
||||
}
|
||||
Reference in New Issue
Block a user