mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2025-12-06 13:54:41 +08:00
* improve(interface): replace with interface * feat(mcp): 添加构建器模式支持 新增功能: - RequestBuilder 构建器,支持流式 API - 多轮对话支持(AddAssistantMessage) - Function Calling / Tools 支持 - 精细参数控制(temperature, top_p, penalties 等) - 3个预设场景(Chat, CodeGen, CreativeWriting) - 完整的测试套件(19个新测试) 修复问题: - Config 字段未使用(MaxRetries、Temperature 等) - DeepSeek/Qwen SetAPIKey 的冗余 nil 检查 向后兼容: - 保留 CallWithMessages API - 新增 CallWithRequest API 测试: - 81 个测试全部通过 - 覆盖率 80.6% 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: tinkle-community <tinklefund@gmail.com> --------- Co-authored-by: zbhan <zbhan@freewheel.tv> Co-authored-by: tinkle-community <tinklefund@gmail.com>
31 lines
983 B
Go
31 lines
983 B
Go
package mcp
|
||
|
||
import (
|
||
"net/http"
|
||
"time"
|
||
)
|
||
|
||
// AIClient AI客户端公开接口(给外部使用)
|
||
type AIClient interface {
|
||
SetAPIKey(apiKey string, customURL string, customModel string)
|
||
SetTimeout(timeout time.Duration)
|
||
CallWithMessages(systemPrompt, userPrompt string) (string, error)
|
||
CallWithRequest(req *Request) (string, error) // 构建器模式 API(支持高级功能)
|
||
}
|
||
|
||
// clientHooks 内部钩子接口(用于子类重写特定步骤)
|
||
// 这些方法只在包内部使用,实现动态分派
|
||
type clientHooks interface {
|
||
// 可被子类重写的钩子方法
|
||
|
||
call(systemPrompt, userPrompt string) (string, error)
|
||
|
||
buildMCPRequestBody(systemPrompt, userPrompt string) map[string]any
|
||
buildUrl() string
|
||
buildRequest(url string, jsonData []byte) (*http.Request, error)
|
||
setAuthHeader(reqHeaders http.Header)
|
||
marshalRequestBody(requestBody map[string]any) ([]byte, error)
|
||
parseMCPResponse(body []byte) (string, error)
|
||
isRetryableError(err error) bool
|
||
}
|