chore: 恢复旧布局基线(迁移改动丢失后重建,apps/packages 布局暂存)
This commit is contained in:
1 parent
a9510235bb
commit
456fa6954b
203 files changed
+18787
-48
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package ai
|
||||
|
||||
import "context"
|
||||
|
||||
// Message 对话消息(OpenAI 兼容协议)。
|
||||
type Message struct {
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// ChatReq 在 stub 时代字段上演进,前端契约不变;新增 schema/model 可选字段。
|
||||
type ChatReq struct {
|
||||
Action string `json:"action"`
|
||||
Prompt string `json:"prompt"`
|
||||
SQL string `json:"sql"`
|
||||
Driver string `json:"driver"`
|
||||
Database string `json:"database"`
|
||||
Error string `json:"error"`
|
||||
Schema string `json:"schema,omitempty"` // 前端注入的库表列上下文
|
||||
Model string `json:"model,omitempty"`
|
||||
}
|
||||
|
||||
type ChatRes struct {
|
||||
Content string `json:"content"`
|
||||
SQL string `json:"sql,omitempty"`
|
||||
}
|
||||
|
||||
// Provider AI 提供方抽象。本轮只做非流式 Complete;
|
||||
// Stream(ctx, req) (<-chan string, error) 预留,SSE 流式留待后续版本。
|
||||
type Provider interface {
|
||||
Name() string
|
||||
Complete(ctx context.Context, req ChatReq) (ChatRes, error)
|
||||
}
|
||||
|
||||
// Default 按当前配置选择 Provider;未配置 API Key 时回落 stub(离线占位)。
|
||||
func Default() Provider {
|
||||
cfg := LoadConfig()
|
||||
switch cfg.Provider {
|
||||
case "openai":
|
||||
if cfg.APIKey != "" {
|
||||
return NewOpenAIProvider(cfg)
|
||||
}
|
||||
}
|
||||
return stubProvider{}
|
||||
}
|
||||
Reference in new issue
Block a user