autocoder-rag-sdk
v0.0.7
Published
Node.js SDK for AutoCoder RAG - 便于在Node.js代码中调用auto-coder.rag run功能
Maintainers
Readme
AutoCoder RAG SDK for Node.js
一个便于在Node.js/TypeScript代码中调用auto-coder.rag run功能的SDK,用于文档问答和检索增强生成。
特性
- 🚀 易于使用: 提供简洁直观的API接口
- 🔄 异步优先: 基于Promise和AsyncGenerator的现代异步设计
- 📡 流式处理: 支持实时流式输出答案
- 🛠 完整配置: 支持所有auto-coder.rag run命令行选项
- 📦 TypeScript优先: 完整的类型定义和类型安全
安装
cd rag-sdks/nodejs
pnpm install
pnpm run build快速开始
基础用法
import { AutoCoderRAGClient } from 'autocoder-rag-sdk';
const client = new AutoCoderRAGClient('/path/to/docs');
const answer = await client.query('如何使用这个项目?');
console.log(answer);流式输出
import { AutoCoderRAGClient } from 'autocoder-rag-sdk';
const client = new AutoCoderRAGClient('/path/to/docs');
for await (const chunk of client.queryStream('这个项目的主要功能是什么?')) {
process.stdout.write(chunk);
}获取上下文
import { AutoCoderRAGClient } from 'autocoder-rag-sdk';
const client = new AutoCoderRAGClient('/path/to/docs');
const response = await client.queryWithContexts('如何安装?');
console.log(`答案: ${response.answer}`);
console.log(`上下文数量: ${response.contexts?.length || 0}`);高级配置
import { AutoCoderRAGClient, RAGConfig } from 'autocoder-rag-sdk';
const config: RAGConfig = {
docDir: '/path/to/docs',
model: 'v3_chat',
modelFile: '/path/to/model_config.yaml', // 模型配置文件(可选)
agentic: true, // 使用 AgenticRAG
productMode: 'pro',
enableHybridIndex: true,
};
const client = new AutoCoderRAGClient(config);
const answer = await client.query('项目架构是什么?');
console.log(answer);使用模型配置文件
如果你需要使用自定义的模型配置文件,可以通过 modelFile 参数指定:
import { AutoCoderRAGClient } from 'autocoder-rag-sdk';
const client = new AutoCoderRAGClient({
docDir: '/path/to/docs',
modelFile: '/path/to/model_config.yaml', // 模型配置文件
});
// 也可以在查询时覆盖
const answer = await client.query('如何使用这个项目?', {
modelFile: '/path/to/another_model_config.yaml',
});
console.log(answer);自定义命令路径
如果你的 auto-coder.rag 命令安装在非标准位置,可以通过 commandPath 配置项指定命令路径:
import { AutoCoderRAGClient } from 'autocoder-rag-sdk';
const client = new AutoCoderRAGClient({
docDir: '/path/to/docs',
commandPath: '/usr/local/bin/auto-coder.rag', // 自定义命令路径
});
const answer = await client.query('如何使用这个项目?');
console.log(answer);API 文档
AutoCoderRAGClient
class AutoCoderRAGClient {
constructor(config: RAGConfig | string);
query(question: string, options?: RAGQueryOptions): Promise<string>;
queryStream(question: string, options?: RAGQueryOptions): AsyncGenerator<string>;
queryWithContexts(question: string, options?: RAGQueryOptions): Promise<RAGResponse>;
getVersion(): string;
checkAvailability(): boolean;
}示例
运行示例:
pnpm run example:basic
pnpm run example:stream许可证
MIT License
