Files
dstalk/docs/tutorial/quick-start.md
XiuChengWu f6cb51b40a Add unit tests for OpenAI plugin and establish coding standards
- Introduced comprehensive unit tests for the OpenAI plugin, covering SSE parsing, sentinel matching, delta extraction, request building, and more.
- Created a new markdown file detailing coding and naming conventions for the dstalk project, including guidelines for comments, naming rules, code organization, and memory management practices.
2026-05-31 00:51:59 +08:00

3.3 KiB
Raw Blame History

快速入门

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


1. 安装工具链

dstalk 需要 CMake、Ninja、LLVM/Clang 和 Conan2。setup.bat 全自动下载安装到 tools/ 目录。

cd tools
setup.bat

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

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

  • Ninjatools/ninja/ninja.exe
  • CMaketools/cmake/bin/cmake.exe
  • LLVMtools/llvm/bin/clang.exe
  • Conan2 通过 pip 安装到 tools/.venv/Scripts/conan.exe

2. 编译

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

build.bat

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

  • build/dstalk-core/dstalk.dll —— 核心 DLL
  • build/dstalk-cli/dstalk-cli.exe —— 命令行前端
  • build/plugins/*.dll —— 功能插件

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 获取。


4. 运行 dstalk-cli

build/dstalk-cli/dstalk-cli.exe

启动后显示欢迎横幅:

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 命令速查表 了解全部命令
  • 输入 /help 在 dstalk 内查看命令列表
  • 输入 /status 查看当前运行状态