微信扫码
添加专属顾问
我要投稿
LazyLLM基本概念
使用指南
# set environment variable: LAZYLLM_OPENAI_API_KEY=xx # or you can make a config file(~/.lazyllm/config.json) and add openai_api_key=xximport lazyllmt = lazyllm.OnlineChatModule(source="openai", stream=True)w = lazyllm.WebModule(t)w.start().wait()
如果使用一个本地部署的模型,请确保自己安装了至少一个推理框架(lightllm或vllm)
import lazyllm# Model will be download automatically if you have an internet connectiont = lazyllm.TrainableModule('internlm2-chat-7b')w = lazyllm.WebModule(t)w.start().wait()import osimport lazyllmfrom lazyllm import pipeline, parallel, bind, _0, Document, Retriever, Rerankerprompt = '你将扮演一个人工智能问答助手的角色,完成一项对话任务。在这个任务中,你需要根据给定的上下文以及问题,给出你的回答。'documents = Document(dataset_path='/file/to/yourpath', embed=TrainableModule('bge-large-zh-v1.5'))with pipeline() as ppl:with parallel().sum as ppl.prl:prl.retriever1 = Retriever(documents, parser='CoarseChunk', similarity_top_k=6)prl.retriever2 = Retriever(documents, parser='SentenceDivider', similarity='chinese_bm25', similarity_top_k=6)ppl.reranker = Reranker(types='ModuleReranker', model='bge-reranker-large') | bind(ppl.input, _0)ppl.post_processer = lambda nodes: f'《{nodes[0].metadata["file_name"].split(".")[0]}》{nodes[0].get_content()}' if len(nodes) > 0 else '未找到'ppl.formatter = (lambda ctx, query: dict(context_str=ctx, query_str=query)) | bind(query=ppl.input)ppl.llm = lazyllm.TrainableModule('internlm2-chat-7b').prompt(lazyllm.ChatPrompter(prompt, extro_keys=['context_str']))mweb = lazyllm.WebModule(ppl, port=23456).start().wait()
故事创作
import lazyllmfrom lazyllm import pipeline, warp, bindfrom lazyllm.components.formatter import JsonFormattertoc_prompt=""" 你现在是一个智能助手。你的任务是理解用户的输入,将大纲以列表嵌套字典的列表。每个字典包含一个 `title` 和 `describe`,其中 `title` 中需要用Markdown格式标清层级,`describe` `describe` 是对该段的描述和写作指导。请根据以下用户输入生成相应的列表嵌套字典:输出示例:[{"title": "# 一级标题","describe": "请详细描述此标题的内容,提供背景信息和核心观点。"},{"title": "## 二级标题","describe": "请详细描述标题的内容,提供具体的细节和例子来支持一级标题的观点。"},{"title": "### 三级标题","describe": "请详细描述标题的内容,深入分析并提供更多的细节和数据支持。"}]用户输入如下:"""completion_prompt="""你现在是一个智能助手。你的任务是接收一个包含 `title` 和 `describe` 的字典,并根据 `describe` 中的指导展开写作输入示例:{"title": "# 一级标题","describe": "这是写作的描述。"}输出:这是展开写作写的内容接收如下:"""writer_prompt = {"system": completion_prompt, "user": '{"title": {title}, "describe": {describe}}'}with pipeline() as ppl:ppl.outline_writer = lazyllm.OnlineChatModule(source="openai", stream=False).formatter(JsonFormatter()).prompt(toc_prompt)ppl.story_generater = warp(lazyllm.OnlineChatModule(source="openai", stream=False).prompt(writer_prompt))ppl.synthesizer = (lambda *storys, outlines: "\n".join([f"{o['title']}\n{s}" for s, o in zip(storys, outlines)])) | bind(outlines=ppl.outline_writer)print(ppl({'query':'请帮我写一篇关于人工智能在医疗领域应用的文章。'}))
规划:LazyLLM v0.2的目标是打造一个支持常见的AI-Agent应用场景,并在各个场景下支持灵活定制的AI应用开发框架。
LazyLLM v0.2 PRD:https://aicarrier.feishu.cn/wiki/BeFfwBFv8iXq7vkVGyrcv1kGnIhdocs:https://lazyllm.readthedocs.io/github https://github.com/LazyAGI/LazyLLM
欢迎关注我的公众号“PaperAgent”,每天一篇大模型(LLM)文章来锻炼我们的思维,简单的例子,不简单的方法,提升自己。
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2026-03-20
企业级 Agent 多智能体架构与选型指南 -- 来自1000+行业应用实践积累
2026-03-20
ollama v0.18.2 发布!OpenClaw 安装优化、Claude 加速、MLX 量化全面升级
2026-03-19
开源版Cowork——Eigent集成ERNIE 5.0,让AI Agent自动化高效工作
2026-03-17
打造 Claude Code 并行自主开发环境:Auto Claude + GLM 4.7
2026-03-17
又一款开源的LLM生成3D场景的3D编辑器,这次功能更强大了
2026-03-17
英伟达的NemoClaw,能帮AI代理这匹“野马”套上缰绳吗?
2026-03-17
腾讯混元AI Infra核心技术重磅开源:推理吞吐提升30%!
2026-03-17
英伟达重磅开源!Nemotron 3 Super:专为AI智能体打造的"超级大脑
2026-01-27
2026-01-30
2026-01-12
2026-01-29
2026-01-27
2025-12-22
2026-01-28
2026-01-21
2025-12-23
2026-01-06
2026-03-17
2026-03-13
2026-03-02
2026-02-05
2026-01-28
2026-01-26
2026-01-21
2026-01-21