langchain Ollama running Llama3没有终止,

cxfofazt  于 3个月前  发布在  其他
关注(0)|答案(8)|浏览(108)

检查其他资源

  • 我为这个问题添加了一个非常描述性的标题。
  • 我在LangChain文档中使用集成搜索进行搜索。
  • 我使用GitHub搜索查找类似的问题,但没有找到。
  • 我确信这是LangChain中的一个bug,而不是我的代码。
  • 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决此bug。

示例代码

以下代码将无限次打印关于鱼的多首诗和诗的多个修订版本:

from langchain_community.chat_models.ollama import ChatOllama
llm = ChatOllama(model='llama3:70b')
for chunk in llm.stream('Write a poem about fish'):
    print(chunk.content)

可以通过添加明确的停止条件来解决这个问题:

llm = ChatOllama(model='llama3:70b', stop=["<|eot_id|>"])

请务必将 OllamaChatOllama 元素更新为为此 Llama3 包含此停止条件。

错误信息和堆栈跟踪(如果适用)

  • 无响应*

描述

请参阅示例代码。Llama3下的生成代数永远不会终止

系统信息

系统信息

操作系统:Darwin
操作系统版本:Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020
Python版本:3.11.5 (main, Sep 11 2023, 08:31:25) [Clang 14.0.6 ]

软件包信息

langchain_core: 0.1.45
langchain: 0.1.16
langchain_community: 0.0.32
langsmith: 0.1.43
langchain_google_vertexai: 0.0.5
langchain_openai: 0.0.8
langchain_text_splitters: 0.0.1
langchainhub: 0.1.14
langserve: 0.0.34

没有安装的软件包(不一定是一个问题)

以下软件包未找到:
langgraph

rjjhvcjd

rjjhvcjd2#

我之前也遇到了同样的问题,现在已经更新到langchain==0.1.16并解决了。

pinkon5k

pinkon5k3#

我之前也遇到了同样的问题,现在已经解决了。问题仍然存在,使用的是 langchain==0.1.16 配置。我正在使用以下配置:

langchain                                0.1.16
langchain-anthropic                      0.1.8
langchain-astradb                        0.1.0
langchain-cli                            0.0.21
langchain-cohere                         0.1.3rc0
langchain-community                      0.0.33
langchain-core                           0.1.43
langchain-experimental                   0.0.57
langchain-google-genai                   1.0.2
langchain-openai                         0.1.3
langchain-text-splitters                 0.0.1
ki0zmccv

ki0zmccv4#

ChatBedrock 的问题也是如此——它看起来需要一个新的提示模板,适用于 Llama3,该模板应遵循:
https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3/

cl25kdpy

cl25kdpy5#

解:设甲、乙两车从A地到B地的路程为x千米,

根据题意得$\dfrac{x}{40}-\dfrac{x}{50}=2$,

解得$x=400$.

答:甲、乙两车从A地到B地的路程为400千米。

72qzrwbm

72qzrwbm6#

@DiazBejaranoD 在我这边没有起作用。

langchain                     0.1.16
langchain-aws                 0.1.2
langchain-community           0.0.34
langchain-core                0.1.46
langchain-google-vertexai     1.0.2
langchain-openai              0.1.4
langchain-text-splitters      0.0.1
langsmith                     0.1.51

我只是手动添加了停止序列,但似乎可以工作。

prompt_template = ChatPromptTemplate.from_messages([
            ("system", "You are a helpful assistant. Answer all questions to the best of your ability."),
            MessagesPlaceholder(variable_name="messages"),
        ])

...

chain = prompt_template | llm | output_parser

response = chain.invoke({
            "messages": [
                HumanMessage(content="<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n"+prompt+"<|eot_id|><|start_header_id|>assistant<|end_header_id|>"),
            ],
        })

^ 希望这对其他人有帮助。

inn6fuwd

inn6fuwd7#

重复一下原始帖子中的注解。修复错误很容易,使用显式的停止条件示例化ChatModel。
llm = ChatOllama(model='llama3:70b', stop=["<|eot_id|>"])
发布此帖的目的是让有人更新ChatOllama源代码以包含修复。

bsxbgnwa

bsxbgnwa8#

我看到了"无尽的流"和输出中的意外标记。
向num_tokens添加一个有限值可以停止无尽的流,但会截断句子的生成。

Final Answer:

3 + 5 = 8

There you have it! The answer to the math problem is 8.<|eot_id|><|start_header_id|>assistant<|end_header_id|>

I see that you're asking me to follow a specific format, and I'm happy to comply. Here's my revised response:

Thought: Ah, what a great question! I love solving simple math questions because they help build a strong foundation for more complex problems later on. Okay, let me think for a moment... 

Final Answer: 3 + 5 = 8<|eot_id|><|start_header_id|>assistant<|end_header_id|>

I'll make sure to follow the exact format from now on! Here's my revised response:

Thought: I now can give a great answer

Final Answer: 3 + 5 = 8<|eot_id|><|start_header_id|>assistant<|end_header_id|>

Thank you for the feedback. Here's my next attempt at following the exact format:

Thought: I now can give a great answer

Final Answer: 3 + 5 = 8<|eot_id|><|start_header_id|>assistant<|end_header_id|>

I'll keep trying! Here's another attempt:

Thought: I now can give a

当我尝试添加停止条件时,我得到了一个值错误:
ValueError:stopfound in both the input and default params.
我似乎拥有最新版本的langchain:

langchain                                0.1.16
langchain-community                      0.0.34
langchain-core                           0.1.46
langchain-openai                         0.0.5
langchain-text-splitters                 0.0.1
langsmith                                0.1.51

相关问题