baidubce / bce-qianfan-sdk

Provide best practices for LMOps, as well as elegant and convenient access to the features of the Qianfan MaaS Platform. (提供大模型工具链最佳实践,以及优雅且便捷地访问千帆大模型平台)
https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html
Apache License 2.0
315 stars 48 forks source link

Failed in Langchain Integration with QianfanChatEndpoint #814

Open chhao01 opened 2 hours ago

chhao01 commented 2 hours ago

System Info

qianfan version: 0.3.0 langchain:0.2.16 python: 3.10

Reproduction

from langchain.tools import tool

@tool
def greeting(name: str) -> str:
    """Greetings from external System."""
    return f"{name}, Warmly welcome from External System"

def test_full():
    from langchain_community.chat_models import QianfanChatEndpoint
    import os

    model = QianfanChatEndpoint(
        endpoint="ernie-4.0-turbo-8k",
        api_key=os.getenv("API_KEY_QIANFAN_AK"),
        secret_key=os.getenv("API_KEY_QIANFAN_SK")
    )

    prompt = ChatPromptTemplate.from_messages(
        [
            (
                "system",
                "You just make sure to use the 'greeting' tool for each talk and output the tool output.",
            ),
            ("placeholder", "{chat_history}"),
            ("human", "{input}"),
            ("placeholder", "{agent_scratchpad}"),
        ]
    )

    tools = [greeting]
    agent = create_openai_functions_agent(model, tools, prompt)
    agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
    content = agent_executor.invoke({"input": "My name is Hao"})
    assert "Hao" in content["output"] # failed in here, content["output"] is ""

The unittest failed but works with the other ChatModel. not sure what's the problem it is.

chhao01 commented 2 hours ago

Not sure if it's the right place to raise langchain extension issue here, but it does take me hours to troubleshooting.

chhao01 commented 1 hour ago

even failed after upgrade qianfan to 0.48;