GoWindGoWind
首页
框架
GoWind Toolkit
  • 开源项目

    • GoWind Admin(后台管理)
    • GoWind CMS(内容管理)
    • GoWind UBA(行为分析)
    • GoWind Shop(电商)
    • GoWind Kanban(协作看板)
    • GoWind Ledger(家庭记账)
    • GoWind ShortPlay(短剧社区)
    • GoWind Ops(运维平台)
    • RushWind(Rust 生态)
  • Open Core(社区开源 · 企业版增强)

    • GoWind OA(协同办公)
    • GoWind ERP(业财一体)
    • GoWind WMS(多货主仓储)
  • 商业产品

    • GoWind IM(即时通讯)
    • GoWind CRM(B2B 销售管理)
    • GoWind Trade(外贸全流程管理)
    • GoWind IoT(物联网)
    • GoWind Edu(AI 教育)
    • GoWind MES(制造执行)
    • GoWind CDC(数据管道)
    • GoWind SDP(零信任网关)
    • GoWind Quant(量化研究)
    • GoWind Trade Radar(外贸选品雷达)
    • GoWind Game Radar(游戏立项雷达)
  • 简体中文
  • English
GitHub
首页
框架
GoWind Toolkit
  • 开源项目

    • GoWind Admin(后台管理)
    • GoWind CMS(内容管理)
    • GoWind UBA(行为分析)
    • GoWind Shop(电商)
    • GoWind Kanban(协作看板)
    • GoWind Ledger(家庭记账)
    • GoWind ShortPlay(短剧社区)
    • GoWind Ops(运维平台)
    • RushWind(Rust 生态)
  • Open Core(社区开源 · 企业版增强)

    • GoWind OA(协同办公)
    • GoWind ERP(业财一体)
    • GoWind WMS(多货主仓储)
  • 商业产品

    • GoWind IM(即时通讯)
    • GoWind CRM(B2B 销售管理)
    • GoWind Trade(外贸全流程管理)
    • GoWind IoT(物联网)
    • GoWind Edu(AI 教育)
    • GoWind MES(制造执行)
    • GoWind CDC(数据管道)
    • GoWind SDP(零信任网关)
    • GoWind Quant(量化研究)
    • GoWind Trade Radar(外贸选品雷达)
    • GoWind Game Radar(游戏立项雷达)
  • 简体中文
  • English
GitHub
  • 介绍

    • GoWind 框架
    • 框架整体架构
  • go-wind 核心

    • go-wind 核心框架
    • App 生命周期管理
    • Context 传播
    • Transport 抽象
    • Log 门面接口
  • go-wind-plugins 插件

    • go-wind-plugins 插件总览
    • 插件配置系统
    • 插件注册机制(SPI)
    • 日志适配插件
    • 传输协议插件
    • 消息中间件插件
    • 编码解码插件
    • 安全与认证插件
    • 链路追踪插件
    • 缓存插件
    • 对象存储插件(OSS)
    • 限流插件
    • 指标监控插件
    • AI 插件
    • 工作流插件
    • 数据库与缓存插件
    • Bootstrap 集成与网关插件
    • 压缩与序列化插件
    • 模板渲染与验证插件
  • go-wind-bootstrap 启动器

    • go-wind-bootstrap 声明式启动器
    • Bootstrap 配置系统
    • Bootstrap SPI 机制
    • 声明式中间件编排
    • Bootstrap 命令行集成
    • Bootstrap 实战示例
  • go-wind-flow 流程引擎

    • GoWind Flow 流程引擎
  • 教程

    • 快速入门教程
    • 自定义插件开发教程
    • 多协议同时监听教程
    • 框架迁移指南

AI 插件

go-wind-plugins 提供 AI 大模型集成,内置 OpenAI、LangChainGo、Eino 三个插件。每个 AI 子模块独立定义配置和客户端,返回各 SDK 的原生类型,支持云端模型与本地模型(如 Ollama)。

一、插件列表

插件导入路径框架
OpenAIplugins/ai/openaisashabaranov/go-openai
LangChainGoplugins/ai/langchaingotmc/langchaingo
Einoplugins/ai/einocloudwego/eino

二、OpenAI

import "github.com/tx7do/go-wind-plugins/ai/openai"

client, _ := openai.NewClient(&openai.Config{
    Type:           openai.ModelTypeCloud,        // ModelTypeLocal | ModelTypeCloud
    ModelName:      "gpt-4",
    TimeoutSeconds: 30,
    Cloud: &openai.CloudConfig{
        ApiKey:  "sk-xxx",
        BaseUrl: "https://api.openai.com/v1",
    },
})
// 返回原生 *openai.Client(sashabaranov/go-openai)

对话

resp, err := client.CreateChatCompletion(ctx, openai.ChatCompletionRequest{
    Model: "gpt-4",
    Messages: []openai.ChatCompletionMessage{
        {Role: "system", Content: "You are a helpful assistant."},
        {Role: "user", Content: "Explain Go interfaces in one sentence."},
    },
    Temperature: 0.7,
    MaxTokens:   200,
})
fmt.Println(resp.Choices[0].Message.Content)

流式对话

stream, _ := client.CreateChatCompletionStream(ctx, req)
defer stream.Close()

for {
    chunk, err := stream.Recv()
    if err != nil {
        break
    }
    fmt.Print(chunk.Choices[0].Delta.Content)
}

YAML 配置

ai:
  openai:
    api_key: ${OPENAI_API_KEY}
    model: gpt-4
    base_url: "https://api.openai.com/v1"
    timeout: 30s
    max_retries: 3

三、LangChainGo

NewModel 按 Config 创建 llms.Model,另提供 Chain / Agent / Memory / Embedding / VectorStore 辅助函数:

import "github.com/tx7do/go-wind-plugins/ai/langchaingo"

llm, err := langchaingo.NewModel(&langchaingo.Config{
    Type:           langchaingo.ModelTypeCloud,
    ModelName:      "gpt-4o",
    TimeoutSeconds: 60,
    Cloud: &langchaingo.CloudConfig{
        ApiKey:  "sk-xxx",
        BaseUrl: "https://api.openai.com/v1",
    },
    // Local: &langchaingo.LocalConfig{ ... },  // 本地模型(如 Ollama)
})

resp, err := llm.Call(context.Background(),
    "Explain microservices in one sentence",
)

// 链式编排
chain := langchaingo.NewLLMChain(llm, prompt)
result, _ := chains.Call(context.Background(), chain, map[string]any{"text": "..."})

// Agent
agent := langchaingo.NewOneShotAgent(llm, agentTools)
executor := langchaingo.NewExecutor(agent)

选项支持透传底层 SDK:WithOpenaiOptions / WithOllamaOptions / WithHTTPClient。

YAML 配置

ai:
  langchaingo:
    type: cloud            # local | cloud
    model: gpt-4o
    cloud:
      api_key: ${OPENAI_API_KEY}
      base_url: "https://api.openai.com/v1"

四、Eino

NewChatModel 创建 CloudWeGo Eino 的 model.ChatModel,并提供 Chain/Graph/Workflow 编排与 Tool 节点辅助函数:

import "github.com/tx7do/go-wind-plugins/ai/eino"

chatModel, _ := eino.NewChatModel(ctx, &eino.Config{
    ModelName: "gpt-4o",
}, eino.WithConfigModifier(func(cfg *einoOpenai.ChatModelConfig) {
    // cfg 为 eino openai 实现的原生 ChatModelConfig,可自由调整
    cfg.Temperature = &temp
}))

// 编排
chain := eino.NewChain[Input, Output]()
graph := eino.NewGraph[Input, Output]()

// Tool 节点
toolNode, _ := eino.NewToolNode(ctx, &compose.ToolsNodeConfig{})

YAML 配置

ai:
  eino:
    model: gpt-4o
    api_key: ${OPENAI_API_KEY}
    base_url: "https://api.openai.com/v1"

五、多模型路由

插件层不设共享 Client 接口(各 SDK 类型互不兼容);需要路由时,在业务侧用一个最小接口包装各原生客户端:

type ChatClient interface {
    Chat(ctx context.Context, prompt string) (string, error)
}

type ModelRouter struct {
    cloud ChatClient   // langchaingo / openai
    local ChatClient   // 本地模型(Ollama,经 langchaingo ModelTypeLocal)
}

func (r *ModelRouter) Chat(ctx context.Context, prompt string) (string, error) {
    if isSensitive(prompt) {
        return r.local.Chat(ctx, prompt)   // 隐私数据走本地模型
    }
    return r.cloud.Chat(ctx, prompt)
}

相关文档

  • 插件配置系统
  • 插件总览
  • 工作流插件
Edit this page
最近更新:: 2026/11/3 12:42
Contributors: Bobo
Prev
指标监控插件
Next
工作流插件