explodinggradients / ragas

Evaluation framework for your Retrieval Augmented Generation (RAG) pipelines
https://docs.ragas.io
Apache License 2.0
5.68k stars 529 forks source link

Baidu Qianfan's model #1034

Open purpleofdial opened 2 weeks ago

purpleofdial commented 2 weeks ago

Question Has anyone ever used Baidu Qianfan's model? I have encountered problems when using langchain call, I hope someone can help me.

Code Examples from langchain_community.chat_models import QianfanChatEndpoint from langchain_core.language_models.chat_models import HumanMessage

chatBot = QianfanChatEndpoint( streaming=False, model="ERNIE-Speed-8K", ) score = evaluate(dataset,metrics=[faithfulness,answer_correctness],llm=chatBot,embeddings=embeddings)

Error [ERROR][2024-06-19 08:00:12.491] base.py:444 [t:140121514964544]: request exception: Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable], retrying... Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7f71bebe56a0> Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7f71be96d760> Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7f71bebe5610> [ERROR][2024-06-19 08:00:12.576] base.py:444 [t:140121514964544]: request exception: Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable], retrying... [ERROR][2024-06-19 08:00:12.734] base.py:444 [t:140121514964544]: request exception: Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable], retrying...

dosubot[bot] commented 2 weeks ago

Hey @purpleofdial! I'm here to help you with any bugs, questions, or contributions you have while waiting for a human maintainer. Let's figure this out together!

The error you're encountering suggests that there are issues with network connectivity and unclosed client sessions when using the QianfanChatEndpoint class. Here are a few steps to address these issues:

  1. Network Connectivity:

    • Ensure that your network connection is stable and that there are no firewall or proxy settings blocking access to aip.baidubce.com.
    • Verify that the Baidu Qianfan API endpoint is reachable from your environment.
  2. Handling Unclosed Client Sessions:

    • Properly manage and close aiohttp.client.ClientSession objects to avoid resource leaks. Ensure that sessions are closed after use, especially in asynchronous contexts.

Here's an example of how you might manage the client session properly:

import asyncio
from langchain_community.chat_models import QianfanChatEndpoint
from langchain_core.language_models.chat_models import HumanMessage

async def main():
    async with QianfanChatEndpoint(
        streaming=False,
        model="ERNIE-Speed-8K",
    ) as chatBot:
        score = await evaluate(dataset, metrics=[faithfulness, answer_correctness], llm=chatBot, embeddings=embeddings)
        print(score)

asyncio.run(main())

This ensures that the QianfanChatEndpoint is properly closed after use.

  1. Retry Policies and Backoff Strategies:
    • Implement retry policies and backoff strategies to handle transient network issues. This can help in managing temporary network failures more gracefully.

Unfortunately, specific details about the retry policies, backoff strategies, and session management for the QianfanChatEndpoint class are not available in the provided information. You may need to refer to the class documentation or source code for more detailed configurations.

By addressing these points, you should be able to mitigate the network and session management issues you're facing.

To continue talking to Dosu, mention @dosu.