ai智能路由
Go to file
wolter 11241af84c Merge branch 'refs/heads/feature/session' into feature/dev 2025-09-18 14:52:43 +08:00
cmd/server 结构修改 2025-09-16 21:31:47 +08:00
config 结构修改 2025-09-16 21:31:47 +08:00
internal Merge branch 'refs/heads/feature/session' into feature/dev 2025-09-18 14:52:43 +08:00
tmpl 结构修改 2025-09-17 17:35:42 +08:00
utils 结构修改 2025-09-16 21:31:47 +08:00
.gitignore dev 2025-09-09 15:31:14 +08:00
Makefile 结构修改 2025-09-16 10:04:44 +08:00
README.md first commit 2025-09-08 16:00:12 +08:00
config.yaml 待定 2025-09-11 11:32:25 +08:00
gen.sh 结构修改 2025-09-16 21:31:47 +08:00
go.mod 结构修改 2025-09-17 17:35:42 +08:00
go.sum 结构修改 2025-09-17 17:35:42 +08:00

README.md

AI Scheduler - 智能路由调度系统

基于Go语言开发的智能AI助手支持Function Calling和工具调用可以智能路由用户请求到合适的工具进行处理。

功能特性

  • 🤖 智能对话: 基于Ollama的AI对话能力
  • 🔧 工具调用: 支持天气查询、计算器等工具
  • 🎯 智能路由: 自动判断是否需要调用工具
  • 📚 API文档: 集成Swagger文档
  • 高性能: 基于Gin框架的HTTP服务
  • 🏗️ 依赖注入: 使用Wire进行依赖管理

项目结构

ai_scheduler/
├── cmd/                    # 应用程序入口
│   └── main.go
├── internal/               # 内部包
│   ├── config/            # 配置管理
│   ├── handlers/          # HTTP处理器
│   ├── models/            # 数据模型
│   ├── services/          # 业务服务
│   ├── tools/             # 工具实现
│   └── wire/              # 依赖注入
├── pkg/                   # 公共包
│   ├── ollama/           # Ollama客户端
│   └── types/            # 类型定义
├── docs/                  # API文档
├── config.yaml           # 配置文件
└── go.mod                # Go模块

快速开始

1. 环境要求

  • Go 1.23+
  • Ollama服务运行中

2. 安装依赖

go mod tidy

3. 配置文件

编辑 config.yaml 文件确保Ollama服务地址正确

server:
  port: "8080"
  host: "localhost"

ollama:
  base_url: "http://localhost:11434"
  model: "llama2"
  timeout: 30s

tools:
  weather:
    enabled: true
    mock_data: true
  calculator:
    enabled: true
    mock_data: false

logging:
  level: "info"
  format: "json"

4. 启动服务

go run cmd/main.go

服务启动后,可以访问:

API使用示例

聊天接口

curl -X POST http://localhost:8080/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{
    "message": "北京今天天气怎么样?",
    "model": "llama2"
  }'

计算器示例

curl -X POST http://localhost:8080/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{
    "message": "计算 15 + 25 * 3",
    "model": "llama2"
  }'

支持的工具

1. 天气查询工具

  • 功能:查询指定城市的天气信息
  • 示例:"北京今天天气怎么样?"

2. 计算器工具

  • 功能:执行数学计算
  • 支持:加减乘除、幂运算
  • 示例:"计算 2 + 3 * 4"

开发说明

添加新工具

  1. internal/tools/ 目录下创建新工具文件
  2. 实现 types.Tool 接口
  3. tools.Manager 中注册新工具

配置管理

配置文件使用Viper加载支持环境变量覆盖。

依赖注入

使用Google Wire进行依赖注入修改依赖关系后需要重新生成代码。

许可证

MIT License