当前位置: 首页 > news >正文

AI Agent开发学习系列 - langchain之LCEL(2):LCEL 链式表达解析

input schema

在 LangChain LCEL(LangChain Expression Language)中,input schema(输入模式/输入结构)用于描述链(chain)或组件所需输入的参数结构。它通常基于 Pydantic 的 schema 自动推断生成,便于类型校验和 IDE 智能提示。

from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from pydantic import SecretStr
import os
from dotenv import load_dotenvload_dotenv()llm = ChatOpenAI(api_key=SecretStr(os.environ.get("HUNYUAN_API_KEY", "")),  # 混元 APIKeybase_url="https://api.hunyuan.cloud.tencent.com/v1",  # 混元 endpointmodel="hunyuan-lite",  # 模型名称temperature=0
)prompt = ChatPromptTemplate.from_template("请讲一个关于{topic}的故事。")chain = prompt | llm 
chain.input_schema.model_json_schema()

{‘properties’: {‘topic’: {‘title’: ‘Topic’, ‘type’: ‘string’}},
‘required’: [‘topic’],
‘title’: ‘PromptInput’,
‘type’: ‘object’}

prompt.input_schema.model_json_schema()

{‘properties’: {‘topic’: {‘title’: ‘Topic’, ‘type’: ‘string’}},
‘required’: [‘topic’],
‘title’: ‘PromptInput’,
‘type’: ‘object’}

llm.input_schema.model_json_schema()
{'$defs': {'AIMessage': {'additionalProperties': True,'description': 'Message from an AI.\n\nAIMessage is returned from a chat model as a response to a prompt.\n\nThis message represents the output of the model and consists of both\nthe raw output as returned by the model together standardized fields\n(e.g., tool calls, usage metadata) added by the LangChain framework.','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'ai','default': 'ai','title': 'Type','type': 'string'},'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Name'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'},'example': {'default': False, 'title': 'Example', 'type': 'boolean'},'tool_calls': {'default': [],'items': {'$ref': '#/$defs/ToolCall'},'title': 'Tool Calls','type': 'array'},'invalid_tool_calls': {'default': [],'items': {'$ref': '#/$defs/InvalidToolCall'},'title': 'Invalid Tool Calls','type': 'array'},'usage_metadata': {'anyOf': [{'$ref': '#/$defs/UsageMetadata'},{'type': 'null'}],'default': None}},'required': ['content'],'title': 'AIMessage','type': 'object'},'AIMessageChunk': {'additionalProperties': True,'description': 'Message chunk from an AI.','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'AIMessageChunk','default': 'AIMessageChunk','title': 'Type','type': 'string'},'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Name'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'},'example': {'default': False, 'title': 'Example', 'type': 'boolean'},'tool_calls': {'default': [],'items': {'$ref': '#/$defs/ToolCall'},'title': 'Tool Calls','type': 'array'},'invalid_tool_calls': {'default': [],'items': {'$ref': '#/$defs/InvalidToolCall'},'title': 'Invalid Tool Calls','type': 'array'},'usage_metadata': {'anyOf': [{'$ref': '#/$defs/UsageMetadata'},{'type': 'null'}],'default': None},'tool_call_chunks': {'default': [],'items': {'$ref': '#/$defs/ToolCallChunk'},'title': 'Tool Call Chunks','type': 'array'}},'required': ['content'],'title': 'AIMessageChunk','type': 'object'},'ChatMessage': {'additionalProperties': True,'description': 'Message that can be assigned an arbitrary speaker (i.e. role).','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'chat','default': 'chat','title': 'Type','type': 'string'},'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Name'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'},'role': {'title': 'Role', 'type': 'string'}},'required': ['content', 'role'],'title': 'ChatMessage','type': 'object'},'ChatMessageChunk': {'additionalProperties': True,'description': 'Chat Message chunk.','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'ChatMessageChunk','default': 'ChatMessageChunk','title': 'Type','type': 'string'},'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Name'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'},'role': {'title': 'Role', 'type': 'string'}},'required': ['content', 'role'],'title': 'ChatMessageChunk','type': 'object'},'ChatPromptValueConcrete': {'description': 'Chat prompt value which explicitly lists out the message types it accepts.\n\nFor use in external schemas.','properties': {'messages': {'items': {'oneOf': [{'$ref': '#/$defs/AIMessage'},{'$ref': '#/$defs/HumanMessage'},{'$ref': '#/$defs/ChatMessage'},{'$ref': '#/$defs/SystemMessage'},{'$ref': '#/$defs/FunctionMessage'},{'$ref': '#/$defs/ToolMessage'},{'$ref': '#/$defs/AIMessageChunk'},{'$ref': '#/$defs/HumanMessageChunk'},{'$ref': '#/$defs/ChatMessageChunk'},{'$ref': '#/$defs/SystemMessageChunk'},{'$ref': '#/$defs/FunctionMessageChunk'},{'$ref': '#/$defs/ToolMessageChunk'}]},'title': 'Messages','type': 'array'},'type': {'const': 'ChatPromptValueConcrete','default': 'ChatPromptValueConcrete','title': 'Type','type': 'string'}},'required': ['messages'],'title': 'ChatPromptValueConcrete','type': 'object'},'FunctionMessage': {'additionalProperties': True,'description': 'Message for passing the result of executing a tool back to a model.\n\nFunctionMessage are an older version of the ToolMessage schema, and\ndo not contain the tool_call_id field.\n\nThe tool_call_id field is used to associate the tool call request with the\ntool call response. This is useful in situations where a chat model is able\nto request multiple tool calls in parallel.','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'function','default': 'function','title': 'Type','type': 'string'},'name': {'title': 'Name', 'type': 'string'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'}},'required': ['content', 'name'],'title': 'FunctionMessage','type': 'object'},'FunctionMessageChunk': {'additionalProperties': True,'description': 'Function Message chunk.','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'FunctionMessageChunk','default': 'FunctionMessageChunk','title': 'Type','type': 'string'},'name': {'title': 'Name', 'type': 'string'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'}},'required': ['content', 'name'],'title': 'FunctionMessageChunk','type': 'object'},'HumanMessage': {'additionalProperties': True,'description': 'Message from a human.\n\nHumanMessages are messages that are passed in from a human to the model.\n\nExample:\n\n    .. code-block:: python\n\n        from langchain_core.messages import HumanMessage, SystemMessage\n\n        messages = [\n            SystemMessage(\n                content="You are a helpful assistant! Your name is Bob."\n            ),\n            HumanMessage(\n                content="What is your name?"\n            )\n        ]\n\n        # Instantiate a chat model and invoke it with the messages\n        model = ...\n        print(model.invoke(messages))','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'human','default': 'human','title': 'Type','type': 'string'},'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Name'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'},'example': {'default': False, 'title': 'Example', 'type': 'boolean'}},'required': ['content'],'title': 'HumanMessage','type': 'object'},'HumanMessageChunk': {'additionalProperties': True,'description': 'Human Message chunk.','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'HumanMessageChunk','default': 'HumanMessageChunk','title': 'Type','type': 'string'},'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Name'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'},'example': {'default': False, 'title': 'Example', 'type': 'boolean'}},'required': ['content'],'title': 'HumanMessageChunk','type': 'object'},'InputTokenDetails': {'description': 'Breakdown of input token counts.\n\nDoes *not* need to sum to full input token count. Does *not* need to have all keys.\n\nExample:\n\n    .. code-block:: python\n\n        {\n            "audio": 10,\n            "cache_creation": 200,\n            "cache_read": 100,\n        }\n\n.. versionadded:: 0.3.9\n\nMay also hold extra provider-specific keys.','properties': {'audio': {'title': 'Audio', 'type': 'integer'},'cache_creation': {'title': 'Cache Creation', 'type': 'integer'},'cache_read': {'title': 'Cache Read', 'type': 'integer'}},'title': 'InputTokenDetails','type': 'object'},'InvalidToolCall': {'description': 'Allowance for errors made by LLM.\n\nHere we add an `error` key to surface errors made during generation\n(e.g., invalid JSON arguments.)','properties': {'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'title': 'Name'},'args': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'title': 'Args'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'title': 'Id'},'error': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'title': 'Error'},'type': {'const': 'invalid_tool_call', 'title': 'Type', 'type': 'string'}},'required': ['name', 'args', 'id', 'error'],'title': 'InvalidToolCall','type': 'object'},'OutputTokenDetails': {'description': 'Breakdown of output token counts.\n\nDoes *not* need to sum to full output token count. Does *not* need to have all keys.\n\nExample:\n\n    .. code-block:: python\n\n        {\n            "audio": 10,\n            "reasoning": 200,\n        }\n\n.. versionadded:: 0.3.9','properties': {'audio': {'title': 'Audio', 'type': 'integer'},'reasoning': {'title': 'Reasoning', 'type': 'integer'}},'title': 'OutputTokenDetails','type': 'object'},'StringPromptValue': {'description': 'String prompt value.','properties': {'text': {'title': 'Text', 'type': 'string'},'type': {'const': 'StringPromptValue','default': 'StringPromptValue','title': 'Type','type': 'string'}},'required': ['text'],'title': 'StringPromptValue','type': 'object'},'SystemMessage': {'additionalProperties': True,'description': 'Message for priming AI behavior.\n\nThe system message is usually passed in as the first of a sequence\nof input messages.\n\nExample:\n\n    .. code-block:: python\n\n        from langchain_core.messages import HumanMessage, SystemMessage\n\n        messages = [\n            SystemMessage(\n                content="You are a helpful assistant! Your name is Bob."\n            ),\n            HumanMessage(\n                content="What is your name?"\n            )\n        ]\n\n        # Define a chat model and invoke it with the messages\n        print(model.invoke(messages))','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'system','default': 'system','title': 'Type','type': 'string'},'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Name'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'}},'required': ['content'],'title': 'SystemMessage','type': 'object'},'SystemMessageChunk': {'additionalProperties': True,'description': 'System Message chunk.','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'SystemMessageChunk','default': 'SystemMessageChunk','title': 'Type','type': 'string'},'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Name'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'}},'required': ['content'],'title': 'SystemMessageChunk','type': 'object'},'ToolCall': {'description': 'Represents a request to call a tool.\n\nExample:\n\n    .. code-block:: python\n\n        {\n            "name": "foo",\n            "args": {"a": 1},\n            "id": "123"\n        }\n\n    This represents a request to call the tool named "foo" with arguments {"a": 1}\n    and an identifier of "123".','properties': {'name': {'title': 'Name', 'type': 'string'},'args': {'additionalProperties': True, 'title': 'Args', 'type': 'object'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'title': 'Id'},'type': {'const': 'tool_call', 'title': 'Type', 'type': 'string'}},'required': ['name', 'args', 'id'],'title': 'ToolCall','type': 'object'},'ToolCallChunk': {'description': 'A chunk of a tool call (e.g., as part of a stream).\n\nWhen merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\nall string attributes are concatenated. Chunks are only merged if their\nvalues of `index` are equal and not None.\n\nExample:\n\n.. code-block:: python\n\n    left_chunks = [ToolCallChunk(name="foo", args=\'{"a":\', index=0)]\n    right_chunks = [ToolCallChunk(name=None, args=\'1}\', index=0)]\n\n    (\n        AIMessageChunk(content="", tool_call_chunks=left_chunks)\n        + AIMessageChunk(content="", tool_call_chunks=right_chunks)\n    ).tool_call_chunks == [ToolCallChunk(name=\'foo\', args=\'{"a":1}\', index=0)]','properties': {'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'title': 'Name'},'args': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'title': 'Args'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'title': 'Id'},'index': {'anyOf': [{'type': 'integer'}, {'type': 'null'}],'title': 'Index'},'type': {'const': 'tool_call_chunk', 'title': 'Type', 'type': 'string'}},'required': ['name', 'args', 'id', 'index'],'title': 'ToolCallChunk','type': 'object'},'ToolMessage': {'additionalProperties': True,'description': 'Message for passing the result of executing a tool back to a model.\n\nToolMessages contain the result of a tool invocation. Typically, the result\nis encoded inside the `content` field.\n\nExample: A ToolMessage representing a result of 42 from a tool call with id\n\n    .. code-block:: python\n\n        from langchain_core.messages import ToolMessage\n\n        ToolMessage(content=\'42\', tool_call_id=\'call_Jja7J89XsjrOLA5r!MEOW!SL\')\n\n\nExample: A ToolMessage where only part of the tool output is sent to the model\n    and the full output is passed in to artifact.\n\n    .. versionadded:: 0.2.17\n\n    .. code-block:: python\n\n        from langchain_core.messages import ToolMessage\n\n        tool_output = {\n            "stdout": "From the graph we can see that the correlation between x and y is ...",\n            "stderr": None,\n            "artifacts": {"type": "image", "base64_data": "/9j/4gIcSU..."},\n        }\n\n        ToolMessage(\n            content=tool_output["stdout"],\n            artifact=tool_output,\n            tool_call_id=\'call_Jja7J89XsjrOLA5r!MEOW!SL\',\n        )\n\nThe tool_call_id field is used to associate the tool call request with the\ntool call response. This is useful in situations where a chat model is able\nto request multiple tool calls in parallel.','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'tool','default': 'tool','title': 'Type','type': 'string'},'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Name'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'},'tool_call_id': {'title': 'Tool Call Id', 'type': 'string'},'artifact': {'default': None, 'title': 'Artifact'},'status': {'default': 'success','enum': ['success', 'error'],'title': 'Status','type': 'string'}},'required': ['content', 'tool_call_id'],'title': 'ToolMessage','type': 'object'},'ToolMessageChunk': {'additionalProperties': True,'description': 'Tool Message chunk.','properties': {'content': {'anyOf': [{'type': 'string'},{'items': {'anyOf': [{'type': 'string'},{'additionalProperties': True, 'type': 'object'}]},'type': 'array'}],'title': 'Content'},'additional_kwargs': {'additionalProperties': True,'title': 'Additional Kwargs','type': 'object'},'response_metadata': {'additionalProperties': True,'title': 'Response Metadata','type': 'object'},'type': {'const': 'ToolMessageChunk','default': 'ToolMessageChunk','title': 'Type','type': 'string'},'name': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Name'},'id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],'default': None,'title': 'Id'},'tool_call_id': {'title': 'Tool Call Id', 'type': 'string'},'artifact': {'default': None, 'title': 'Artifact'},'status': {'default': 'success','enum': ['success', 'error'],'title': 'Status','type': 'string'}},'required': ['content', 'tool_call_id'],'title': 'ToolMessageChunk','type': 'object'},'UsageMetadata': {'description': 'Usage metadata for a message, such as token counts.\n\nThis is a standard representation of token usage that is consistent across models.\n\nExample:\n\n    .. code-block:: python\n\n        {\n            "input_tokens": 350,\n            "output_tokens": 240,\n            "total_tokens": 590,\n            "input_token_details": {\n                "audio": 10,\n                "cache_creation": 200,\n                "cache_read": 100,\n            },\n            "output_token_details": {\n                "audio": 10,\n                "reasoning": 200,\n            }\n        }\n\n.. versionchanged:: 0.3.9\n\n    Added ``input_token_details`` and ``output_token_details``.','properties': {'input_tokens': {'title': 'Input Tokens', 'type': 'integer'},'output_tokens': {'title': 'Output Tokens', 'type': 'integer'},'total_tokens': {'title': 'Total Tokens', 'type': 'integer'},'input_token_details': {'$ref': '#/$defs/InputTokenDetails'},'output_token_details': {'$ref': '#/$defs/OutputTokenDetails'}},'required': ['input_tokens', 'output_tokens', 'total_tokens'],'title': 'UsageMetadata','type': 'object'}},'anyOf': [{'type': 'string'},{'$ref': '#/$defs/StringPromptValue'},{'$ref': '#/$defs/ChatPromptValueConcrete'},{'items': {'oneOf': [{'$ref': '#/$defs/AIMessage'},{'$ref': '#/$defs/HumanMessage'},{'$ref': '#/$defs/ChatMessage'},{'$ref': '#/$defs/SystemMessage'},{'$ref': '#/$defs/FunctionMessage'},{'$ref': '#/$defs/ToolMessage'},{'$ref': '#/$defs/AIMessageChunk'},{'$ref': '#/$defs/HumanMessageChunk'},{'$ref': '#/$defs/ChatMessageChunk'},{'$ref': '#/$defs/SystemMessageChunk'},{'$ref': '#/$defs/FunctionMessageChunk'},{'$ref': '#/$defs/ToolMessageChunk'}]},'type': 'array'}],'title': 'ChatOpenAIInput'}

Steam(流式输出)

在 LangChain LCEL 或链式表达中,Stream(流式输出) 指的是大模型生成内容时,能够边生成边输出,而不是等全部生成完毕后一次性返回。这种方式常用于提升用户体验,尤其适合长文本生成、对话、RAG 问答等场景。

for s in chain.stream({"topic": "月亮"}):print(s.content, end="", flush=True)
从前,有一个古老的村庄,村子里的居民们相信月亮是他们的守护神。每个月圆之夜,月亮都会准时升起,照亮了整个天空,给村民们带来无尽的遐想和希望。在这个村子里,有一个聪明勇敢的小男孩,名叫小明。他非常喜欢观察天象,尤其是月亮的变化。每个月圆之夜,他都会爬上自家院子的屋顶,仰望那轮明亮的月亮,陷入深深的遐想。有一天晚上,小明发现月亮似乎有些异样。它比平时更加明亮,而且形状也变得有些奇怪。小明决定去问问村里的长者,看看他们是否知道这是什么原因。长者们告诉小明,那轮月亮已经很久没有这样出现过过了。他们还告诉他,只有心地善良、勇敢面对困难的人,才能见到这神秘的月亮。小明听后,决定要一探究竟。他告别了家人,踏上了寻找神秘月亮的旅程。他穿过了森林,翻过了山丘,跨过了河流,终于来到了一个神秘的山洞前。在山洞里,小明遇到了一位美丽的仙女。仙女告诉他,那轮神秘的月亮其实是一位被贬下凡的神灵,她被困在这里,无法回到天庭。只有找到一颗拥有神奇力量的宝石,才能帮助她重返天庭。小明毫不犹豫地答应了仙女的帮助。他们一起踏上了寻找宝石的旅程。最后,他们在一座高山上找到了那颗宝石,它散发着耀眼的光芒。小明拿着宝石回到了村子,将宝石交给了仙女。仙女感激地向小明道谢,然后化作一道光芒,飞回了天庭。而那颗宝石,也成为了村子的守护神,保佑着村民们过上幸福安宁的生活。从此以后,每逢月圆之夜,小明都会站在自家院子的屋顶,仰望那轮明亮的月亮,心中充满了对神秘月亮的敬意和感激。而村民们也被小明的勇敢和善良所感染,他们相信,只要有勇气面对困难,每个人都能成为自己生活中的守护神。

Invoke

在 LangChain LCEL(LangChain Expression Language)中,Invoke 是最常用的同步调用方法,用于“一次性”输入参数并获取完整输出结果。它适用于绝大多数链式表达、模型推理、RAG 问答等场景。

chain.invoke({"topic": "月亮"})
AIMessage(content='从前,有一个古老的村庄,村子里的居民们都相信月亮是他们的守护神。每天夜晚,他们都会仰望星空,默默祈祷,希望月亮能保佑他们的生活平安、丰收。\n\n有一天晚上,村子里的小孩们决定去探险,看看月亮到底是什么样子的。他们悄悄地溜出家门,来到了一片开阔的田野。孩子们仰望着天空,月亮高悬在夜空中,洒下一片柔和的银光。他们惊讶地发现,月亮的形状竟然像一个大银盘!\n\n这时,一个名叫小明的孩子突然说:“你们看,月亮上的那个黑点,是不是一个眼睛?”孩子们纷纷凑过去看,确实发现月亮上有一个小小的黑点。这时,小明提议:“我们每天都看着月亮,不如我们来做个约定吧!每天晚上,我们都来观察月亮,看看它的形状有没有变化。”\n\n孩子们觉得这个主意很好,于是他们决定每天都晚上去观察月亮。渐渐地,孩子们发现月亮的形状确实发生了变化,有时像一只小船,有时像一个大银盘,还有时像一个笑脸。\n\n有一天晚上,孩子们又来到田野里观察月亮。突然,小明指着月亮说:“你们看,月亮上的那个黑点变成了一个弯弯的眉毛!”孩子们仔细一看,果然如此。这时,小明兴奋地说:“你们知道吗?那个黑点其实是一个古老的传说,它代表着月亮的守护神,一直在默默地保护着我们。”\n\n孩子们听了小明的话,更加敬仰月亮了。他们决定以后每天晚上都来观察月亮,不仅为了欣赏它的美丽,还要学习它的故事。从此,村子里的人们也更加尊敬月亮,每逢月圆之夜,都会举行庆祝活动,感谢月亮的守护。\n\n这个故事传遍了整个村子,人们都明白了尊重自然、珍惜美好的事物的重要性。而村子里的孩子们也学会了观察和探索,培养了他们的想象力和求知欲。从此,这个村子变得越来越美好,人们的生活也越来越幸福。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 404, 'prompt_tokens': 9, 'total_tokens': 413, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': 'f5759702a9a5eca8eff99516d362410d', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--54218d8a-78f2-47b5-8cf3-5179c54d4eba-0', usage_metadata={'input_tokens': 9, 'output_tokens': 404, 'total_tokens': 413, 'input_token_details': {}, 'output_token_details': {}})

Batch

在 LangChain LCEL(LangChain Expression Language)中,Batch 用于批量输入多个请求,并一次性并发处理,返回对应的批量输出结果。它非常适合需要同时处理大量输入、提升吞吐量的场景,比如批量生成、批量问答、数据清洗等。

chain.batch([{"topic": "月亮"}, {"topic": "太阳"}])
[AIMessage(content='从前,有一个古老的村庄,村子里的居民们相信月亮是他们的守护神。每个月圆之夜,月亮都会准时升起,照亮了整个村庄。村民们相信,在月圆之夜许愿会带来好运和祝福。\n\n有一天晚上,一个名叫小莉的女孩在村子附近的树林里迷路了。月亮高悬在夜空中,洒下一片柔和的银光。小莉心里害怕,不知所措。就在这时,她注意到不远处有一个古老的石碑,上面刻着奇怪的符号。\n\n小莉鼓起勇气走过去,仔细观察这些符号。突然,她发现这些符号与月亮的形状非常相似。她开始跟着符号的轮廓,轻轻地哼唱着一种古老的旋律。随着她的吟唱,石碑上的符号开始发出微弱的光芒。\n\n突然间,月亮从云层中探出头来,它的光芒照在石碑上,使得那些符号变得更加明亮。就在这时,小莉感到一股神秘的力量涌上心头。她闭上眼睛,许下了一个愿望:“我希望回到村子,不再迷路。”\n\n当她睁开眼睛时,发现自己已经站在家门口。她回到了熟悉的村子,看到了熟悉的景象。村民们都非常惊讶,纷纷围上来询问她是如何回家的。\n\n小莉把在树林里遇到的古老石碑和神秘夜晚的经历告诉了大家。从此,村民们更加敬畏月亮,每逢月圆之夜,都会举行庆祝活动,感谢月亮的庇佑。\n\n而小莉,也成了村子里流传千古的传奇人物。每当月圆之夜,她都会被人们想起那个神秘的夜晚,以及她所许下的美好愿望。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 332, 'prompt_tokens': 9, 'total_tokens': 341, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '1894c543e177e7599d1fc1d6f71bbc4e', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--148873f5-5acb-4396-bd11-c90dc8fbc59a-0', usage_metadata={'input_tokens': 9, 'output_tokens': 332, 'total_tokens': 341, 'input_token_details': {}, 'output_token_details': {}}),AIMessage(content='从前,有一个遥远的国度,名叫日光王国。在这个国度里,有一个巨大的太阳,它高悬在天空,照耀着大地,给人们带来温暖和光明。\n\n日光王国的国王是一位英明的君主,他深知太阳对于国度的重要性。为了感谢太阳的恩赐,国王决定为它举办一场盛大的庆典。他邀请了整个国度的人们,共同庆祝太阳的生日。\n\n庆典那天,人们穿上节日盛装,载歌载舞,共同庆祝这个特殊的日子。太阳也感受到了人们的喜悦,它洒下金光,照亮了整个国度,让一切都显得如此美好。\n\n就在庆典的高潮时刻,国王突然意识到,太阳每天都会升起,给人们带来光明和温暖,但它自己却没有休息的时候。于是,国王决定为太阳举办一场特殊的宴会,邀请太阳参加。\n\n太阳欣然接受了国王的邀请,它飞到宴会现场,与人们共度欢乐时光。人们在宴会上唱歌、跳舞,尽情地享受着太阳带来的温暖和光明。\n\n然而,太阳觉得这样的庆祝方式有些单调。它决定给人们一个惊喜,于是从天空中拿出一把金色的魔法画笔,开始在天空中绘制美丽的图案。随着太阳画笔的舞动,天空中出现了许多美丽的景象,如彩虹、云朵和花朵等。\n\n人们被这美丽的景象深深吸引,纷纷拿出手机拍照留念。国王也为太阳的创意感到骄傲,他宣布将这一刻永远定格在日光王国的历史中。\n\n从此,日光王国的人们更加珍惜太阳带来的光和热,他们感激太阳的恩赐,并将这一天定为永恒的节日。而太阳也继续高悬天际,照耀着这片美丽的国度,给人们带来希望和温暖。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 356, 'prompt_tokens': 9, 'total_tokens': 365, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': 'd0a8acb1a1aacf2518b4771a5f8aa1ab', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--58e59480-734e-4786-bd66-ffd7e39436a4-0', usage_metadata={'input_tokens': 9, 'output_tokens': 356, 'total_tokens': 365, 'input_token_details': {}, 'output_token_details': {}})]
#max_concurrency控制并发数
chain.batch([{"topic": "月亮"}, {"topic": "太阳"}, {"topic": "星星"}],max_concurrency=2
)
[AIMessage(content='从前,有一个古老的村庄,村子里的居民们相信月亮是他们的守护神。每个月圆之夜,月亮都会准时升起,照亮了整个天空,给村民们带来无尽的遐想和希望。\n\n在这个村子里,有一个聪明勇敢的小男孩,名叫小明。他非常喜欢观察天象,尤其是月亮的变化。每个月圆之夜,他都会爬上自家院子的屋顶,仰望那轮明亮的月亮,陷入深深的思索。\n\n有一天晚上,小明发现月亮似乎有些异样。它比往常更加明亮,而且形状也变得有些奇怪。小明感到非常困惑,决定去请教村里的长者。\n\n长者们告诉小明,那轮明月其实是一位美丽的仙女。她被困在了月亮上,只有找到一颗神奇的宝石,才能解救她。这颗宝石被藏在一座遥远的山峰之巅。\n\n小明决定踏上寻找神奇宝石的冒险之旅。他告别了家人和朋友,带上了一些干粮和水,踏上了通往山峰的道路。一路上,他遇到了各种困难和挑战,但他从未放弃过。\n\n经过一番艰苦的跋涉,小明终于来到了山峰之巅。在那里,他发现了一个巨大的石碑,上面刻着古老的文字。小明仔细阅读了这些文字,发现了一个关于宝石的谜题。\n\n小明凭借着自己的智慧和勇气,解开了谜题,找到了那颗神奇的宝石。他小心翼翼地将宝石带回村子,将它交给了长者们。\n\n长者们感激地向小明表示感谢,并告诉他,自从他找到宝石以来,月亮已经恢复了往日的美丽和神秘。从那以后,每当月圆之夜,小明都会和村民们一起欣赏那美丽的月亮,感激她为他们带来的好运和希望。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 356, 'prompt_tokens': 9, 'total_tokens': 365, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '721472fecbce3d903038a5459687a6e2', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--c765c788-b39c-47c1-9540-9ce7964ce428-0', usage_metadata={'input_tokens': 9, 'output_tokens': 356, 'total_tokens': 365, 'input_token_details': {}, 'output_token_details': {}}),AIMessage(content='从前,有一个遥远的国度,名叫日光王国。在这个国度里,有一个巨大的太阳,它高悬在天空,照耀着大地,给人们带来温暖和光明。\n\n日光王国的国王是一位英明的君主,他深知太阳对于国度的重要性。为了感谢太阳的恩赐,国王决定为太阳举办一场盛大的庆典。他邀请了整个国度的人们,共同庆祝太阳的生日。\n\n庆典那天,人们穿上节日盛装,载歌载舞,共同庆祝这个特殊的日子。太阳也感受到了人们的喜悦,它洒下金光,照亮了整个国度,让一切都显得如此美好。\n\n就在庆典的高潮时刻,国王突然意识到,太阳每天都会升起,给人们带来光明和温暖,但它的生命是短暂的。为了让太阳能够永远照耀大地,国王决定召集全国的智者,寻求一个能让太阳永生的办法。\n\n经过一番努力,智者们终于找到了一个方法。他们发现,只要在太阳的中心镶嵌一颗神奇的宝石,太阳就会永远照耀大地。于是,国王派出勇士,前往寻找这颗神奇的宝石。\n\n经过一番艰苦的探险,勇士终于找到了宝石,并将其带回日光王国。国王将宝石小心翼翼地镶嵌在太阳的中心,果然,太阳变得更加明亮,永远照耀着大地。\n\n人们为国王和勇士们的勇敢和智慧欢呼雀跃,他们共同庆祝这个美好的时刻。从此,日光王国的人们过上了幸福美满的生活,而太阳也永远照耀着这片土地。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 301, 'prompt_tokens': 9, 'total_tokens': 310, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': 'c56077cd5429df3f94b87bddf32adacb', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--6d60910e-5cab-49f7-ae1a-d34678763239-0', usage_metadata={'input_tokens': 9, 'output_tokens': 301, 'total_tokens': 310, 'input_token_details': {}, 'output_token_details': {}}),AIMessage(content='从前,有一个遥远的星球,那里有一片璀璨的星空。在这个星球上,生活着一群可爱的小精灵。这些小精灵全身散发着柔和的光芒,他们最喜欢的事情就是在星空中飞翔,欣赏那些美丽的星星。\n\n有一天,一颗新星来到了这个星球。这颗新星非常特别,它的光芒与众不同,闪烁着奇异的颜色。小精灵们都非常好奇,纷纷围了上来。他们发现这颗新星的光芒中似乎蕴含着某种神秘的力量。\n\n于是,一位名叫米洛的小精灵提议大家一起去探索这颗新星。于是,所有的精灵们聚在一起,他们手牵手,一起飞向那颗闪烁着奇异光芒的新星。\n\n当他们飞到新星附近时,突然被眼前的景象惊呆了。新星周围竟然有一片神秘的森林,森林里住着各种奇特的生物。这些生物有的像巨大的蜘蛛,有的像会说话的树木,还有的像透明的水晶球。\n\n精灵们兴奋地在这片森林里探险,他们发现这里的每一个生物都散发着柔和的光芒,与星空中的星星相映成趣。他们在森林里度过了一段美好的时光,学到了许多新知识。\n\n然而,这段旅程并没有持续太久。突然,森林里传来了一阵恐怖的声音,原来是一只邪恶的巨龙来到了这片森林。巨龙瞪着眼睛,恶狠狠地看着小精灵们,口中喷出熊熊火焰。\n\n小精灵们吓得浑身发抖,但他们并没有放弃。米洛再次提议大家一起对抗巨龙。于是,所有的精灵们团结一致,一起向巨龙发起了攻击。\n\n经过一番激战,小精灵们终于战胜了邪恶的巨龙。巨龙被打败后,恢复了原本善良的本性。它告诉小精灵们,它的名字叫卡洛,是这片森林的守护者。卡洛告诉小精灵们,只有团结一心,才能战胜强大的敌人。\n\n最后,卡洛带领着小精灵们回到了星球。从此,小精灵们再也不害怕黑暗和邪恶,他们学会了勇敢和团结。而那颗闪烁着奇异光芒的新星,也成为了他们心中永恒的回忆。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 445, 'prompt_tokens': 9, 'total_tokens': 454, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '6d412ea4184fe0551916dffeb39e0c82', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--08e882c7-3278-49e9-85f7-533b4d7bb0c5-0', usage_metadata={'input_tokens': 9, 'output_tokens': 445, 'total_tokens': 454, 'input_token_details': {}, 'output_token_details': {}})]

Async Stream 异步

在 LangChain LCEL(LangChain Expression Language)中,Async Stream(异步流式输出) 指的是在异步环境下,边生成边输出内容,适合需要实时响应和高并发的场景。它结合了“异步编程”与“流式输出”的优势,常用于 Web 服务、Jupyter Notebook、前端实时展示等。

async for s in chain.astream({"topic": "月亮"}):print(s.content, end="", flush=True)
从前,有一个古老的村庄,村子里的居民们相信月亮是他们的守护神。每个月圆之夜,月亮都会准时升起,照亮了整个天空,给村民们带来无尽的遐想和希望。在这个村子里,有一个聪明勇敢的小男孩,名叫小明。他非常喜欢观察天象,尤其是月亮的变化。每个月圆之夜,他都会爬上自家院子的屋顶,仰望那轮明亮的月亮,陷入深深的思索。有一天晚上,小明发现月亮似乎有些异样。它比往常更加明亮、更加圆润,仿佛在向人们传递着什么信息。小明决定去问问村里的长者,看看他们是否知道这是什么意思。长者们告诉小明,这轮月亮已经很久没有这样出现过过了。他们还告诉他,这是一个特殊的征兆,预示着村子将会迎来一件前所未有的好事。小明兴奋地跑回家,告诉父母和村里的人们这个好消息。然而,就在这时,村子上空突然出现了一层神秘的薄雾,将月亮遮住了。村民们开始恐慌,纷纷猜测这究竟是福是祸。小明决定去揭开这个谜团。他带上了一些干粮和水,悄悄地溜上了屋顶。他沿着月亮的轨迹寻找,终于来到了一个废弃的古老神庙。神庙里弥漫着一股神秘的气息,中央摆放着一个巨大的石台,石台上放着一枚金光闪闪的月亮。原来,这枚金月亮的出现是月亮女神送给村民们的祝福。她希望通过这种方式,让村民们明白,只要他们团结一心、共同努力,就一定能够克服困难,迎来更美好的未来。小明带着这个好消息回到了村子,村民们纷纷涌上街头,载歌载舞,庆祝这难得的喜事。从此,他们更加珍惜彼此的团结与友爱,共同为村子的繁荣和发展努力。而那轮明亮的月亮,也一直守护着这个村子,见证着村民们的幸福时光。每当月圆之夜,人们都会抬头仰望那轮美丽的月亮,感激它带来的好运与祝福。

Async Invoke

await chain.ainvoke({"topic": "月亮"})
AIMessage(content='从前,有一个古老的村庄,村子里的居民们相信月亮是他们的守护神。每天夜晚,他们都会仰望星空,默默祈祷,希望月亮能保佑他们的生活平安顺利。\n\n有一天晚上,村子里的小男孩小明悄悄地溜出家门,来到了村外的树林里。他抬头仰望着天空,发现今晚的月亮格外明亮,仿佛在向他招手。小明心生好奇,决定去探寻月亮的奥秘。\n\n他顺着月光走去,竟然发现了一个神秘的洞穴。洞穴里闪烁着奇异的光芒,小明觉得这里一定隐藏着什么秘密。于是,他鼓起勇气走进了洞穴。\n\n洞穴里,小明发现了一棵巨大的月亮树。树上挂满了晶莹剔透的月亮果实,每一个果实都散发着柔和的银光。原来,这棵月亮树是月亮的神圣之树,它结出的果实就是月亮果实。\n\n小明兴奋地摘下一个月亮果实,突然,果实发出一阵耀眼的光芒,将他带到了一个美丽的仙境。在那里,他遇到了月亮的守护神——一位美丽的女神。\n\n女神告诉小明,月亮果实具有神奇的力量,它可以实现持有者的愿望。然而,这股力量并非无止境,只有心地善良、无私奉献的人才能真正拥有它。\n\n小明明白了这个道理,他决定将月亮果实带回家,帮助村民们解决困难。回到村子后,小明将月亮果实分给了每一个人。村子里的人们因为有了月亮果实的祝福,生活变得更加美好。\n\n然而,好景不长。贪婪的村民们开始争夺月亮果实,企图独占这股力量。女神得知此事后,决定收回月亮果实,让村子恢复平静。\n\n在小明的帮助下,女神成功地收回了月亮果实。她告诉村民们,真正的幸福不在于拥有多少财富,而在于团结互助、互相关爱。从此,村子里的人们过上了幸福快乐的生活,而小明也成了村子的英雄。\n\n这个故事传遍了整个村子,人们始终铭记着那位美丽的女神和小明无私奉献的精神。每当夜晚来临,村民们都会仰望星空,感谢月亮带来的恩赐,同时也要铭记那些为了他人幸福而付出努力的英雄。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 460, 'prompt_tokens': 9, 'total_tokens': 469, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': 'b41791a8e77239345ee53907d715629d', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--3541a657-01e1-4b13-b7b1-30a1719caa84-0', usage_metadata={'input_tokens': 9, 'output_tokens': 460, 'total_tokens': 469, 'input_token_details': {}, 'output_token_details': {}})

异步获取中间步骤

在 LangChain LCEL(LangChain Expression Language)中,异步获取中间步骤,通常指在链式执行过程中,能够实时、异步地获取每个子步骤(如检索、生成等)的中间日志、输出或状态。这对于调试复杂链路、可视化执行过程、前端实时展示等非常有用。

from langchain_community.vectorstores import FAISS
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI
from langchain.embeddings.base import Embeddings
from pydantic import SecretStr
import os
import requests
from dotenv import load_dotenvload_dotenv()llm = ChatOpenAI(api_key=SecretStr(os.environ.get("HUNYUAN_API_KEY", "")),  # 混元 APIKeybase_url="https://api.hunyuan.cloud.tencent.com/v1",  # 混元 endpointmodel="hunyuan-lite",  # 模型名称temperature=0
)# 设置API配置
api_base = "https://api.hunyuan.cloud.tencent.com/v1"  # 腾讯混元OpenAI兼容endpoint
api_key = os.environ.get("HUNYUAN_API_KEY")# 定义腾讯混元Embeddings类
class HunyuanEmbeddings(Embeddings):def __init__(self, api_key, api_base, model="hunyuan-embedding"):self.api_key = api_keyself.api_base = api_baseself.model = model# 批量文本向量化方法def embed_documents(self, texts):url = f"{self.api_base}/embeddings"headers = {"Authorization": f"Bearer {self.api_key}","Content-Type": "application/json"}data = {"model": self.model,"input": texts}response = requests.post(url, headers=headers, json=data)result = response.json()print("混元 embedding 返回:", result)return [item["embedding"] for item in result["data"]]# 单条文本向量化方法def embed_query(self, text):return self.embed_documents([text])[0]template = """根据以下上下文回答问题:
{context}问题:{question}
"""prompt = ChatPromptTemplate.from_template(template)vectorstore = FAISS.from_texts(["小明在北京工作。"], embedding=HunyuanEmbeddings(api_key=api_key, api_base=api_base)
)retriever = vectorstore.as_retriever()retrieval_chain = ({"context": retriever.with_config(run_name="Docs"), "question": RunnablePassthrough()}| prompt| llm| StrOutputParser()
)
混元 embedding 返回: {'object': 'list', 'data': [{'index': 0, 'embedding': [0.01209259033203125, -0.0193939208984375, -0.00030994415283203125, -0.0340576171875, -0.0189971923828125, 0.0203704833984375, -3.0517578125e-05, -0.0119781494140625, -0.021148681640625, 0.0030384063720703125, -0.04266357421875, 0.052947998046875, -0.42919921875, 0.0034275054931640625, -0.01324462890625, -0.051727294921875, 0.04412841796875, 0.0007004737854003906, 0.0291900634765625, -0.003261566162109375, -0.0004372596740722656, -0.01039886474609375, -0.0206756591796875, -0.0209503173828125, -0.02117919921875, -0.021575927734375, -0.044036865234375, 0.0161590576171875, 0.0379638671875, -0.0227508544921875, -0.01666259765625, -6.443262100219727e-05, 0.040252685546875, 0.01690673828125, 0.044525146484375, 0.031768798828125, 0.03704833984375, 0.052032470703125, -0.031951904296875, -0.0010919570922851562, -0.043853759765625, 0.036834716796875, -0.03363037109375, -0.01776123046875, 0.0284576416015625, 0.0019664764404296875, -0.03631591796875, 0.0095672607421875, -0.021881103515625, 0.02056884765625, 0.05938720703125, 0.01983642578125, -0.032928466796875, -0.0254669189453125, 0.003131866455078125, 0.004497528076171875, -0.0281982421875, 0.044342041015625, 0.053497314453125, -0.04669189453125, -0.0081787109375, -0.03839111328125, 0.01491546630859375, 0.0143280029296875, 0.01392364501953125, 0.02191162109375, -0.0291900634765625, -0.0022106170654296875, -0.01062774658203125, -0.02862548828125, 0.045135498046875, -0.01090240478515625, 0.001689910888671875, -0.023956298828125, 0.0233154296875, 0.0289764404296875, -0.033447265625, -0.03851318359375, 0.06488037109375, 0.01383209228515625, 0.05218505859375, 0.01250457763671875, 0.01226806640625, 0.0291290283203125, -0.025421142578125, -0.0149993896484375, 0.0007905960083007812, -0.005916595458984375, 0.01082611083984375, -0.034332275390625, 0.04962158203125, -0.00452423095703125, 0.0758056640625, 0.0115966796875, 0.017913818359375, 0.03155517578125, -0.010467529296875, -0.026458740234375, -0.06298828125, 0.0191802978515625, 0.0214691162109375, 0.037139892578125, 0.01293182373046875, 0.0119476318359375, 0.0284881591796875, -0.034423828125, 0.01776123046875, -0.0386962890625, 0.0070343017578125, -0.026031494140625, -0.0106353759765625, -0.0151824951171875, -0.007015228271484375, 0.049072265625, 0.0028514862060546875, 0.0219879150390625, 0.012725830078125, 0.0670166015625, 0.008209228515625, -0.02276611328125, -0.0237274169921875, 0.04095458984375, 0.0003616809844970703, 0.01171875, -0.04052734375, 0.003063201904296875, 0.00495147705078125, 0.036529541015625, -0.0341796875, 0.00042939186096191406, -0.0313720703125, -0.053009033203125, -0.037689208984375, 0.029998779296875, -0.02655029296875, -0.005039215087890625, -0.008819580078125, 0.0015134811401367188, 0.04681396484375, 0.04010009765625, -0.01001739501953125, -0.0082244873046875, -0.01137542724609375, 0.006317138671875, 0.0193023681640625, -0.0302276611328125, -0.01371002197265625, -0.0092315673828125, 0.042938232421875, 0.00331878662109375, 0.032562255859375, -0.00418853759765625, -0.046539306640625, -0.036590576171875, -0.001926422119140625, -0.00885772705078125, -0.0197906494140625, -0.0011920928955078125, 0.047149658203125, -0.0115814208984375, -0.0169830322265625, -0.0269622802734375, -0.0018310546875, 0.057464599609375, -0.0246429443359375, 0.0106964111328125, -0.01073455810546875, 0.052276611328125, -0.022003173828125, 0.004573822021484375, 0.01090240478515625, -0.034149169921875, 0.020233154296875, 0.040252685546875, -0.02227783203125, -0.055908203125, -0.0109710693359375, -0.0340576171875, 0.0016393661499023438, -0.042572021484375, -0.021026611328125, 0.0298004150390625, -0.01172637939453125, 0.0167388916015625, 0.0239410400390625, 0.0010385513305664062, 0.042388916015625, -0.0278167724609375, -0.0227813720703125, 0.00955963134765625, -0.042388916015625, -0.0521240234375, 0.04034423828125, 0.0201416015625, 0.014617919921875, 0.04705810546875, -0.051544189453125, 0.01555633544921875, 0.00763702392578125, 0.00048661231994628906, -0.01361846923828125, 0.01568603515625, 0.004795074462890625, -0.0181427001953125, -0.01397705078125, -0.03997802734375, -0.0302581787109375, -0.050506591796875, 0.03125, 0.011444091796875, 0.043487548828125, -0.002655029296875, -0.04840087890625, 0.007236480712890625, -0.0017452239990234375, -0.0255584716796875, -0.0190887451171875, 0.005886077880859375, -0.006229400634765625, 0.01045989990234375, -0.045074462890625, -0.00995635986328125, 0.0161590576171875, -0.04144287109375, 0.049407958984375, -0.014862060546875, -0.0313720703125, -0.0086822509765625, 0.0258331298828125, 0.01213836669921875, -0.0231170654296875, -0.0364990234375, 0.0135955810546875, 0.0192718505859375, 0.04449462890625, 0.034515380859375, 0.0191802978515625, -0.0251922607421875, -0.03411865234375, -0.00493621826171875, 0.007503509521484375, 0.023651123046875, -0.0149383544921875, 0.002010345458984375, 0.032684326171875, 0.0338134765625, 0.00412750244140625, -0.025970458984375, 0.0241241455078125, 0.0034637451171875, -0.0182952880859375, 0.03460693359375, -0.05511474609375, -0.0311431884765625, -0.0298309326171875, -0.00495147705078125, -0.045989990234375, -0.0280303955078125, -0.00041675567626953125, -0.024017333984375, 0.007411956787109375, -0.03802490234375, -0.01537322998046875, -0.0172119140625, 0.005558013916015625, 0.033111572265625, -0.013275146484375, 0.0304412841796875, -0.0180816650390625, 0.044464111328125, -0.0209808349609375, -0.009033203125, -0.0212554931640625, -0.1011962890625, 0.01554107666015625, 0.01229095458984375, -0.0180816650390625, 0.04022216796875, 0.0460205078125, -0.004730224609375, -0.0184326171875, 0.010772705078125, 0.00012123584747314453, -0.056060791015625, -0.05865478515625, 0.034423828125, 0.01555633544921875, -0.045989990234375, 0.034088134765625, -0.016326904296875, 0.0012140274047851562, -0.0084228515625, 0.015380859375, 0.052093505859375, 0.0250091552734375, 0.02862548828125, -0.024444580078125, -0.00411224365234375, -0.01141357421875, -0.004482269287109375, -0.034942626953125, -0.00859832763671875, 0.03082275390625, -0.0225677490234375, 0.00030112266540527344, 0.01412200927734375, -0.0021953582763671875, -0.03936767578125, 0.049285888671875, 0.0026187896728515625, -0.0259552001953125, -0.03021240234375, 0.024688720703125, 0.0270538330078125, -0.007465362548828125, 0.002635955810546875, 0.006317138671875, -0.0234832763671875, 0.0292205810546875, 0.0088653564453125, 0.024749755859375, -0.0207061767578125, -0.01100921630859375, 0.021392822265625, 0.01268768310546875, 0.01526641845703125, -0.0259552001953125, -0.033294677734375, -0.018798828125, 0.001789093017578125, 0.021392822265625, -0.01427459716796875, -0.0009794235229492188, 0.0285491943359375, 0.004413604736328125, -0.036346435546875, 0.015411376953125, -0.0517578125, 0.029937744140625, 0.037109375, 0.019073486328125, -0.005168914794921875, -0.0020503997802734375, -0.03106689453125, -0.0127716064453125, 0.04779052734375, -0.035064697265625, -0.0183868408203125, -0.0227203369140625, -0.003681182861328125, 0.00933074951171875, -0.01139068603515625, -0.039825439453125, -0.0989990234375, -0.0008111000061035156, -0.022369384765625, -0.0261077880859375, 0.01035308837890625, 0.000682830810546875, 0.034423828125, -0.045989990234375, 0.02337646484375, -0.027374267578125, 0.0322265625, -0.018524169921875, 0.00994110107421875, -0.0025844573974609375, -0.0235443115234375, -0.049346923828125, -0.07208251953125, -0.04510498046875, 0.00159454345703125, -0.032379150390625, -0.0077056884765625, 0.048736572265625, 0.003665924072265625, -0.00098419189453125, 0.00988006591796875, -0.0160675048828125, -0.0034637451171875, -0.005741119384765625, -0.01435089111328125, 0.03521728515625, 0.00853729248046875, 0.01216888427734375, 0.0181732177734375, -0.004596710205078125, -0.0247802734375, -0.04168701171875, -0.0068817138671875, -0.0194244384765625, 0.017608642578125, 0.0214385986328125, 0.00400543212890625, 0.0073089599609375, -0.032928466796875, -0.041229248046875, -0.03662109375, 0.009124755859375, 0.0205078125, 0.029052734375, 0.0284881591796875, -0.0347900390625, 0.01727294921875, -0.005859375, -0.00984954833984375, -0.0036144256591796875, 0.0010900497436523438, 0.0063323974609375, -0.01262664794921875, -0.042510986328125, 0.010955810546875, -0.0202178955078125, -0.01345062255859375, 0.0238800048828125, -0.013092041015625, 0.0224151611328125, 0.04205322265625, -0.013519287109375, 0.015655517578125, 0.02496337890625, -0.003719329833984375, -1.2695789337158203e-05, -0.0113677978515625, -0.016021728515625, 0.028350830078125, 0.03179931640625, 0.0274505615234375, -0.0172119140625, 0.0297698974609375, -0.0200042724609375, -0.016326904296875, -0.010467529296875, -0.02557373046875, -0.0352783203125, 0.014404296875, -0.0017976760864257812, -0.024627685546875, 0.013275146484375, 0.01329803466796875, -0.00820159912109375, 0.016265869140625, -0.0162353515625, 0.03399658203125, -0.037322998046875, 0.036651611328125, -0.020660400390625, 0.0267181396484375, 0.04290771484375, -0.0229644775390625, -0.0195465087890625, 0.0233612060546875, 0.0019741058349609375, -0.046905517578125, 0.01259613037109375, 0.0246429443359375, 0.0537109375, 0.043182373046875, 0.033477783203125, 0.0224609375, -0.01319122314453125, 0.0010786056518554688, 0.033447265625, -0.0280609130859375, -0.030853271484375, -0.0261383056640625, -0.00569915771484375, -0.0303192138671875, -0.00937652587890625, -0.005603790283203125, -0.046173095703125, 0.05938720703125, 0.006778717041015625, 0.00775146484375, 0.003215789794921875, -0.005985260009765625, 0.0828857421875, -0.070068359375, -0.0049896240234375, -0.043609619140625, 0.0357666015625, 0.0003581047058105469, 0.0041351318359375, -0.0258331298828125, 0.0036220550537109375, -0.040313720703125, -0.0345458984375, 0.0479736328125, -0.0604248046875, 9.113550186157227e-05, -0.017547607421875, 0.034088134765625, 0.0210723876953125, -0.050506591796875, -0.0298004150390625, -0.019744873046875, 0.037353515625, 0.0169677734375, -0.0164642333984375, 0.036865234375, -0.032989501953125, -0.0019092559814453125, -0.032745361328125, -0.042633056640625, 0.0110931396484375, -0.04888916015625, -0.0157623291015625, 0.01094818115234375, -0.046844482421875, 0.01082611083984375, -0.0274200439453125, -0.021087646484375, -0.0237579345703125, -0.0240936279296875, -0.034332275390625, -0.001373291015625, 0.0255584716796875, -0.03118896484375, 0.0001080632209777832, -0.0278778076171875, -0.021697998046875, -0.0313720703125, 0.0296173095703125, -0.038818359375, -0.0012187957763671875, -0.01177978515625, 0.0222320556640625, 0.0084991455078125, 0.016143798828125, -0.0137481689453125, -0.01296234130859375, -0.01192474365234375, -0.01171112060546875, 0.00673675537109375, 0.0080108642578125, -0.029022216796875, -0.0004096031188964844, 0.002471923828125, 0.04876708984375, 0.0218048095703125, 0.0196685791015625, 0.047943115234375, 0.0335693359375, -0.01397705078125, 0.01308441162109375, -0.025543212890625, 0.007030487060546875, 0.041961669921875, -0.003421783447265625, -0.0018463134765625, 0.00571441650390625, -0.00989532470703125, -0.00733184814453125, -0.024139404296875, 0.025054931640625, 0.019073486328125, -0.019989013671875, -0.0102996826171875, -0.003986358642578125, 0.0133514404296875, -0.0032596588134765625, -0.053863525390625, 0.01026153564453125, 0.01922607421875, 0.018280029296875, -0.00485992431640625, -0.0049591064453125, -0.05987548828125, -0.034210205078125, -0.0186767578125, -0.00864410400390625, -0.0007166862487792969, 0.0234375, 0.05889892578125, 0.0209808349609375, -0.036468505859375, -0.00896453857421875, 0.072998046875, -0.039154052734375, -0.01511383056640625, -0.038787841796875, 0.0282440185546875, -0.02532958984375, 0.00997161865234375, -0.01580810546875, -0.033599853515625, 0.03582763671875, -0.01512908935546875, -0.0058746337890625, 0.05328369140625, 0.01236724853515625, -0.008880615234375, 0.0007605552673339844, 0.030609130859375, 0.03271484375, 0.0183563232421875, 0.006145477294921875, -0.0014734268188476562, -0.029327392578125, -0.017486572265625, 0.04901123046875, 0.035736083984375, -0.033294677734375, -0.01690673828125, -0.0210113525390625, 0.0306549072265625, 0.0265960693359375, -0.0040283203125, 0.00923919677734375, 0.04443359375, 0.01482391357421875, 0.0241546630859375, -0.0209197998046875, 0.006595611572265625, -0.0545654296875, 0.0166015625, 0.05255126953125, 0.044342041015625, -0.034271240234375, 0.0160369873046875, 0.007564544677734375, -0.016754150390625, -0.057952880859375, -0.00522613525390625, 0.004970550537109375, 0.00643157958984375, -0.02618408203125, -0.018829345703125, -0.0018091201782226562, -0.04754638671875, 0.056060791015625, 0.007007598876953125, 0.00559234619140625, -0.015899658203125, -0.009368896484375, -0.013519287109375, 0.038177490234375, 0.01204681396484375, 0.047332763671875, -0.0199127197265625, 0.0189971923828125, -0.00446319580078125, -0.019775390625, -0.026580810546875, -0.040069580078125, 0.003719329833984375, 0.0272064208984375, -0.0017824172973632812, 0.0230865478515625, 0.003040313720703125, 0.00992584228515625, -0.0159912109375, -0.0625, 0.01165771484375, 0.0017805099487304688, -0.043365478515625, 0.00765228271484375, 0.005596160888671875, 0.031585693359375, 0.00646209716796875, 0.04840087890625, 0.01467132568359375, 0.01007843017578125, -0.029937744140625, -0.0174407958984375, -0.0157928466796875, 0.01320648193359375, 0.01149749755859375, 0.025146484375, -0.0144500732421875, -0.01080322265625, -0.0052337646484375, 0.040924072265625, -0.0467529296875, -0.01434326171875, -0.0254669189453125, -0.00021898746490478516, -0.00313568115234375, 0.03741455078125, 0.01493072509765625, -0.0072784423828125, 0.0187835693359375, 0.0150604248046875, 0.0013036727905273438, -0.0131072998046875, 0.0175323486328125, -0.040740966796875, 0.0250701904296875, -0.01678466796875, -0.004108428955078125, 0.0086212158203125, 0.05853271484375, -0.0103607177734375, -0.0168609619140625, 0.01053619384765625, -0.0295867919921875, 0.0289459228515625, -0.025543212890625, 0.0173187255859375, -0.0028057098388671875, 0.015869140625, -0.00057220458984375, -0.0516357421875, 0.01447296142578125, -0.0269317626953125, -0.00864410400390625, 0.0738525390625, -0.02655029296875, -0.054473876953125, 0.05511474609375, 0.05242919921875, -0.0243072509765625, -0.0279541015625, -0.03192138671875, 0.025634765625, 0.03814697265625, 0.04669189453125, 0.0537109375, 0.0347900390625, -0.006565093994140625, 0.01904296875, -0.0199432373046875, 0.0243682861328125, 0.0445556640625, 0.0174407958984375, -0.0875244140625, -0.0192108154296875, -0.01457977294921875, -0.033355712890625, 0.032379150390625, -0.042236328125, -0.0227813720703125, 0.024749755859375, 0.03125, -0.0160064697265625, 0.0007796287536621094, -0.028839111328125, -0.0178375244140625, -0.03155517578125, -0.03436279296875, 0.03802490234375, 0.00574493408203125, 0.0188751220703125, 0.06170654296875, -0.02685546875, -0.013275146484375, 0.038421630859375, -0.03558349609375, 0.00284576416015625, -0.00244903564453125, 0.00452423095703125, -0.039794921875, 0.0260467529296875, 0.033294677734375, 0.01102447509765625, 0.015716552734375, -0.05767822265625, 0.0008172988891601562, 0.0021820068359375, 0.0208740234375, -0.00727081298828125, 0.019561767578125, -0.024444580078125, 0.007015228271484375, 0.0027980804443359375, 0.018341064453125, -0.0009622573852539062, 0.05322265625, -0.0144500732421875, -0.006023406982421875, 0.006832122802734375, -0.0224609375, -0.0009136199951171875, 0.051025390625, 0.00536346435546875, -0.01959228515625, 0.0072784423828125, -0.01401519775390625, 0.025665283203125, 0.020111083984375, -0.0036487579345703125, 0.029449462890625, -0.0372314453125, -0.044952392578125, 0.0128936767578125, -0.0051422119140625, -0.023712158203125, -0.00041937828063964844, 0.0218353271484375, 0.042144775390625, -0.0248565673828125, -0.033203125, 0.0113525390625, 0.0265045166015625, 0.019500732421875, -0.052520751953125, 0.0244140625, 0.0036678314208984375, 0.0175323486328125, 0.081298828125, -0.0267486572265625, -0.00048613548278808594, 0.0170440673828125, 0.02081298828125, -0.0204925537109375, -0.0172119140625, 0.0318603515625, -0.02679443359375, 0.0209197998046875, 0.01158905029296875, -0.0278778076171875, -0.031219482421875, -0.0012197494506835938, 0.00435638427734375, -0.00820159912109375, 0.001148223876953125, 0.05596923828125, -0.0006055831909179688, -0.041259765625, -0.005741119384765625, 0.01258087158203125, -0.048248291015625, 0.02294921875, -0.07232666015625, 0.0259552001953125, -0.012176513671875, -0.006214141845703125, 0.022857666015625, -0.006900787353515625, 0.0135040283203125, -0.057464599609375, 0.0078582763671875, -0.020599365234375, 0.045166015625, -0.0207977294921875, -0.001041412353515625, -0.007068634033203125, -0.0506591796875, 0.0292205810546875, -0.052947998046875, -0.0269927978515625, 0.0001703500747680664, -0.05169677734375, 0.0013933181762695312, -0.028411865234375, 0.03131103515625, 0.02655029296875, 0.018890380859375, -0.0095672607421875, -0.024993896484375, 0.0296478271484375, -0.0005350112915039062, -0.0078582763671875, -0.0224151611328125, -0.03167724609375, -0.01085662841796875, 0.0294342041015625, -0.01427459716796875, -0.002117156982421875, -0.0194244384765625, 0.0333251953125, -0.03936767578125, -0.0198974609375, -0.00679779052734375, -0.0157928466796875, -0.0030670166015625, -0.00432586669921875, -0.00481414794921875, -0.018218994140625, -0.046051025390625, 0.0295562744140625, 0.061065673828125, -0.0163421630859375, -0.01172637939453125, -0.040283203125, -0.01372528076171875, 0.01384735107421875, -0.06573486328125, 0.06207275390625, -0.01557159423828125, -0.036773681640625, 0.02117919921875, 0.00774383544921875, 0.01641845703125, 0.0009131431579589844, 0.01416778564453125, -0.00972747802734375, -0.0125732421875, -0.0128173828125, -0.0027179718017578125, -0.00428009033203125, -0.054901123046875, 0.050506591796875, -0.061004638671875, -0.028594970703125, 0.01532745361328125, -0.029266357421875, -0.0160675048828125, 0.05120849609375, -0.0037631988525390625, 0.0121002197265625, 0.0008945465087890625, 0.0010890960693359375, 0.006011962890625, 0.01422119140625, 0.01226806640625, 0.0198516845703125, -0.0015668869018554688, 0.0202789306640625, -0.03338623046875, 0.01287078857421875, 0.036956787109375, -0.028839111328125, -0.0010433197021484375, -0.0285491943359375, -0.005962371826171875, -0.008819580078125, 0.015594482421875, -0.020233154296875, 0.004779815673828125, -0.063232421875, 0.02276611328125, 0.0183563232421875, -0.029998779296875, -0.0440673828125, 0.0211029052734375, -0.040130615234375, -0.0077667236328125, 7.56382942199707e-05, 0.040069580078125, -0.021636962890625, 0.002758026123046875, 0.03704833984375, -0.02178955078125, 0.11077880859375, -0.0174407958984375, 0.0166778564453125, 0.0012950897216796875, -0.0011758804321289062, -0.031982421875, -0.017181396484375, -0.027923583984375, 0.039642333984375, -0.005481719970703125, -0.027008056640625, -0.033660888671875, 0.0129547119140625, 0.034271240234375, 0.0150604248046875, 0.0018262863159179688, 0.023651123046875, 0.0161590576171875, -0.0133056640625, 0.028839111328125, -0.018524169921875, -0.0008554458618164062, 0.0011663436889648438, -0.007190704345703125, -0.01160430908203125, 0.02606201171875, -0.0076904296875, 0.035736083984375, -0.011505126953125, 0.030975341796875, -0.0198211669921875, -0.01220703125, 0.022735595703125, -0.024139404296875, 0.044647216796875, -0.0022602081298828125, 0.00923919677734375, 0.0399169921875, -0.0028209686279296875, -0.0284881591796875, 0.0389404296875, 0.07794189453125, -0.0015668869018554688, -0.0234527587890625, -0.0008902549743652344, 0.0011739730834960938, 0.0187225341796875, 0.009307861328125, 0.01090240478515625, 0.0229339599609375, 0.0131378173828125, 0.0168914794921875, -0.04266357421875, 0.04901123046875, 0.03204345703125, 0.022857666015625, 0.022674560546875, -0.03936767578125, -0.046600341796875, 0.06317138671875, 0.0020885467529296875, 0.01314544677734375, 0.01983642578125, 0.0301513671875, -0.0322265625, 0.0302276611328125, -0.0042724609375, 0.0009622573852539062, -0.0157623291015625, -0.0159149169921875, 0.02996826171875, -0.033294677734375, -0.004852294921875, -0.033660888671875, 0.0213775634765625, -0.0276336669921875, -0.00731658935546875, 0.0128173828125, 0.010955810546875, -0.0185089111328125, 0.016876220703125, -0.04083251953125, -0.003917694091796875, -0.061004638671875, 0.0190582275390625, -0.033599853515625, 0.046722412109375, 0.0423583984375, -0.005855560302734375, -0.01153564453125], 'object': 'embedding'}], 'model': 'hunyuan-embedding', 'usage': {'prompt_tokens': 7, 'total_tokens': 7}}
async for chunk in retrieval_chain.astream_log("小明在哪里工作?", include_names=["Docs"]
):print("-" * 40)print(chunk)
----------------------------------------
RunLogPatch({'op': 'replace','path': '','value': {'final_output': None,'id': '0f5b678a-8f58-4641-887a-f77875806f39','logs': {},'name': 'RunnableSequence','streamed_output': [],'type': 'chain'}})
----------------------------------------
RunLogPatch({'op': 'add','path': '/logs/Docs','value': {'end_time': None,'final_output': None,'id': 'e2e8bbf9-81f5-4585-9e9b-168cc5fea7ea','metadata': {'ls_embedding_provider': 'HunyuanEmbeddings','ls_retriever_name': 'vectorstore','ls_vector_store_provider': 'FAISS'},'name': 'Docs','start_time': '2025-07-14T13:14:23.771+00:00','streamed_output': [],'streamed_output_str': [],'tags': ['map:key:context', 'FAISS', 'HunyuanEmbeddings'],'type': 'retriever'}})
混元 embedding 返回: {'object': 'list', 'data': [{'index': 0, 'embedding': [0.0130767822265625, -0.0018110275268554688, 0.0224151611328125, -0.031494140625, -0.0210723876953125, 0.003986358642578125, 0.0019464492797851562, -0.07232666015625, -0.004791259765625, 0.023223876953125, -0.040435791015625, 0.042144775390625, -0.417236328125, 0.022186279296875, 0.005435943603515625, -0.056396484375, 0.036102294921875, -0.0006375312805175781, 0.0146026611328125, -0.023223876953125, -0.0294952392578125, -0.03717041015625, -0.020477294921875, -0.01287078857421875, -0.01087188720703125, -0.003582000732421875, -0.0304718017578125, -0.017364501953125, 0.0254974365234375, -0.00804901123046875, -0.0341796875, 0.0142669677734375, 0.030914306640625, 0.0228118896484375, 0.07012939453125, 0.0273895263671875, 0.0584716796875, 0.0546875, -0.01465606689453125, -0.007793426513671875, -0.020843505859375, 0.038482666015625, -0.042083740234375, -0.039581298828125, 0.043426513671875, -0.0156707763671875, -0.03179931640625, 0.00923919677734375, -0.0041046142578125, 0.03619384765625, 0.04180908203125, 0.0270538330078125, -0.039947509765625, -0.0242156982421875, 0.0031452178955078125, 0.005374908447265625, -0.03570556640625, 0.06304931640625, 0.05352783203125, -0.024810791015625, 0.015289306640625, -0.040374755859375, 0.0220947265625, 0.0012941360473632812, -0.0169830322265625, 0.0306854248046875, -0.0421142578125, 0.00858306884765625, -0.029541015625, -0.034088134765625, 0.0254669189453125, -0.034271240234375, -0.001697540283203125, -0.0357666015625, 0.049560546875, 0.031280517578125, -0.0214996337890625, -0.01293182373046875, 0.06329345703125, 0.022796630859375, 0.06951904296875, 0.025909423828125, 0.01560211181640625, 0.030181884765625, -0.01419830322265625, -0.04095458984375, -0.00487518310546875, -0.0018606185913085938, -0.0135650634765625, -0.0179901123046875, 0.0258026123046875, 0.0005517005920410156, 0.06842041015625, 0.0179595947265625, -0.01068115234375, 0.0096435546875, -0.0029048919677734375, -0.0215911865234375, -0.05126953125, 0.01453399658203125, 0.039398193359375, -0.01404571533203125, -0.0233001708984375, 0.0183258056640625, 0.035980224609375, -0.0301055908203125, 0.006984710693359375, -0.035430908203125, 0.01247406005859375, -0.04071044921875, -0.0160369873046875, 0.005207061767578125, 0.01479339599609375, 0.06378173828125, -0.00750732421875, 0.0340576171875, 0.0164947509765625, 0.076171875, 0.005924224853515625, -0.009307861328125, -0.008392333984375, 0.052490234375, 0.00682830810546875, 0.0018901824951171875, -0.0303497314453125, -0.046905517578125, -0.0212554931640625, 0.01947021484375, -0.0265350341796875, -0.0223541259765625, -0.00750732421875, -0.039703369140625, -0.030517578125, 0.0308685302734375, -0.035919189453125, -0.01308441162109375, -0.0009298324584960938, 0.0269927978515625, 0.0213470458984375, 0.0139007568359375, -0.0181732177734375, -0.0146942138671875, -0.0234222412109375, 0.029571533203125, 0.02984619140625, -0.01393890380859375, -0.041168212890625, -0.0027599334716796875, 0.033935546875, -0.00487518310546875, 0.0111846923828125, -0.0150909423828125, -0.0423583984375, -0.029144287109375, 0.00803375244140625, -0.01195526123046875, 0.01085662841796875, -0.0200958251953125, 0.02935791015625, -0.026092529296875, -0.016326904296875, -0.01439666748046875, 0.003841400146484375, 0.040496826171875, -0.0031280517578125, -0.0005497932434082031, -0.0108489990234375, 0.0231170654296875, -0.0145721435546875, 0.007106781005859375, 0.0279388427734375, -0.014678955078125, 0.044158935546875, 0.034393310546875, -0.02642822265625, -0.04803466796875, 0.002300262451171875, -0.005527496337890625, -0.022369384765625, -0.02313232421875, -0.00507354736328125, 0.03485107421875, -0.0035991668701171875, 0.0142669677734375, 0.032196044921875, -0.006988525390625, 0.036163330078125, -0.045562744140625, -0.01282501220703125, 0.0139923095703125, -0.0197601318359375, -0.0258636474609375, 0.056549072265625, 0.05828857421875, 0.033355712890625, 0.050018310546875, -0.0292510986328125, -0.0111236572265625, 0.0086669921875, -0.0021610260009765625, -0.0318603515625, 0.0167388916015625, 0.017181396484375, -0.0027523040771484375, -0.026580810546875, -0.035675048828125, -0.03790283203125, -0.047760009765625, 0.0015649795532226562, -0.0178985595703125, 0.038970947265625, -0.003627777099609375, -0.043487548828125, -0.003322601318359375, -0.0197601318359375, -0.0186614990234375, -0.0198822021484375, -0.00476837158203125, -0.0005331039428710938, 0.0054931640625, -0.054351806640625, -0.0343017578125, 0.007598876953125, -0.006969451904296875, 0.06103515625, -0.01369476318359375, -0.0288848876953125, -0.0178985595703125, 0.0240325927734375, 0.011260986328125, -0.01141357421875, -0.0560302734375, 0.011749267578125, 0.00870513916015625, 0.033935546875, 0.057769775390625, -0.007236480712890625, -0.036651611328125, -0.0303497314453125, 0.004032135009765625, 0.01288604736328125, 0.00019884109497070312, -0.0093994140625, 0.007495880126953125, 0.0322265625, 0.04217529296875, -0.027435302734375, -0.01471710205078125, 0.037200927734375, 0.00782012939453125, -0.007656097412109375, 0.026336669921875, -0.03369140625, -0.04473876953125, -0.0288848876953125, 0.0021514892578125, -0.025360107421875, -0.0204010009765625, 0.017547607421875, -0.030426025390625, 0.0244293212890625, -0.02264404296875, -0.00028967857360839844, -0.027801513671875, 0.00038909912109375, 0.038360595703125, 0.0182342529296875, 0.0286865234375, -0.0129547119140625, 0.027984619140625, -0.020660400390625, -0.01268768310546875, -0.040679931640625, -0.090087890625, -0.01203155517578125, 0.01174163818359375, -0.01128387451171875, 0.037750244140625, 0.05352783203125, -0.0034923553466796875, 0.008209228515625, 0.00569915771484375, -0.018768310546875, -0.07147216796875, -0.07830810546875, 0.0124969482421875, 0.0098876953125, -0.0614013671875, 0.0286102294921875, -0.033782958984375, -0.011474609375, 0.00765228271484375, 0.028472900390625, 0.051422119140625, 3.540515899658203e-05, 0.0231781005859375, -0.04296875, -0.00894927978515625, -0.0052032470703125, -0.01314544677734375, -0.047515869140625, -0.03802490234375, 0.040496826171875, -0.0108642578125, -0.0059661865234375, 0.01373291015625, 0.0218048095703125, -0.0311737060546875, 0.06341552734375, 0.003307342529296875, -0.0001901388168334961, -0.019500732421875, 0.0172119140625, 0.024139404296875, -0.0200347900390625, -0.01251983642578125, 0.0178985595703125, -0.0169830322265625, 0.020660400390625, -0.013092041015625, 0.042694091796875, -0.0220794677734375, -0.0014934539794921875, 0.0243072509765625, 0.01213836669921875, 0.00591278076171875, -0.01395416259765625, -0.0099029541015625, -0.0195770263671875, -0.006275177001953125, 0.016845703125, -0.0256195068359375, 0.0016813278198242188, 0.005397796630859375, -0.018951416015625, -0.041168212890625, 0.00647735595703125, -0.0308837890625, 0.02618408203125, 0.037353515625, 0.0318603515625, -0.0284576416015625, 0.0352783203125, -0.022613525390625, -0.001735687255859375, 0.0311737060546875, -0.03094482421875, 0.0034923553466796875, -0.0217437744140625, 0.0019350051879882812, 0.0036830902099609375, 0.0032100677490234375, -0.052764892578125, -0.08453369140625, 0.014068603515625, -0.0035152435302734375, -0.037322998046875, -0.0149993896484375, 0.01378631591796875, 0.04144287109375, -0.0499267578125, 0.02178955078125, -0.016448974609375, 0.0206146240234375, -0.032989501953125, 0.027618408203125, 0.0107574462890625, -0.0260467529296875, -0.07769775390625, -0.03802490234375, -0.0193328857421875, -0.019012451171875, -0.0377197265625, -0.0045166015625, 0.048065185546875, -0.0221099853515625, -0.0241241455078125, 0.018157958984375, 0.005336761474609375, 0.008880615234375, -0.0028667449951171875, 0.004825592041015625, 0.032867431640625, 0.0247650146484375, 0.003238677978515625, 0.007457733154296875, 0.0016126632690429688, -0.0328369140625, -0.06524658203125, -0.00978851318359375, -0.035552978515625, 0.0343017578125, 0.0323486328125, 0.0078125, 0.029876708984375, -0.047149658203125, -0.04559326171875, -0.04864501953125, 0.00524139404296875, 0.015380859375, 0.0187530517578125, 0.054718017578125, -0.034698486328125, 0.0299835205078125, -0.00800323486328125, -0.01806640625, 0.002857208251953125, 0.01378631591796875, 3.844499588012695e-05, -0.023834228515625, -0.033050537109375, -0.0035858154296875, -0.01849365234375, -0.003387451171875, 0.03680419921875, -0.0294342041015625, 0.0031223297119140625, 0.0263214111328125, -0.0176849365234375, -0.0024242401123046875, 0.01158905029296875, 0.004795074462890625, 0.01430511474609375, -0.01166534423828125, -0.0211181640625, 0.02801513671875, 0.023101806640625, 0.01727294921875, 0.004444122314453125, 0.04132080078125, -0.04022216796875, -0.0031871795654296875, -0.0181884765625, -0.0264739990234375, -0.044952392578125, 0.037567138671875, -0.0208892822265625, -0.0192718505859375, 0.005138397216796875, 0.0136260986328125, 0.01396942138671875, 0.004901885986328125, -0.0284271240234375, 0.0197601318359375, -0.0308380126953125, 0.0478515625, -0.0113677978515625, 0.007282257080078125, 0.007415771484375, 0.00756072998046875, -0.0291290283203125, 0.022735595703125, -0.0010366439819335938, -0.041473388671875, 0.032012939453125, 0.0343017578125, 0.0303497314453125, 0.01788330078125, 0.00653076171875, 0.048370361328125, 0.0073394775390625, 0.004638671875, 0.03460693359375, -0.0218658447265625, -0.022430419921875, -0.020843505859375, -0.01580810546875, -0.056060791015625, -0.00505828857421875, 0.0004470348358154297, -0.04437255859375, 0.06988525390625, 0.00960540771484375, 0.00926971435546875, 0.018402099609375, 0.009552001953125, 0.08538818359375, -0.039276123046875, -0.0139312744140625, -0.058197021484375, 0.050628662109375, -0.00653839111328125, 0.0002872943878173828, -0.0047149658203125, 0.018829345703125, -0.06109619140625, -0.0276947021484375, 0.0279388427734375, -0.063232421875, 0.007801055908203125, -0.018646240234375, 0.01377105712890625, 0.0207672119140625, -0.0287933349609375, -0.046112060546875, -0.0178375244140625, 0.032196044921875, -0.0014743804931640625, 0.00026106834411621094, 0.051605224609375, -0.042236328125, 0.00830078125, -0.02618408203125, -0.047637939453125, 0.0194549560546875, -0.040313720703125, -0.0067291259765625, 0.002490997314453125, -0.05706787109375, 0.0171356201171875, -0.0091552734375, -0.01739501953125, -0.051605224609375, -0.033447265625, -0.044677734375, -0.0171966552734375, 0.023651123046875, -0.0177001953125, 0.019927978515625, -0.031097412109375, -0.0207672119140625, -0.045989990234375, 0.00937652587890625, -0.0216827392578125, -0.0152740478515625, -0.023651123046875, -0.0009474754333496094, 0.02728271484375, 0.0229034423828125, -0.01033782958984375, -0.0094451904296875, 0.0018558502197265625, 0.01276397705078125, 0.00328826904296875, 0.01375579833984375, -0.043701171875, -0.012176513671875, 0.0225372314453125, 0.0254058837890625, 0.0278778076171875, 0.0218963623046875, 0.04156494140625, 0.034637451171875, -0.003963470458984375, 0.0085601806640625, -0.0222320556640625, -0.002254486083984375, 0.04620361328125, -0.00040650367736816406, 0.01332855224609375, 0.0092926025390625, -0.018402099609375, -0.021881103515625, -0.0187835693359375, 0.0176544189453125, -0.00627899169921875, -0.00548553466796875, -0.00936126708984375, 0.01541900634765625, -0.00911712646484375, 0.009674072265625, -0.039947509765625, 0.0054779052734375, 0.0198516845703125, 0.00043201446533203125, 0.01055908203125, 0.0008616447448730469, -0.0718994140625, -0.052825927734375, 0.00021219253540039062, -0.01268768310546875, -0.01849365234375, -0.003566741943359375, 0.020416259765625, -0.002101898193359375, -0.01280975341796875, -0.0104217529296875, 0.08477783203125, -0.040771484375, -0.0158843994140625, -0.0472412109375, 0.0247039794921875, -0.030731201171875, 0.0017995834350585938, -0.0104522705078125, -0.03533935546875, 0.0545654296875, -0.002105712890625, -0.01021575927734375, 0.036468505859375, -0.006378173828125, 0.00501251220703125, -0.00029087066650390625, 0.037689208984375, 0.0241241455078125, 0.0160064697265625, 0.006061553955078125, 0.0183563232421875, -0.009979248046875, -0.020263671875, 0.07000732421875, 0.034027099609375, -0.0157470703125, -0.033355712890625, -0.000732421875, 0.0106964111328125, 0.03167724609375, 0.007274627685546875, 0.00894927978515625, 0.052947998046875, -0.0178070068359375, 0.038238525390625, -0.032501220703125, -0.0035533905029296875, -0.0294036865234375, -0.0210723876953125, 0.023651123046875, 0.0357666015625, -0.01395416259765625, 0.0125579833984375, 0.00783538818359375, -0.01165008544921875, -0.0621337890625, 0.00292205810546875, 0.01401519775390625, 0.0102996826171875, -0.0296173095703125, -0.030548095703125, 0.0214996337890625, -0.0426025390625, 0.049163818359375, -0.0029888153076171875, -0.01258087158203125, -0.014495849609375, 0.006092071533203125, -0.0221099853515625, 0.040435791015625, -0.000782012939453125, 0.0634765625, -0.0185699462890625, 0.0194244384765625, -0.004909515380859375, 0.0020599365234375, -0.01324462890625, -0.029144287109375, 4.982948303222656e-05, 0.025543212890625, -0.00749969482421875, 0.04443359375, 0.0023403167724609375, 0.008026123046875, 0.0172119140625, -0.03338623046875, 0.002056121826171875, -0.01373291015625, -0.059814453125, 0.01227569580078125, -0.0249481201171875, 0.00554656982421875, 0.0143585205078125, 0.044464111328125, 0.01953125, 0.0036640167236328125, -0.0282745361328125, -0.01215362548828125, -0.0023136138916015625, 0.025634765625, 0.031768798828125, 0.03009033203125, -0.00860595703125, -0.0128936767578125, 0.01349639892578125, 0.0433349609375, -0.02764892578125, 0.0061187744140625, -0.0106353759765625, -0.004482269287109375, 0.01050567626953125, 0.0250701904296875, 0.0038967132568359375, 0.0133056640625, 0.00817108154296875, 0.0286865234375, 0.034454345703125, -0.00847625732421875, 0.037322998046875, -0.01922607421875, 0.045745849609375, -0.034881591796875, -0.0084228515625, -0.00991058349609375, 0.051910400390625, -0.0048065185546875, -0.01316070556640625, 0.019256591796875, -0.029541015625, 0.00554656982421875, -0.032318115234375, 0.00843048095703125, 0.01439666748046875, 0.017608642578125, -0.010040283203125, -0.053741455078125, 0.024505615234375, -0.00933837890625, 0.00823974609375, 0.06634521484375, -0.0269012451171875, -0.0220184326171875, 0.02294921875, 0.03802490234375, -0.012451171875, -0.040496826171875, -0.0223541259765625, 0.0423583984375, 0.0123443603515625, 0.032806396484375, 0.044525146484375, 0.024078369140625, 0.026580810546875, -0.005584716796875, -0.033233642578125, 0.04473876953125, 0.02935791015625, 0.007480621337890625, -0.08331298828125, -0.0121307373046875, -0.04046630859375, -0.0286865234375, 0.03717041015625, -0.06085205078125, -0.0220184326171875, 0.042816162109375, 0.043304443359375, -0.0170135498046875, 0.00562286376953125, -0.0306243896484375, 0.0061492919921875, -0.0357666015625, -0.04541015625, 0.035614013671875, -7.516145706176758e-05, 0.01953125, 0.04449462890625, -0.02099609375, 0.008392333984375, 0.0391845703125, -0.0132598876953125, -0.0167083740234375, 0.0004546642303466797, -0.018829345703125, -0.043975830078125, 0.01910400390625, 0.0252838134765625, 0.01335906982421875, 0.005718231201171875, -0.02923583984375, 0.00928497314453125, 0.01029205322265625, 0.0243072509765625, 0.015838623046875, 0.021209716796875, -0.0116424560546875, 0.0143280029296875, -0.035614013671875, 0.02301025390625, 0.0149383544921875, 0.04571533203125, -0.01397705078125, -0.0006127357482910156, 0.00789642333984375, -0.0028972625732421875, -0.0033855438232421875, 0.048065185546875, 0.010101318359375, -0.0275421142578125, -0.00897216796875, 0.006977081298828125, 0.020904541015625, 0.0269775390625, 0.01264190673828125, 0.0399169921875, -0.04095458984375, -0.062408447265625, 0.045654296875, 0.02203369140625, 0.004161834716796875, 0.01922607421875, 0.0235595703125, 0.03057861328125, -0.0380859375, -0.0156097412109375, -0.004364013671875, 0.037109375, 0.024688720703125, -0.042724609375, 0.01290130615234375, 0.0220794677734375, 0.0218505859375, 0.07025146484375, -0.0275726318359375, 0.028656005859375, 0.024749755859375, 0.010040283203125, -0.02288818359375, -0.029541015625, 0.044097900390625, -0.038726806640625, 0.02166748046875, 0.0035953521728515625, -0.0318603515625, -0.017425537109375, 0.002178192138671875, -0.0012149810791015625, -0.00988006591796875, -0.0161895751953125, 0.0264129638671875, -0.0156707763671875, -0.05535888671875, -0.00737762451171875, -0.00795745849609375, -0.042694091796875, 5.960464477539062e-07, -0.06573486328125, 0.00885009765625, 0.0095062255859375, -0.015289306640625, -0.001697540283203125, 0.010894775390625, 0.0048675537109375, -0.049530029296875, 0.0187225341796875, -0.0242462158203125, 0.040130615234375, -0.0450439453125, -0.0016202926635742188, -0.016143798828125, -0.046295166015625, 0.052032470703125, -0.055816650390625, -0.0236358642578125, 0.0250701904296875, -0.0231781005859375, 0.00576019287109375, -0.03192138671875, 0.04083251953125, 0.0121307373046875, 0.0233917236328125, -0.038848876953125, -0.026580810546875, 0.0132293701171875, 0.003055572509765625, -0.00751495361328125, -0.0272064208984375, -0.043701171875, -0.00989532470703125, 0.00852203369140625, 0.0165863037109375, -0.01139068603515625, -0.0223541259765625, 0.04278564453125, -0.033905029296875, 0.004062652587890625, 0.0032634735107421875, 0.0023250579833984375, 0.0038051605224609375, -0.0156097412109375, -0.0170745849609375, -5.340576171875e-05, -0.029998779296875, 0.0229644775390625, 0.05767822265625, -0.0238494873046875, -0.0045928955078125, -0.046875, -0.0129241943359375, 0.041412353515625, -0.05462646484375, 0.0596923828125, -0.0113677978515625, -0.021759033203125, 0.0199127197265625, 0.025115966796875, 0.01824951171875, -3.147125244140625e-05, 0.02313232421875, -0.0161895751953125, 0.0159759521484375, -0.0243377685546875, -0.005077362060546875, -0.0209503173828125, -0.053741455078125, 0.05328369140625, -0.0215606689453125, -0.049285888671875, 0.0012760162353515625, -0.017181396484375, -0.0207366943359375, 0.037689208984375, 0.00852203369140625, -0.01012420654296875, -0.00499725341796875, -0.008270263671875, -0.02099609375, 0.0218353271484375, 0.00946807861328125, 0.0116729736328125, -0.014678955078125, 0.01551055908203125, -0.019012451171875, 0.013397216796875, 0.026336669921875, -0.032501220703125, -0.007671356201171875, -0.0212554931640625, 0.00858306884765625, -0.012725830078125, 0.01358795166015625, -0.0230712890625, -0.002979278564453125, -0.046966552734375, 0.031707763671875, 0.021697998046875, -0.032989501953125, -0.042572021484375, 0.033905029296875, -0.061920166015625, -0.005321502685546875, 0.0061492919921875, 0.005336761474609375, -0.008880615234375, -0.0082244873046875, 0.019683837890625, -0.01204681396484375, 0.10498046875, -0.00534820556640625, 0.018707275390625, 0.01739501953125, -0.006893157958984375, -0.0136566162109375, -0.0196990966796875, -0.045196533203125, 0.0157318115234375, -0.0225372314453125, -0.0116729736328125, -0.0256500244140625, 0.00687408447265625, 0.0169219970703125, 0.0270843505859375, 0.0204925537109375, 0.032012939453125, 0.0240631103515625, -0.013092041015625, 0.00356292724609375, -0.0006046295166015625, 0.0081024169921875, -0.01751708984375, -0.0043182373046875, -0.0067901611328125, 0.02532958984375, -0.026397705078125, 0.0232086181640625, -0.03253173828125, 0.0236358642578125, 0.01174163818359375, 0.0008869171142578125, 0.041259765625, -0.0007977485656738281, 0.031036376953125, -0.0021610260009765625, -0.0218505859375, 0.0184783935546875, 0.017303466796875, -0.018585205078125, 0.0311279296875, 0.06585693359375, -0.020111083984375, -0.0201568603515625, -0.0053863525390625, -0.0006642341613769531, 0.0136566162109375, 0.0145721435546875, -0.01454925537109375, 0.00916290283203125, 0.01995849609375, 0.005290985107421875, -0.037261962890625, 0.041961669921875, 0.009857177734375, 0.0267486572265625, 0.00806427001953125, -0.0458984375, -0.031524658203125, 0.049591064453125, 0.0281982421875, -0.0216827392578125, 0.01812744140625, 0.01837158203125, -0.0240325927734375, 0.0445556640625, -0.006511688232421875, -0.0156402587890625, -0.044036865234375, -0.041473388671875, 0.04119873046875, -0.054412841796875, 0.020050048828125, -0.027679443359375, 0.0147705078125, -0.0328369140625, -0.012847900390625, 0.01099395751953125, 0.0110931396484375, 0.01229095458984375, 0.016571044921875, -0.03167724609375, -0.00847625732421875, -0.040435791015625, 0.0005779266357421875, -0.048309326171875, 0.0201263427734375, 0.01508331298828125, -0.01690673828125, -0.0247344970703125], 'object': 'embedding'}], 'model': 'hunyuan-embedding', 'usage': {'prompt_tokens': 7, 'total_tokens': 7}}
----------------------------------------
RunLogPatch({'op': 'add','path': '/logs/Docs/final_output','value': {'documents': [Document(id='9f1d2dad-16fd-4870-bb35-3d47c224c680', metadata={}, page_content='小明在北京工作。')]}},{'op': 'add','path': '/logs/Docs/end_time','value': '2025-07-14T13:14:24.309+00:00'})
----------------------------------------
RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': '小'},{'op': 'replace', 'path': '/final_output', 'value': '小'})
----------------------------------------
RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': '明'},{'op': 'replace', 'path': '/final_output', 'value': '小明'})
----------------------------------------
RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': '在北京'},{'op': 'replace', 'path': '/final_output', 'value': '小明在北京'})
----------------------------------------
RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': '工作'},{'op': 'replace', 'path': '/final_output', 'value': '小明在北京工作'})
----------------------------------------
RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': '。'},{'op': 'replace', 'path': '/final_output', 'value': '小明在北京工作。'})
----------------------------------------
RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': ''})

并行支持

在 LangChain LCEL(LangChain Expression Language)中,并行支持 指的是可以同时(并发)执行多个子链(chain)或任务,大幅提升处理效率,适合多任务生成、批量推理、复杂流程等场景。

from langchain_core.runnables import RunnableParallel, RunnablePassthroughchain1 = ChatPromptTemplate.from_template("请讲一个关于{topic}的故事。") | llm
chain2 = (ChatPromptTemplate.from_template("请写一句关于{topic}的句子。") | llm
)combined = RunnableParallel({"story": chain1, "sentence": chain2})
%%time
chain1.invoke({"topic": "月亮"})
CPU times: user 6.64 ms, sys: 3.06 ms, total: 9.69 ms
Wall time: 3.95 s
AIMessage(content='从前,有一个古老的村庄,村子里的居民们相信月亮是他们的守护神。每个月圆之夜,月亮都会准时升起,照亮了整个天空,给村民们带来无尽的遐想和希望。\n\n在这个村子里,有一个聪明勇敢的小男孩,名叫小明。他非常喜欢观察天象,尤其是月亮的变化。每个月圆之夜,他都会爬上自家院子的屋顶,仰望那轮明亮的月亮,陷入深深的思索。\n\n有一天晚上,小明发现月亮似乎有些异样。它比往常更加明亮、更加圆润,仿佛在向人们传递着什么信息。小明决定去问问村里的长者,看看他们是否知道这是什么意思。\n\n长者们告诉小明,这是一个古老的传说。相传,在很久以前,月亮曾经被一位邪恶的巫师诅咒,变得暗淡无光。后来,一位善良的仙女为了拯救月亮,历经千辛万苦,终于找到了解除诅咒的方法。在月圆之夜,她会在月光下祈祷,用她的爱心驱散巫师的黑暗力量,让月亮重新焕发生机。\n\n小明听完这个故事,心中充满了好奇和敬佩。他决定在月圆之夜,也像仙女一样,为月亮祈祷,希望能够驱散巫师的黑暗力量,让月亮重新焕发出美丽的光芒。\n\n月圆之夜到了,小明爬上屋顶,仰望着那轮明亮的月亮,心中默默祈祷。就在这时,他突然感觉到一股温暖的力量从心底涌出,直通月亮。他惊讶地发现,月亮的光芒变得更加明亮,仿佛在回应着他的祝福。\n\n从此以后,每当月圆之夜,小明都会为月亮祈祷,而月亮也总是如期而至,照亮了整个天空。村民们看到了这一幕,都纷纷感叹小明的善良和勇气,感激月亮赐予他们的光明与希望。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 379, 'prompt_tokens': 9, 'total_tokens': 388, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '3bcf36fb464a325fc59249012acbae52', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--43172fba-24e2-4061-b83b-adbdd058e1f6-0', usage_metadata={'input_tokens': 9, 'output_tokens': 379, 'total_tokens': 388, 'input_token_details': {}, 'output_token_details': {}})
%%time
chain2.invoke({"topic": "太阳"})
CPU times: user 6.12 ms, sys: 3.53 ms, total: 9.65 ms
Wall time: 1.17 s
AIMessage(content='太阳是我们太阳系的中心恒星,提供了地球上所需的热量和光线。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 16, 'prompt_tokens': 10, 'total_tokens': 26, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': 'acf79c547bf92ae612dd0e3de1e4aded', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--ae2af093-fc34-494c-930d-81497e95b8bf-0', usage_metadata={'input_tokens': 10, 'output_tokens': 16, 'total_tokens': 26, 'input_token_details': {}, 'output_token_details': {}})

并行执行

%%time
combined.invoke({"topic": "月亮"})
CPU times: user 10.9 ms, sys: 4.88 ms, total: 15.8 ms
Wall time: 4.62 s
{'story': AIMessage(content='从前,有一个古老的村庄,村子里的居民们相信月亮是他们的守护神。每个月圆之夜,月亮都会准时升起,照亮了整个天空,给村民们带来无尽的遐想和希望。\n\n在这个村子里,有一个聪明勇敢的小男孩,名叫小明。他非常喜欢观察天象,尤其是月亮的变化。每个月圆之夜,他都会爬上自家院子的屋顶,仰望那轮明亮的月亮,陷入深深的思索。\n\n有一天晚上,小明发现月亮似乎有些异样。它比往常更加明亮、更加圆润,仿佛在向人们传递着什么信息。小明决定去问问村里的长者,看看他们是否知道这是什么意思。\n\n长者们告诉小明,这是一个古老的传说。相传,在很久以前,月亮曾经被一位邪恶的巫师诅咒,变得暗淡无光。后来,一位善良的仙女为了拯救月亮,历经千辛万苦,终于找到了解除诅咒的方法。在月圆之夜,月亮会恢复原来的光彩,而仙女也会现身帮助人们。\n\n小明听完这个故事,心中充满了好奇和敬仰。他决定在月圆之夜守候在月亮下,看看是否有仙女出现。当晚,月圆如盘,银光洒满大地。小明躺在床上,透过窗户望着那轮明月,心中默默祈祷。\n\n突然,一道柔和的光芒洒在小明的脸上,他睁开眼睛,惊喜地发现月亮竟然变成了一个美丽的仙女!仙女微笑着对小明说:“谢谢你一直以来的信任和喜爱,我是月宫仙子。现在,我需要你的帮助,共同拯救被诅咒的月亮。”\n\n小明激动地答应了仙子的请求,他们一起开始了寻找解除诅咒方法的旅程。经过一番努力,他们终于找到了那颗拥有神奇力量的宝石。仙女用宝石的力量解除了诅咒,月亮重新焕发出明亮的光芒。\n\n从此,小明和月宫仙子成为了好朋友,他们一起守护着月亮,给村民们带来无尽的欢乐和希望。每当月圆之夜,小明都会带着月饼,邀请村里的孩子们一起分享这美味的佳肴,共同庆祝这个美好的时刻。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 442, 'prompt_tokens': 9, 'total_tokens': 451, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': 'f503c4d4d0b57ce85e78d392e51d2765', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--856ca9e7-e399-43dd-83db-e22cf315ccb7-0', usage_metadata={'input_tokens': 9, 'output_tokens': 442, 'total_tokens': 451, 'input_token_details': {}, 'output_token_details': {}}),'sentence': AIMessage(content='月亮是地球的唯一自然卫星,它以圆润的形态和柔和的银光洒满大地,成为了夜晚天空中最耀眼的风景之一。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 32, 'prompt_tokens': 10, 'total_tokens': 42, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '449c3a7ee40dae0435213dab3963fec2', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--1d40053c-a66f-482a-b206-98d4053f6226-0', usage_metadata={'input_tokens': 10, 'output_tokens': 32, 'total_tokens': 42, 'input_token_details': {}, 'output_token_details': {}})}

并行执行让多任务AI链路“又快又多”,是提升大模型应用效率和体验的关键能力。
无论是批量生成、复杂推理还是多模态协同,LCEL 的并行链都能让你的 AI 应用更高效、更灵活、更易扩展。

并行批处理,适用于大量生成

在 LangChain LCEL(LangChain Expression Language)中,并行批处理(Parallel Batch)是指将多个输入批量提交给并行链(如 RunnableParallel),让每个输入都能同时触发多个子链的并发执行,从而极大提升大规模任务的处理效率。

%%time
chain1.batch([{"topic": "月亮"}, {"topic": "太阳"}])
CPU times: user 10.8 ms, sys: 4.32 ms, total: 15.1 ms
Wall time: 3.99 s
[AIMessage(content='从前,有一个古老的村庄,村子里的居民们都相信月亮是他们的守护神。每天夜晚,他们都会仰望星空,默默祈祷,希望月亮能保佑他们的生活平安、丰收。\n\n有一天晚上,村子里的小孩们决定去探险,看看月亮到底是什么样子的。他们悄悄地溜出家门,来到了一片开阔的田野。孩子们仰望着天空,月亮高悬在夜空中,洒下一片柔和的银光。他们惊讶地发现,月亮的形状竟然像一个大银盘!\n\n这时,一个名叫小明的孩子突然说:“你们看,月亮上的那个黑点,是不是一个眼睛?”孩子们纷纷凑过去看,确实发现月亮上有一个小小的黑点。这时,小明提议:“我们每天都看着月亮,不如我们来做个约定吧!每天晚上,我们都来观察月亮,看看它的形状有没有变化。”\n\n孩子们觉得这个主意很好,于是他们决定每天都晚上去观察月亮。渐渐地,孩子们发现月亮的形状确实发生了变化,有时像一个弯弯的眉毛,有时像一只小船,还有时像一个笑脸。\n\n有一天晚上,孩子们像往常一样来到田野观察月亮。突然,小明指着月亮说:“你们看,月亮上的那个黑点变成了一个弯弯的眉毛!”孩子们仔细一看,果然如此。这时,小明兴奋地说:“你们知道吗?那个黑点其实是一个古老的传说,它代表着月亮的守护神,一直在默默地保佑着我们村子。”\n\n从此以后,村子里的人们更加敬仰月亮了。他们每天晚上都会怀着感激的心情,仰望星空,祈祷月亮的守护神能继续保佑他们的生活平安、丰收。而孩子们则把这个传说传遍了整个村子,让更多的孩子了解到月亮的美丽与神秘。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 361, 'prompt_tokens': 9, 'total_tokens': 370, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '825adb38c73ab860d4abecf04c24f5f8', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--fc9519ad-59c5-49f0-97f1-e01033046579-0', usage_metadata={'input_tokens': 9, 'output_tokens': 361, 'total_tokens': 370, 'input_token_details': {}, 'output_token_details': {}}),AIMessage(content='从前,有一个遥远的国度,名叫炽热之地。这里的人们都非常热爱太阳,因为太阳为他们带来了温暖和光明,让他们过上了美好的生活。\n\n在炽热之地的中心,有一座巨大的金光闪闪的城堡,那里住着一位英俊的青年,名叫拉瑞。拉瑞是炽热之地最伟大的巫师,他懂得如何驾驭太阳的力量。在他的守护下,炽热之地风调雨顺,五谷丰登,人们过上了幸福的生活。\n\n然而,有一天,一个邪恶的巫师来到了炽热之地,他嫉妒拉瑞的才华和太阳带来的恩惠。于是,邪恶巫师决定施展黑暗魔法,企图夺走太阳的光芒,让炽热之地陷入永恒的黑暗之中。\n\n拉瑞得知这个消息后,立刻开始了阻止邪恶巫师的冒险之旅。他跋山涉水,历经千辛万苦,终于找到了邪恶巫师的藏身之处。在一场激战之后,拉瑞凭借着智慧和勇气,成功击败了邪恶巫师,保卫了太阳的光芒。\n\n为了庆祝胜利,炽热之地的人民举行了一场盛大的庆典。他们点燃了篝火,跳起了欢快的舞蹈,共同庆祝这来之不易的胜利。拉瑞也在这场庆典上,向所有人讲述了他的冒险经历,激励着他们珍惜太阳带来的恩惠,勇敢地面对生活中的困难与挑战。\n\n从此以后,炽热之地的人们更加珍惜太阳的光芒,他们感激拉瑞为他们所付出的一切。而拉瑞的故事也在炽热之地流传千古,成为了永恒的传说。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 325, 'prompt_tokens': 9, 'total_tokens': 334, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '9cbde2389d51221c1c62623fe6784fd5', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--58fa945c-892c-445d-9695-e70cd33d08d3-0', usage_metadata={'input_tokens': 9, 'output_tokens': 325, 'total_tokens': 334, 'input_token_details': {}, 'output_token_details': {}})]
%%time
chain2.batch([{"topic": "星星"}, {"topic": "云朵"}])
CPU times: user 11.6 ms, sys: 4.84 ms, total: 16.5 ms
Wall time: 1.15 s
[AIMessage(content='星星是夜空中闪烁的美丽宝石,它们在无尽的黑暗中独自闪耀,为迷失方向的人指引回家的路。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 27, 'prompt_tokens': 10, 'total_tokens': 37, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': 'e4c6bde286db330744e6fbb18de88b41', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--b6ae5840-b425-4d3c-9e9a-a9edd6af78a1-0', usage_metadata={'input_tokens': 10, 'output_tokens': 27, 'total_tokens': 37, 'input_token_details': {}, 'output_token_details': {}}),AIMessage(content='云朵在天空中自由飘荡,变幻着各种形状和颜色,增添了天空的美感和神秘感。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 25, 'prompt_tokens': 11, 'total_tokens': 36, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '502ae9626ed9c5f98459ca2cfa8a20d7', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--0a023a17-8bb2-4475-9613-ebf7289a9c0b-0', usage_metadata={'input_tokens': 11, 'output_tokens': 25, 'total_tokens': 36, 'input_token_details': {}, 'output_token_details': {}})]

并行执行

%%time
combined.batch([{"topic": "月亮"},{"topic": "太阳"}])
CPU times: user 18.7 ms, sys: 6.32 ms, total: 25 ms
Wall time: 3.73 s
[{'story': AIMessage(content='从前,有一个古老的村庄,村子里的居民们都相信月亮是他们的守护神。每天夜晚,当月亮升起时,村民们都会聚集在广场上,向月亮祈祷,希望得到它的庇佑和祝福。\n\n有一天晚上,一个名叫小莉的女孩独自一人走在回家的路上。她抬头看到了那轮明亮的月亮,突然感到一种莫名的孤独。她想起了村子里的人们,他们每个人都在向着月亮祈祷,分享彼此的快乐和忧愁。小莉觉得自己的内心也充满了这些情感,她渴望与人分享自己的内心世界。\n\n就在这时,小莉注意到月亮似乎在向她眨眼睛,就像是在跟她对话。她惊讶地发现,月亮的光芒中似乎包含了各种情感,有喜悦、悲伤、愤怒,还有爱。她突然明白,月亮其实是一个充满智慧和情感的存在,它愿意倾听每个人的心声。\n\n从那天晚上开始,小莉变得更加开朗和善于表达。她开始主动与村民们交流,分享自己的故事和感受。村民们也被小莉的真诚和热情所感染,他们开始更加珍惜彼此之间的友谊和感情。\n\n随着时间的推移,村子里的氛围变得越来越和谐,人们的心灵也变得更加丰富。他们感激月亮给予他们的智慧和情感,也更加珍惜与月亮相处的时光。\n\n这个故事告诉我们,月亮其实是一个充满智慧和情感的存在,它愿意倾听每个人的心声。我们应该珍惜与月亮相处的时光,同时也学会倾听和理解他人的心声,让我们的生活变得更加美好和和谐。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 305, 'prompt_tokens': 9, 'total_tokens': 314, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '51a1a74169e205e3d7c467b1f5d43204', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--e7474081-5334-4e53-9e71-0a539bb05660-0', usage_metadata={'input_tokens': 9, 'output_tokens': 305, 'total_tokens': 314, 'input_token_details': {}, 'output_token_details': {}}),'sentence': AIMessage(content='月亮是地球的唯一自然卫星,它以圆润的形态和柔和的银光洒满大地,成为了夜晚天空中最耀眼的风景之一。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 33, 'prompt_tokens': 10, 'total_tokens': 43, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '3fa1f70172f81180f388ddd7a4d7054d', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--52c7afd3-1991-4eaf-b285-ed315674ab2f-0', usage_metadata={'input_tokens': 10, 'output_tokens': 33, 'total_tokens': 43, 'input_token_details': {}, 'output_token_details': {}})},{'story': AIMessage(content='从前,有一个遥远的国度,名叫日光王国。这个国度的最中央有一座高耸入云的太阳神庙,那里供奉着太阳神的雕像。太阳神在这个国度里拥有无上的权力,他掌控着阳光、温暖和生机。\n\n日光王国的居民们过着和谐美满的生活,他们依赖太阳神赐予的阳光和温暖来种植庄稼、养殖动物和制造器具。然而,这个国度也有一个问题,那就是干旱。长时间的干旱让土地贫瘠,庄稼枯萎,河流干涸,居民们的生活陷入了困境。\n\n有一天,一个名叫小智的年轻人站了出来。他决定去寻找传说中的“太阳之泪”,一种能够解除干旱的神圣泪水。据说,谁要是能找到这颗泪珠,并将其滴入太阳神庙的祭坛上,太阳神就会赋予他神奇的力量,帮助日光王国度过这场灾难。\n\n小智告别了家人和朋友,踏上了漫长的旅程。他穿越了高山、丛林和沙漠,历经千辛万苦,终于在一片神秘的湖泊旁找到了“太阳之泪”。湖泊的水面平静如镜,倒映着天空中的太阳,仿佛是太阳神派来的使者。\n\n小智小心翼翼地取下“太阳之泪”,准备滴入祭坛。就在此时,一阵狂风突然袭来,天空乌云密布,电闪雷鸣。原来,太阳神的怒火被小智的勇气和决心所感动,他决定亲自出马,帮助日光王国度过这场干旱。\n\n太阳神降临在祭坛前,用他的神力滋润了干涸的土地,唤醒了枯萎的庄稼,也解救了河流。阳光再次洒满了整个国度,居民们欢呼雀跃,感激涕零。\n\n从此,日光王国恢复了往日的繁荣与和谐。小智成为了民间传颂的英雄,而“太阳之泪”的传说也代代相传,永远铭记在人们的心中。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 402, 'prompt_tokens': 9, 'total_tokens': 411, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '0b8aeacd7b952f7d3b77b0ef33675a48', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--3a66dae3-df80-492b-88e6-3d6e566fd3e8-0', usage_metadata={'input_tokens': 9, 'output_tokens': 402, 'total_tokens': 411, 'input_token_details': {}, 'output_token_details': {}}),'sentence': AIMessage(content='太阳是我们太阳系的中心恒星,提供了地球上所需的热量和光线。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 16, 'prompt_tokens': 10, 'total_tokens': 26, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'hunyuan-lite', 'system_fingerprint': '', 'id': '42a7ec0428be7399fc39fc714ea54796', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='run--149f0a99-c581-42a6-b500-4d63f906752a-0', usage_metadata={'input_tokens': 10, 'output_tokens': 16, 'total_tokens': 26, 'input_token_details': {}, 'output_token_details': {}})}]
http://www.dtcms.com/a/283280.html

相关文章:

  • Java对象的比较
  • 产品更新丨谷云科技 iPaaS 集成平台 V7.6 版本发布
  • C++面向对象创建打印算术表达式树
  • Spring Boot 源码解析之 Logging
  • Vue加密文章密码 VuePress
  • xss-labs靶场(1-5关)
  • 从零开始学习 Redux:React Native 项目中的状态管理
  • 数据结构-1(顺序表)
  • kafka--基础知识点--0
  • 智慧农业新图景:物联网如何精准守护作物生长​
  • 第六届信号处理与计算机科学国际学术会议(SPCS 2025)
  • CrewAI中构建智能体如何选择Crews 和Flows
  • 注意力机制从理论到实践:注意力提示、汇聚与评分函数
  • HertzBeat 监控 SpringBoot 使用案例
  • elf、axf、bin的区别与转换
  • freetds 解决连接SQL SERVER报错Unexpected EOF from the server
  • 基于组学数据的药物敏感性预测模型构建与验证
  • AI时代基础入门
  • 卷积神经网络(CNN)最本质的技术
  • 离线环境中将现有的 WSL 1 升级到 WSL 2
  • list类的常用接口实现及迭代器
  • [BJDCTF2020]Cookie is so stable
  • Mybatis07-缓存
  • 正确选择光伏方案设计软件:人力成本优化的关键一步
  • 聊聊自己的新书吧
  • lustre设置用户配额
  • 同态加密赋能大模型医疗文本分析:可验证延迟压缩的融合之道
  • xss-labs靶场前八关
  • C语言基础:循环练习题
  • Linux切换到Jenkins用户解决Jenkins Host key verification failed