Files
dstalk/docs/tutorial/quick-start.md
XiuChengWu 4745ce1f1c
Some checks failed
CI / Determine matrix (push) Has been cancelled
CI / Sanitizer (ASan+UBSan) / ubuntu-24.04 (push) Has been cancelled
CI / Coverage (gcovr) / ubuntu-24.04 (push) Has been cancelled
CI / ${{ matrix.os }} / ${{ matrix.build_type }} (push) Has been cancelled
feat: add AI endpoint manager plugin with configuration and routing capabilities
- Introduced `ai_endpoint_mgr` plugin to manage multiple AI provider endpoints.
- Added configuration reference documentation for `config.toml`.
- Implemented endpoint loading, active endpoint switching, and model mutation.
- Included error handling for missing endpoints and configuration failures.
- Developed unit tests covering various scenarios including error paths and concurrency.
2026-06-03 21:07:25 +08:00

4.3 KiB
Raw Blame History

快速入门

5 步上手 dstalk, 从安装工具链到完成第一个 AI 对话。


1. 安装工具链

dstalk 需要 CMake、Ninja、LLVM/Clang 和 Conan2。tools/ 下的脚本全自动安装。

Windows:

cd tools
setup.bat

Mac:

# 方式 A: 手动安装后运行脚本
brew install cmake ninja
cd tools && bash setup.sh

# 方式 B: 脚本全自动 (推荐)
cd tools && bash setup.sh

Linux (Ubuntu/Debian):

# 方式 A: 手动安装后运行脚本
sudo apt install cmake ninja-build
cd tools && bash setup.sh

# 方式 B: 脚本全自动 (推荐)
cd tools && bash setup.sh

前提: 系统需已安装 Python 3.10+。

网络不畅时, 可手动下载放入对应目录:

  • Ninjatools/ninja/ninja (或 ninja.exe)
  • CMaketools/cmake/bin/cmake (或 cmake.exe)
  • LLVMtools/llvm/bin/clang (或 clang.exe)
  • Conan2 通过 pip 安装到 tools/.venv/Scripts/conan.exe (Win) 或 tools/.venv/bin/conan (Mac/Linux)

2. 编译

项目根目录提供 build.bat (Windows) / build.sh (Mac/Linux), 一键完成: Conan 拉取依赖 -> CMake 配置 -> Ninja 编译。

Windows:

build.bat

Mac / Linux:

bash build.sh

编译产物输出到 build/ 目录:

产物 Windows Mac Linux
核心 DLL build/bin/dstalk.dll build/bin/libdstalk.dylib build/bin/libdstalk.so
CLI 前端 build/bin/dstalk_cli.exe build/bin/dstalk_cli build/bin/dstalk_cli
功能插件 build/plugins/*.dll build/plugins/*.dylib build/plugins/*.so

3. 创建 config.toml

在项目根目录创建 config.toml, 配置 AI 后端和 API Key。

# 在项目根目录手动创建 config.toml

config.toml 示例:

# 选择 AI 后端插件: ai_openai 或 ai_anthropic
ai.provider = "ai_openai"

# OpenAI-compatible
api.base_url = "https://api.openai.com/v1"
api.api_key = "sk-xxxxxxxx"
api.model = "gpt-4o"

# Anthropic Claude (切换 ai.provider 为 "ai_anthropic" 即可)
# api.base_url = "https://api.anthropic.com/v1"
# api.api_key = "sk-ant-xxxxxxxx"
# api.model = "claude-opus-4-20250514"

关键: 修改 ai.provider 字段即可在不同后端间切换, 无需改动代码。

API Key 可从 OpenAI-compatible 开放平台Anthropic Console 获取。

多 Endpoint 配置 (同时使用多个 AI 后端并在运行时通过 /endpoint 切换): 参见 配置参考 和项目根目录 config.example.toml


4. 运行 dstalk_cli

Windows:

build\bin\dstalk_cli.exe

Mac / Linux:

build/bin/dstalk_cli

启动后显示欢迎横幅:

dstalk v0.1.0  |  dstalk AI  |  /help 查看帮助  |  /quit 退出

[gpt-4o] >

图形模式默认关闭。需要 SDL3 GUI 时, 用 -DDSTALK_BUILD_GUI=ON 重新配置 CMake。


5. 第一个对话

在提示符 > 后输入自然语言, 即可与 AI 对话。

[gpt-4o] > 帮我写一个读取 CSV 并计算平均值的 C 程序

  [dstalk] 正在思考...

  #include <stdio.h>
  #include <stdlib.h>

  int main(int argc, char *argv[]) {
      if (argc < 2) {
          fprintf(stderr, "用法: %s <csv文件>\n", argv[0]);
          return 1;
      }
      FILE *fp = fopen(argv[1], "r");
      if (!fp) { perror("fopen"); return 1; }

      double sum = 0.0;
      int count = 0;
      char line[1024];
      while (fgets(line, sizeof(line), fp)) {
          sum += atof(line);
          count++;
      }
      fclose(fp);

      printf("平均值: %.2f (共 %d 行)\n", sum / count, count);
      return 0;
  }

  已写入 csv_avg.c。需要我帮你编译测试吗

[gpt-4o] > 把这段代码改成支持表头的

  [dstalk] 已更新 csv_avg.c——跳过第一行表头, 增加列选择功能。

[gpt-4o] > /file show csv_avg.c

  [dstalk] 已显示 csv_avg.c 内容。

下一步

  • 查看 CLI 命令速查表 了解全部命令
  • 查看 配置参考 了解 config.toml 所有字段
  • 输入 /help 在 dstalk 内查看命令列表
  • 输入 /status 查看当前运行状态