Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Feedback for usage/tools-calling #4560

Open
twang2218 opened this issue Oct 31, 2024 · 1 comment
Open

[Docs] Feedback for usage/tools-calling #4560

twang2218 opened this issue Oct 31, 2024 · 1 comment
Labels
📝 Documentation Improvements or additions to documentation | 文档问题

Comments

@twang2218
Copy link

📝 Reference

https://github.com/lobehub/lobe-chat/tree/main/docs/usage/tools-calling.zh-CN.mdx

🐛 Feedback

tools-calling除了这个应用外,还有一个应用形式,即「结构化输出」(Structured Output),如:

from typing import Optional
from pathlib import Path
from pydantic import BaseModel, Field
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

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")


model = ChatOpenAI(model="gpt-4o-mini")
model = model.with_structured_output(Joke)
prompt = ChatPromptTemplate.from_messages([
    ("system", "你是一个幽默大师"),
    ("user", "{text}")
])

在LangSmith中可以看到返回后会调用PydanticToolParser,从而确保了语言模型的输出符合指定结构。

在具体实现上,呼叫API的时候,tools中会给出指定类的schema,模型就会严格按照这个schema返回信息。

此外,我还发现一个好像很多模型都会忽视的一个问题,就是当提供的上下文,如{text}的内容过长时,许多模型的tool_calls就会失败。比如当提供了4K内容给{text}的时候,许多模型就开始忽略tool_calls的调用,转为普通的输出了。因此测试的时候,可以考虑增加指令、上下文长度和tool_calls的成功率的测试。

@lobehubbot
Copy link
Member

👀 @twang2218

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible.
Please make sure you have given us as much context as possible.
非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

@dosubot dosubot bot added the 📝 Documentation Improvements or additions to documentation | 文档问题 label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📝 Documentation Improvements or additions to documentation | 文档问题
Projects
None yet
Development

No branches or pull requests

2 participants