Repository: explodinggradients/ragas
Issue: How can I Generate Synthetic Testset for RAG using deepseek in RAGAS?
Root cause: Documentation Deficiency


yep, since deepseek supports langchain, we can just use that https://api-docs.deepseek.com/faq#does-your-api-support-langchain

@dosu can you make a code example to help out @Sara-Hossny ? Modify the getting started doc to use deepseek. I'm attaching the code example deepseek has given bellow too

```py
# pip3 install langchain_openai
# python3 deepseek_langchain.py
from langchain_openai.chat_models.base import BaseChatOpenAI

llm = BaseChatOpenAI(
    model='deepseek-chat', 
    openai_api_key='<your api key>', 
    openai_api_base='https://api.deepseek.com',
    max_tokens=1024
)

response = llm.invoke("Hi!")
print(response.content)
```

<!-- Answer -->
To generate a synthetic test set for RAG using DeepSeek in RAGAS, you can follow these steps:

1. **Install Required Packages**: Ensure you have the necessary packages installed. You can install `langchain_openai` using pip:

    ```bash
    pip3 install langchain_openai
    ```

2. **Set Up DeepSeek with LangChain**: Use the provided DeepSeek example to set up your language model. Replace `<your api key>` with your actual DeepSeek API key.

    ```python
    from langchain_openai.chat_models.base import BaseChatOpenAI

    llm = BaseChatOpenAI(
        model='deepseek-chat', 
        openai_api_key='<your api key>', 
        openai_api_base='https://api.deepseek.com',
        max_tokens=1024
    )

    response = llm.invoke("Hi!")
    print(response.content)
    ```

3. **Load Documents**: Use a document loader to load your documents. For example, using `SimpleDirectoryReader` from `llama_index`:

    ```python
    from llama_index import SimpleDirectoryReader

    dir_path = "./your-documents-directory"
    reader = SimpleDirectoryReader(dir_path, num_files_limit=2)
    documents = reader.load_data()
    ```

4. **Generate Testset**: Use the `TestsetGenerator` from Ragas to generate the test set. You can specify the size of the test set and use the DeepSeek model for generation:

    ```python
    from ragas.testset import TestsetGenerator
    from langchain_openai import OpenAIEmbeddings

    TEST_SIZE = 25

    # Initialize generator with DeepSeek model
    generator_llm = llm  # Use the DeepSeek model initialized earlier
    critic_llm = llm  # You can use the same model or another if needed
    embeddings = OpenAIEmbeddings()

    generator = TestsetGenerator.from_langchain(generator_llm, critic_llm, embeddings)

    # Generate testset
    testset = generator.generate_with_llamaindex_docs(documents, test_size=TEST_SIZE)
    test_df = testset.to_pandas()
    ```

This setup will allow you to generate a synthetic test set for your RAG pipeline using DeepSeek integrated with LangChain. Adjust the document path, test size, and models as needed for your specific use case.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

---
<sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/a03244e8-b980-4e30-9089-a5bc19ed52a1?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/a03244e8-b980-4e30-9089-a5bc19ed52a1?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/a03244e8-b980-4e30-9089-a5bc19ed52a1?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/a03244e8-b980-4e30-9089-a5bc19ed52a1?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/a03244e8-b980-4e30-9089-a5bc19ed52a1?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/a03244e8-b980-4e30-9089-a5bc19ed52a1?feedback_type=other)</sup>