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

Making custom LLMs compatible with TestsetGenerator? #230

Closed
Data-drone opened this issue Oct 29, 2023 · 13 comments
Closed

Making custom LLMs compatible with TestsetGenerator? #230

Data-drone opened this issue Oct 29, 2023 · 13 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@Data-drone
Copy link

Hi Team,

I am trying to get the TestsetGenerator to work properly with a Langchain custom LLM.

It's _call method current expects a string prompt but it gets a ChatPromptTemplate from ragas. what is the best way to handle this?

@Data-drone
Copy link
Author

I got things working by just running format() against the prompt my LLM received if it was in ChatPromptTemplate format but not sure that is the best approach.

I have set the chat_qa=0.0 so shouldn't all the prompts be coming in as string?

@shahules786
Copy link
Member

Hey @Data-drone , can you share the ragas & python version you're using?

@Data-drone
Copy link
Author

ragas==0.0.18 python 3.10.12

@shahules786
Copy link
Member

Hi @Data-drone , We will look into the langchain custom llms issue. Regarding setting chat_qa=0, it is used to control if the test set should contain conversational questions or not.

@shahules786
Copy link
Member

Hi @Data-drone , which model are you using? Are you using an instruction-tuned model (that is not chat based)?

@Data-drone
Copy link
Author

Vicuna 1.5 13b

@jjmachan
Copy link
Member

hey @Data-drone , so we do have this snipped inside RagasLLMs that should handle this logic for you

        if isinstance(self.llm, BaseLLM):
            ps = [p.format() for p in prompts]
            result = self.llm.generate(ps, callbacks=callbacks)
        else:  # if BaseChatModel
            ps = [p.format_messages() for p in prompts]
            result = self.llm.generate(ps, callbacks=callbacks)

if your custom model is a base class of either, it should do the conversation for you. but not sure why its not working here. Could you show us how you're calling the testsetgenerator and custom models code?

@msunkarahend
Copy link

@shahules786 @jjmachan In the same context, TestsetGenerator uses cross-encoder/stsb-TinyBERT-L-4/ from hugging face. Is there a way, i can avoid using that and just use gpt models from azure open ai alone and generate synthetic dataset?

@jjmachan jjmachan added documentation Improvements or additions to documentation question Further information is requested labels Nov 29, 2023
@jjmachan jjmachan added this to the v0.1.0 milestone Nov 29, 2023
@jjmachan
Copy link
Member

hey @msunkarahend thanks for bringing that up. what you can do is change it via the class

class TestsetGenerator:

    """
    Ragas Test Set Generator

    Attributes
    ----------
    generator_llm: LangchainLLM
        LLM used for all the generator operations in the TestGeneration paradigm.
    critique_llm: LangchainLLM
        LLM used for all the filtering and scoring operations in TestGeneration
        paradigm.
    embeddings_model: Embeddings
        Embeddings used for vectorizing nodes when required.
    chat_qa: float
        Determines the fraction of conversational questions the resulting test set.
    chunk_size: int
        The chunk size of nodes created from data.
    test_distribution : dict
        Distribution of different types of questions to be generated from given
        set of documents. Defaults to {"easy":0.1, "reasoning":0.4, "conversation":0.5}
    """

    def __init__(
        self,
        generator_llm: RagasLLM,
        critic_llm: RagasLLM,
        embeddings_model: Embeddings,
        testset_distribution: t.Optional[t.Dict[str, float]] = None,
        chat_qa: float = 0.0,
        chunk_size: int = 1024,
        seed: int = 42,
    ) -> None:

so if you give a new different Embedding instance you will be able to change it.

let me know if you want the finished snippet and I'll share that too 😄

@jjmachan
Copy link
Member

but @shahules786 probably we should change from_defaults class method to with_openai or something like that to make it easier?

@msunkarahend
Copy link

@jjmachan If you can share the finished snippet for the TestsetGenerator, it would be great. thanks in advance.

@hbj52
Copy link

hbj52 commented Jan 19, 2024

I notice that the if downloaded from source, the version of ragas on github is 0.0.23.dev44+g506ad60, while the latest version I down load from pip is 0.0.22, same as shown "latest realease" on github. And it seems like 0.0.22 will meet similar question about list(str) and list(ChatPromptTemplate).

@mspronesti
Copy link
Contributor

mspronesti commented Feb 28, 2024

Could you guys try #670?

jjmachan added a commit that referenced this issue Mar 12, 2024
…ngs (#670)

## **User description**
The current version of `with_openai` contains a hardcoded instantiation
of `langchain_openai.chat_models.ChatOpenAI`, which makes
`TestsetGenerator` very limited and not compatible with completion
models, Azure OpenAI models, and open-source models.

This PR extends `TestsetGenerator` to any `BaseLanguageModel` and
`Embeddings` from langchain for versatility, addressing #230, #342,
#635, and #636.

Lastly, I've removed all the occurrences of mutable default arguments
(bad antipattern, read
[here](https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments)).

---------

Co-authored-by: Shahules786 <Shahules786@gmail.com>
Co-authored-by: jjmachan <jamesjithin97@gmail.com>
@jjmachan jjmachan removed this from the v0.1.0 milestone May 1, 2024
@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Jun 1, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Jun 8, 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 question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants