#setenvironmentvariableAZYLLM_OPENAI_API_KEY=xx#oryoucanmakeaconfigfile(~/.lazyllm/config.json)andaddopenai_api_key=xximportlazyllmt=lazyllm.OnlineChatModule(source="openai",stream=True)w=lazyllm.WebModule(t)w.start().wait()
如果使用一个本地部署的模型,请确保自己安装了至少一个推理框架(lightllm或vllm)
importlazyllm#Modelwillbedownloadautomaticallyifyouhaveaninternetconnectiont=lazyllm.TrainableModule('internlm2-chat-7b')w=lazyllm.WebModule(t)w.start().wait()importosimport 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应用开发框架。
LazyLLMv0.2PRD:https://aicarrier.feishu.cn/wiki/BeFfwBFv8iXq7vkVGyrcv1kGnIhdocs:https://lazyllm.readthedocs.io/githubhttps://github.com/LazyAGI/LazyLLM
欢迎关注我的公众号“PaperAgent”,每天一篇大模型(LLM)文章来锻炼我们的思维,简单的例子,不简单的方法,提升自己。
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |