Agent LLM: multi-provider, multi-model, simple chat/image API. Consumes agent.yaml llm section.
npm install @easynet/agent-llm最小目标:从 llm.yaml 创建一个可直接给 LangChain 使用的 ChatModel。
``ts
import { createAgentLlM } from "@easynet/agent-llm";
const llm = await createAgentLlM();
const result = await llm.invoke("hello");
console.log(result.content);
`
llm.yaml
`yaml
llm:
# 默认使用 small 这个实例
default: small
# 可按需保留 strong;不需要就删掉
strong:
provider: openai
base_url: ${LLM_BASE_URL}
model: ${LLM_MODEL}
# 本地 Ollama 最常见配置
small:
provider: openai
base_url: http://localhost:11434/v1
model: qwen3:0.6b
`
`ts
import { createAgentLlM } from "@easynet/agent-llm";
async function main() {
// 1) 从当前目录 llm.yaml 读取配置并创建模型
const llm = await createAgentLlM();
// 2) 直接调用模型
const response = await llm.invoke("请用一句话介绍你自己。");
// 3) 输出文本
console.log(response.content);
}
main().catch(console.error);
`
- 自定义 provider:registerChatModelProvider(...)getDefaultLlmConfig(...)
- 只取默认模型配置:createChatModelFromLlmConfig(...)`
- 直接从对象构建模型: