跳转到主要内容

Documentation Index

Fetch the complete documentation index at: https://simplellmfunc.cn/llms.txt

Use this file to discover all available pages before exploring further.

示例

所有示例都在 examples/ 目录中。每个示例都是独立且可运行的。

快速入门

示例展示内容
basic_usage.py最简 @llm_function 调用及类型化输出
template_params_example.py使用 _template_params 的动态文档字符串模板

工具使用

示例展示内容
tool_usage_example.py@tool 装饰器、多工具 Agent
multimodal_tool_example.py返回 ImgPath/ImgUrl 的工具
agent_as_tool_example.py将一个 Agent 嵌套为另一个 Agent 的工具

聊天与流式输出

示例展示内容
streaming_example.py使用 LLMChunkArriveEvent 消费实时流式输出
event_stream_example.py完整的事件流消费模式
abort_example.py使用 AbortSignal 进行取消操作

PyRepl 与运行时

示例展示内容
pyrepl_example.py持久化 REPL:变量、流式输出、重置
selfref_example.pyruntime.selfref.context.* 原语

完整 Agent

示例展示内容
tui_general_agent_example.py完整的编程 Agent,包含 TUI、PyRepl、FileToolset、SelfRef、分叉(fork)与压缩(compaction)
这是构建生产级 Agent 的参考实现。架构详解请参阅 Harness 模式

运行示例

# 克隆仓库
git clone https://github.com/NiJingzhe/SimpleLLMFunc.git
cd SimpleLLMFunc

# 安装依赖
poetry install

# 复制并配置 provider.json
cp examples/provider_template.json examples/provider.json
# 编辑 examples/provider.json,填入你的 API 密钥

# 运行任意示例
poetry run python examples/basic_usage.py
poetry run python examples/tui_general_agent_example.py

构建你自己的应用

从以下模式之一开始:

单次调用函数

@llm_function — 类型化输入/输出,无状态

聊天 Agent

@llm_chat + 工具 — 多轮对话与 ReAct 循环

完整 Agent

PyRepl + SelfRef + FileToolset + TUI — 生产级