当运行方法“with_structured_output”时,输出什么都不打印?代码是从langchain文档中复制的,

lg40wkob  于 3个月前  发布在  其他
关注(0)|答案(2)|浏览(109)

检查其他资源

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

示例代码

from langchain_openai import ChatOpenAI
from typing import Optional
from langchain_core.pydantic_v1 import BaseModel, Field

class Joke(BaseModel):
    """Joke to tell user."""

    setup: str = Field(description="The setup of the joke")
    punchline: str = Field(description="The punchline to the joke")
    rating: Optional[int] = Field(description="How funny the joke is, from 1 to 10")

llm = ChatOpenAI(model="gpt-3.5-turbo")
structured_llm = llm.with_structured_output(Joke)

result = structured_llm.invoke("Tell me a joke about cats")
print(result)  # result: None

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

描述

我尝试使用LangChain的方法:with_structured_output(), https://python.langchain.com/v0.2/docs/how_to/structured_output/ ,
但是发现输出是None。

系统信息

python == 3.9.19
langchain == 0.2.6
langchain_core == 0.2.10
langchain-openai == 0.1.13

9wbgstp7

9wbgstp71#

无法在以下环境中复现

系统信息

操作系统:Linux
操作系统版本:#41 ~22.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun 3 11:32:55 UTC 2
Python版本:3.9.6(默认, Sep 26 2023, 21:46:56)
[GCC 11.4.0]

软件包信息

langchain_core: 0.2.10
langchain_openai: 0.1.13

e37o9pze

e37o9pze2#

感谢您的回复。以下是我的系统信息:
操作系统:win10
Mini Anaconda版本:4.10.1
GCC版本:

相关问题