Repository: explodinggradients/ragas
Issue: TypeError: object of type 'PromptValue' has no len()
Root cause: Interface Contract Mismatch

[ ] I have checked the [documentation](https://docs.ragas.io/) and related resources and couldn't resolve my bug.

**Describe the bug**
when i try to calculate factual correctness, there is always report error:  TypeError: object of type 'PromptValue' has no len()

Ragas version:0.2.1
Python version:3.11

**Code to Reproduce**
```
import asyncio
import os
from langchain_openai import ChatOpenAI
from ragas.dataset_schema import SingleTurnSample
from ragas.metrics._factual_correctness import FactualCorrectness

def create_llm():
    llm = ChatOpenAI(
        model="gpt-4-32k",
        temperature=0,
        streaming=False
    )

    return llm


async def main():
    sample = SingleTurnSample(
        response="The Eiffel Tower is located in Paris.",
        reference="The Eiffel Tower is located in Paris. I has a height of 1000ft."
    )

    scorer = FactualCorrectness()
    scorer.llm = create_llm()
    result = await scorer.single_turn_ascore(sample)
    print(result)


if __name__ == '__main__':
    asyncio.run(main())

```

**Error trace**
```
Traceback (most recent call last):
  File "D:\PyCharm 2024.1\plugins\python\helpers-pro\pydevd_asyncio\pydevd_nest_asyncio.py", line 135, in run
    return loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\PyCharm 2024.1\plugins\python\helpers-pro\pydevd_asyncio\pydevd_nest_asyncio.py", line 238, in run_until_complete
    return f.result()
           ^^^^^^^^^^
  File "D:\Anaconda\envs\ragas\Lib\asyncio\futures.py", line 203, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "D:\Anaconda\envs\ragas\Lib\asyncio\tasks.py", line 277, in __step
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File "D:\llm-apps\ragas\ragas0.2.py", line 30, in main
    result = await scorer.single_turn_ascore(sample)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\ragas\Lib\site-packages\ragas\metrics\base.py", line 255, in single_turn_ascore
    raise e
  File "D:\Anaconda\envs\ragas\Lib\site-packages\ragas\metrics\base.py", line 248, in single_turn_ascore
    score = await asyncio.wait_for(
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\ragas\Lib\asyncio\tasks.py", line 452, in wait_for
    return await fut
           ^^^^^^^^^
  File "D:\Anaconda\envs\ragas\Lib\site-packages\ragas\metrics\_factual_correctness.py", line 241, in _single_turn_ascore
    response_claims = await self.decompose_claims(response, callbacks)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\ragas\Lib\site-packages\ragas\metrics\_factual_correctness.py", line 214, in decompose_claims
    result = await self.claim_decomposition_prompt.generate(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\ragas\Lib\site-packages\ragas\prompt\pydantic_prompt.py", line 126, in generate
    output_single = await self.generate_multiple(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\ragas\Lib\site-packages\ragas\prompt\pydantic_prompt.py", line 181, in generate_multiple
    resp = await llm.generate(
                 ^^^^^^^^^^^^^
  File "D:\Anaconda\envs\ragas\Lib\site-packages\langchain_core\language_models\chat_models.py", line 627, in generate
    batch_size=len(messages),
               ^^^^^^^^^^^^^
TypeError: object of type 'PromptValue' has no len()

```

<!-- PS: bugs suck but is also part of the process. We sincerely apologies for breaking your flow because of it, but don't worry, we got your back ❤️. We will get this fixed as fast as we can and thanks for helping us out by reporting it 🙏. -->


<!-- Greeting -->
Hey @chenlei1231! I'm here to assist you with any bugs, questions, or contributions you have. Let's tackle this issue together!

<!-- Answer -->
A similar issue was reported in the Ragas repository, where users encountered an error related to the `PromptValue` object not having a `len()` method. The solution suggested in a closed issue was to wrap the language model with `LangchainLLMWrapper` to ensure compatibility. Here is the code snippet that was provided as a solution:

```python
from langchain.chat_models import ChatVertexAI
from langchain.embeddings import VertexAIEmbeddings
from ragas.llms.base import LangchainLLMWrapper

creds, project_id = google.auth.default()
ragas_vertexai_llm = ChatVertexAI(model_name='gemini-pro', credentials=creds)

wrapper = LangchainLLMWrapper(ragas_vertexai_llm)
vertexai_embeddings = VertexAIEmbeddings(model_name='textembedding-gecko@003', credentials=creds)

for m in metrics:
    # change LLM for metric
    m.__setattr__("llm", wrapper)

    # check if this metric needs embeddings
    if hasattr(m, "embeddings"):
        # if so change with VertexAI Embeddings
        m.__setattr__("embeddings", vertexai_embeddings)

from ragas import evaluate
result = evaluate(
    amnesty_qa["eval"].select(range(1)),  # using 1 as example due to quota constraints
    metrics=metrics,
    llm=wrapper,
    embeddings=vertexai_embeddings
)
```

In your case, you should wrap your `ChatOpenAI` instance with `LangchainLLMWrapper` before using it in the `FactualCorrectness` class. This should resolve the `TypeError` related to the `PromptValue` object <sup>[[1]](https://github.com/explodinggradients/ragas/issues/614)</sup>.


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


hey @chenlei1231 I think this is because of a small bug in your code - Ragas expects any llm to have the base class of [BaseRagasLLM](https://docs.ragas.io/en/stable/references/llms/#ragas.llms.BaseRagasLLM).

since you using langchain, you can use [LangchainLLMWrapper](https://docs.ragas.io/en/stable/references/llms/#ragas.llms.LangchainLLMWrapper) instead 

```py
from ragas.dataset_schema import SingleTurnSample
from ragas.metrics import FactualCorrectness
from ragas.llms import llm_factory

sample = SingleTurnSample(
    response="The Eiffel Tower is located in Paris.",
    reference="The Eiffel Tower is located in Paris. I has a height of 1000ft."
    )

scorer = FactualCorrectness(llm=llm_factory("gpt-4o"))
result = await scorer.single_turn_ascore(sample)
print(result)
```

It seems the issue was answered, closing this now.