Files
dstalk/docs/tutorial/quick-start.md
XiuChengWu ba7382db2a feat: add OpenAI-compatible AI provider plugin with SSE streaming support
- Implemented the OpenAI-compatible AI provider plugin, including configuration, chat, and chat_stream functionalities.
- Added support for SSE streaming and tool calls.
- Integrated Boost.JSON for JSON handling.
- Created CMake configuration for the plugin.
- Added error handling and logging throughout the plugin.
2026-05-31 05:37:04 +08:00

141 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 快速入门
5 步上手 dstalk, 从安装工具链到完成第一个 AI 对话。
---
## 1. 安装工具链
dstalk 需要 CMake、Ninja、LLVM/Clang 和 Conan2。`setup.bat` 全自动下载安装到 `tools/` 目录。
```bash
cd tools
setup.bat
```
> **前提**: 系统需已安装 Python 3.10+。
>
> 网络不畅时, 可手动下载放入对应目录:
> - [Ninja](https://github.com/ninja-build/ninja/releases) → `tools/ninja/ninja.exe`
> - [CMake](https://cmake.org/download/) → `tools/cmake/bin/cmake.exe`
> - [LLVM](https://github.com/llvm/llvm-project/releases) → `tools/llvm/bin/clang.exe`
> - Conan2 通过 pip 安装到 `tools/.venv/Scripts/conan.exe`
---
## 2. 编译
项目根目录提供 `build.bat`, 一键完成: Conan 拉取依赖 -> CMake 配置 -> Ninja 编译。
```bash
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。
```bash
# 在项目根目录手动创建 config.toml
```
**config.toml 示例:**
```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 开放平台](https://platform.openai.com/) 或 [Anthropic Console](https://console.anthropic.com/) 获取。
---
## 4. 运行 dstalk_cli
```bash
build/dstalk_cli/dstalk_cli.exe
```
启动后显示欢迎横幅:
```text
dstalk v0.1.0 | dstalk AI | /help 查看帮助 | /quit 退出
[gpt-4o] >
```
> 图形模式默认关闭。需要 SDL3 GUI 时, 用 `-DDSTALK_BUILD_GUI=ON` 重新配置 CMake。
---
## 5. 第一个对话
在提示符 `>` 后输入自然语言, 即可与 AI 对话。
```text
[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 命令速查表](../reference/commands.md) 了解全部命令
- 输入 `/help` 在 dstalk 内查看命令列表
- 输入 `/status` 查看当前运行状态