Chidori 开源项目教程
1. 项目介绍
Chidori 是一个开源的反应式运行时,专门用于构建持久的 AI 代理。它提供了一个运行时环境,支持 Python 和 JavaScript 代码执行,旨在解决 AI 代理在长期运行工作流中的复杂性问题。Chidori 的核心功能包括行为缓存、时间旅行调试、可视化调试环境以及创建和导航树搜索代码执行工作流。
2. 项目快速启动
安装
Chidori 可以通过 cargo
安装,以下是安装步骤:
xcode-select --install
brew install cmake protobuf libiconv python@3.12 uv
cargo install chidori-debugger
设置运行时环境
Chidori 默认使用 http://localhost:4000
与 LiteLLM 的代理进行交互。如果需要使用 gpt-3.5-turbo
,可以按照以下步骤设置:
pip install litellm[proxy]
uv sync
export OPENAI_API_KEY=your_openai_api_key
uv run litellm --config /litellm_config.yaml
示例代码
以下是一个简单的 Chidori 代理示例,该代理从 Hacker News 获取热门文章,并使用 OpenAI API 过滤出与 AI 相关的新项目,然后将其格式化为 Markdown:
const axios = require('https://deno.land/x/axiod/mod.ts');
const HN_URL_TOP_STORIES = "https://hacker-news.firebaseio.com/v0/topstories.json";
function fetchStory(id) {
return axios.get(`https://hacker-news.firebaseio.com/v0/item/${id}.json?print=pretty`)
.then(response => response.data);
}
async function fetchHN() {
const stories = await axios.get(HN_URL_TOP_STORIES);
const storyIds = stories.data;
const tasks = storyIds.slice(0, 30).map(id => fetchStory(id));
return Promise.all(tasks)
.then(stories => {
return stories.map(story => {
const [title, url, score] = story;
return [title, url, score];
});
});
}
(interpret_the_group)
Based on the following list of HackerNews threads, filter this list to only launches of new AI projects: [[fetched_articles]]
(format_and_rank)
Format this list of new AI projects in markdown, ranking the most interesting projects from most interesting to least: [[interpret_the_group]]
articles = await fetchHN()
format_and_rank(articles=articles)
3. 应用案例和最佳实践
Chidori 适用于需要复杂状态管理和调试的 AI 代理项目。例如,在开发一个需要与多个 AI 模型交互的代理时,Chidori 可以帮助开发者理解和控制代理的状态变化,通过时间旅行调试功能,开发者可以回溯和修正代理的行为。
4. 典型生态项目
Chidori 作为一个运行时环境,可以与其他 AI 工具和框架集成。例如,它可以与 LiteLLM 代理一起使用,通过 HTTP 代理与 OpenAI 的 GPT 模型进行交互。此外,Chidori 还支持与 Python 和 JavaScript 生态系统的其他工具和库集成,如 NumPy、Pandas 等。