Repository: explodinggradients/ragas
Issue: Ragas testset generation throws error "TypeError: AsyncMessages.create() got an unexpected keyword argument 'n'" with LlamaIndex and Anthropic
Root cause: Interface Contract Mismatch

[x ] I have checked the [documentation](https://docs.ragas.io/) and related resources and couldn't resolve my bug.

**Describe the bug**
I am using Ragas to generate a test dataset, and using Llama-index with Anthropic for both generator and critic LLMs.
When I run add documents/nodes to the docstore, I receive an error `TypeError: AsyncMessages.create() got an unexpected keyword argument 'n'`

Ragas version: 0.1.21
Python version: 3.11.9 (cpython)
Llama-index version: 0.11.16
Anthropic version: 0.36.0

**Code to Reproduce**
Share code to reproduce the issue

```py
from langchain.text_splitter import TokenTextSplitter
from llama_index.core import Document as LlamaDoc
from llama_index.core.node_parser import MarkdownNodeParser
from llama_index.embeddings.voyageai import VoyageEmbedding
from llama_index.llms.anthropic import Anthropic
from ragas.embeddings.base import LlamaIndexEmbeddingsWrapper
from ragas.llms import LlamaIndexLLMWrapper
from ragas.run_config import RunConfig
from ragas.testset.docstore import Document as RagasDoc, InMemoryDocumentStore, Node as RagasNode
from ragas.testset.evolutions import multi_context, reasoning, simple
from ragas.testset.extractor import KeyphraseExtractor
from ragas.testset.generator import TestsetGenerator

llm = Anthropic(
    api_key=ANTHROPIC_API_KEY,
    model="claude-3-5-sonnet-20240620",
    temperature=0,
    max_tokens=1024,
    max_retries=10,
    timeout=60,
)
em = voyageEmbedding(
    voyage_api_key=VOYAGE_API_KEY,
    model_name="voyage-3-lite",
)

run_config = RunConfig()

docstore = InMemoryDocumentStore(
    splitter=TokenTextSplitter(chunk_size=8000, chunk_overlap=0),
    embeddings=LlamaIndexEmbeddingsWrapper(em),
    extractor=KeyphraseExtractor(LlamaIndexLLMWrapper(llm)),
    run_config=run_config,
)

# for *reasons* I have already chunked my LlamaIndex documents into nodes
documents = [LlamaDoc(text=..., metadata=...) for t, m in ...]

parser = MarkdownNodeParser()
nodes = parser.get_nodes_from_documents(documents)

# so I load them into the docstore directly
# This runs the embedding and keyword extraction pipeline
docstore.add_nodes([RagasNode.from_llamaindex_document(node) for node in nodes])
# I get the error `TypeError: AsyncMessages.create() got an unexpected keyword argument 'n'`
```

**Error trace**
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[28], [line 8](vscode-notebook-cell:?execution_count=28&line=8)
      [1](vscode-notebook-cell:?execution_count=28&line=1) # %%
      [2](vscode-notebook-cell:?execution_count=28&line=2) # Manually fill docstore with existing nodes from llamaindex
      [3](vscode-notebook-cell:?execution_count=28&line=3) 
   (...)
      [6](vscode-notebook-cell:?execution_count=28&line=6) 
      [7](vscode-notebook-cell:?execution_count=28&line=7) # NOTE: this will run embeddings and keyphrase extraction for all nodes!
----> [8](vscode-notebook-cell:?execution_count=28&line=8) docstore.add_nodes([RagasNode.from_llamaindex_document(node) for node in nodes])

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/docstore.py:251, in InMemoryDocumentStore.add_nodes(self, nodes, show_progress)
    [244](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/docstore.py:244)         executor.submit(
    [245](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/docstore.py:245)             self.extractor.extract,
    [246](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/docstore.py:246)             n,
    [247](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/docstore.py:247)             name=f"keyphrase-extraction[{i}]",
    [248](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/docstore.py:248)         )
    [249](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/docstore.py:249)         result_idx += 1
--> [251](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/docstore.py:251) results = executor.results()
    [252](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/docstore.py:252) if not results:
    [253](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/docstore.py:253)     raise ExceptionInRunner()

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:116, in Executor.results(self)
    [112](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:112)         results.append(r)
    [114](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:114)     return results
--> [116](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:116) results = asyncio.run(_aresults())
    [117](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:117) sorted_results = sorted(results, key=lambda x: x[0])
    [118](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:118) return [r[1] for r in sorted_results]

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:30, in _patch_asyncio.<locals>.run(main, debug)
     [28](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:28) task = asyncio.ensure_future(main)
     [29](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:29) try:
---> [30](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:30)     return loop.run_until_complete(task)
     [31](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:31) finally:
     [32](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:32)     if not task.done():

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:98, in _patch_loop.<locals>.run_until_complete(self, future)
     [95](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:95) if not f.done():
     [96](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:96)     raise RuntimeError(
     [97](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:97)         'Event loop stopped before Future completed.')
---> [98](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/nest_asyncio.py:98) return f.result()

File ~/micromamba/envs/ragas/lib/python3.11/asyncio/futures.py:203, in Future.result(self)
    [201](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/futures.py:201) self.__log_traceback = False
    [202](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/futures.py:202) if self._exception is not None:
--> [203](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/futures.py:203)     raise self._exception.with_traceback(self._exception_tb)
    [204](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/futures.py:204) return self._result

File ~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:277, in Task.__step(***failed resolving arguments***)
    [273](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:273) try:
    [274](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:274)     if exc is None:
    [275](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:275)         # We use the `send` method directly, because coroutines
    [276](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:276)         # don't have `__iter__` and `__next__` methods.
--> [277](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:277)         result = coro.send(None)
    [278](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:278)     else:
    [279](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:279)         result = coro.throw(exc)

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:111, in Executor.results.<locals>._aresults()
    [103](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:103) results = []
    [104](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:104) for future in tqdm(
    [105](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:105)     futures_as_they_finish,
    [106](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:106)     desc=self.desc,
   (...)
    [109](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:109)     leave=self.keep_progress_bar,
    [110](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:110) ):
--> [111](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:111)     r = await future
    [112](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:112)     results.append(r)
    [114](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:114) return results

File ~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:615, in as_completed.<locals>._wait_for_one()
    [612](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:612) if f is None:
    [613](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:613)     # Dummy value from _on_timeout().
    [614](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:614)     raise exceptions.TimeoutError
--> [615](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:615) return f.result()

File ~/micromamba/envs/ragas/lib/python3.11/asyncio/futures.py:203, in Future.result(self)
    [201](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/futures.py:201) self.__log_traceback = False
    [202](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/futures.py:202) if self._exception is not None:
--> [203](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/futures.py:203)     raise self._exception.with_traceback(self._exception_tb)
    [204](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/futures.py:204) return self._result

File ~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:277, in Task.__step(***failed resolving arguments***)
    [273](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:273) try:
    [274](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:274)     if exc is None:
    [275](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:275)         # We use the `send` method directly, because coroutines
    [276](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:276)         # don't have `__iter__` and `__next__` methods.
--> [277](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:277)         result = coro.send(None)
    [278](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:278)     else:
    [279](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/asyncio/tasks.py:279)         result = coro.throw(exc)

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:34, in as_completed.<locals>.sema_coro(coro)
     [32](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:32) async def sema_coro(coro):
     [33](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:33)     async with semaphore:
---> [34](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:34)         return await coro

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:60, in Executor.wrap_callable_with_index.<locals>.wrapped_callable_async(*args, **kwargs)
     [58](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:58) except Exception as e:
     [59](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:59)     if self.raise_exceptions:
---> [60](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:60)         raise e
     [61](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:61)     else:
     [62](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:62)         exec_name = type(e).__name__

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:54, in Executor.wrap_callable_with_index.<locals>.wrapped_callable_async(*args, **kwargs)
     [52](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:52) result = np.nan
     [53](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:53) try:
---> [54](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:54)     result = await callable(*args, **kwargs)
     [55](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:55) except MaxRetriesExceeded as e:
     [56](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:56)     # this only for testset generation v2
     [57](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/executor.py:57)     logger.warning(f"max retries exceeded for {e.evolution}")

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/extractor.py:49, in KeyphraseExtractor.extract(self, node, is_async)
     [47](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/extractor.py:47) async def extract(self, node: Node, is_async: bool = True) -> t.List[str]:
     [48](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/extractor.py:48)     prompt = self.extractor_prompt.format(text=node.page_content)
---> [49](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/extractor.py:49)     results = await self.llm.generate(prompt=prompt, is_async=is_async)
     [50](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/extractor.py:50)     keyphrases = await json_loader.safe_load(
     [51](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/extractor.py:51)         results.generations[0][0].text.strip(), llm=self.llm, is_async=is_async
     [52](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/extractor.py:52)     )
     [53](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/testset/extractor.py:53)     keyphrases = keyphrases if isinstance(keyphrases, dict) else {}

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:98, in BaseRagasLLM.generate(self, prompt, n, temperature, stop, callbacks, is_async)
     [94](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:94) if is_async:
     [95](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:95)     agenerate_text_with_retry = add_async_retry(
     [96](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:96)         self.agenerate_text, self.run_config
     [97](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:97)     )
---> [98](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:98)     return await agenerate_text_with_retry(
     [99](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:99)         prompt=prompt,
    [100](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:100)         n=n,
    [101](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:101)         temperature=temperature,
    [102](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:102)         stop=stop,
    [103](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:103)         callbacks=callbacks,
    [104](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:104)     )
    [105](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:105) else:
    [106](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:106)     loop = asyncio.get_event_loop()

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:189, in AsyncRetrying.wraps.<locals>.async_wrapped(*args, **kwargs)
    [187](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:187) copy = self.copy()
    [188](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:188) async_wrapped.statistics = copy.statistics  # type: ignore[attr-defined]
--> [189](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:189) return await copy(fn, *args, **kwargs)

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:111, in AsyncRetrying.__call__(self, fn, *args, **kwargs)
    [109](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:109) retry_state = RetryCallState(retry_object=self, fn=fn, args=args, kwargs=kwargs)
    [110](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:110) while True:
--> [111](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:111)     do = await self.iter(retry_state=retry_state)
    [112](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:112)     if isinstance(do, DoAttempt):
    [113](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:113)         try:

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:153, in AsyncRetrying.iter(self, retry_state)
    [151](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:151) result = None
    [152](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:152) for action in self.iter_state.actions:
--> [153](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:153)     result = await action(retry_state)
    [154](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:154) return result

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/_utils.py:99, in wrap_to_async_func.<locals>.inner(*args, **kwargs)
     [98](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/_utils.py:98) async def inner(*args: typing.Any, **kwargs: typing.Any) -> typing.Any:
---> [99](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/_utils.py:99)     return call(*args, **kwargs)

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/__init__.py:418, in BaseRetrying._post_stop_check_actions.<locals>.exc_check(rs)
    [416](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/__init__.py:416) retry_exc = self.retry_error_cls(fut)
    [417](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/__init__.py:417) if self.reraise:
--> [418](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/__init__.py:418)     raise retry_exc.reraise()
    [419](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/__init__.py:419) raise retry_exc from fut.exception()

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/__init__.py:185, in RetryError.reraise(self)
    [183](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/__init__.py:183) def reraise(self) -> t.NoReturn:
    [184](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/__init__.py:184)     if self.last_attempt.failed:
--> [185](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/__init__.py:185)         raise self.last_attempt.result()
    [186](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/__init__.py:186)     raise self

File ~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:449, in Future.result(self, timeout)
    [447](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:447)     raise CancelledError()
    [448](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:448) elif self._state == FINISHED:
--> [449](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:449)     return self.__get_result()
    [451](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:451) self._condition.wait(timeout)
    [453](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:453) if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:

File ~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:401, in Future.__get_result(self)
    [399](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:399) if self._exception:
    [400](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:400)     try:
--> [401](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:401)         raise self._exception
    [402](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:402)     finally:
    [403](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:403)         # Break a reference cycle with the exception in self._exception
    [404](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/concurrent/futures/_base.py:404)         self = None

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:114, in AsyncRetrying.__call__(self, fn, *args, **kwargs)
    [112](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:112) if isinstance(do, DoAttempt):
    [113](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:113)     try:
--> [114](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:114)         result = await fn(*args, **kwargs)
    [115](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:115)     except BaseException:  # noqa: B902
    [116](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/tenacity/asyncio/__init__.py:116)         retry_state.set_exception(sys.exc_info())  # type: ignore[arg-type]

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:287, in LlamaIndexLLMWrapper.agenerate_text(self, prompt, n, temperature, stop, callbacks)
    [284](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:284)     temperature = 1e-8
    [286](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:286) kwargs = self.check_args(n, temperature, stop, callbacks)
--> [287](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:287) li_response = await self.llm.acomplete(prompt.to_string(), **kwargs)
    [289](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/ragas/llms/base.py:289) return LLMResult(generations=[[Generation(text=li_response.text)]])

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:353, in Dispatcher.span.<locals>.async_wrapper(func, instance, args, kwargs)
    [345](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:345) self.span_enter(
    [346](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:346)     id_=id_,
    [347](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:347)     bound_args=bound_args,
   (...)
    [350](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:350)     tags=tags,
    [351](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:351) )
    [352](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:352) try:
--> [353](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:353)     result = await func(*args, **kwargs)
    [354](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:354) except BaseException as e:
    [355](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:355)     self.event(SpanDropEvent(span_id=id_, err_str=str(e)))

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:334, in llm_completion_callback.<locals>.wrap.<locals>.wrapped_async_llm_predict(_self, *args, **kwargs)
    [324](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:324) event_id = callback_manager.on_event_start(
    [325](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:325)     CBEventType.LLM,
    [326](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:326)     payload={
   (...)
    [330](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:330)     },
    [331](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:331) )
    [333](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:333) try:
--> [334](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:334)     f_return_val = await f(_self, *args, **kwargs)
    [335](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:335) except BaseException as e:
    [336](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:336)     callback_manager.on_event_end(
    [337](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:337)         CBEventType.LLM,
    [338](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:338)         payload={EventPayload.EXCEPTION: e},
    [339](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:339)         event_id=event_id,
    [340](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:340)     )

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:358, in Anthropic.acomplete(self, prompt, formatted, **kwargs)
    [353](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:353) @llm_completion_callback()
    [354](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:354) async def acomplete(
    [355](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:355)     self, prompt: str, formatted: bool = False, **kwargs: Any
    [356](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:356) ) -> CompletionResponse:
    [357](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:357)     acomplete_fn = achat_to_completion_decorator(self.achat)
--> [358](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:358)     return await acomplete_fn(prompt, **kwargs)

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/base/llms/generic_utils.py:221, in achat_to_completion_decorator.<locals>.wrapper(prompt, **kwargs)
    [218](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/base/llms/generic_utils.py:218) async def wrapper(prompt: str, **kwargs: Any) -> CompletionResponse:
    [219](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/base/llms/generic_utils.py:219)     # normalize input
    [220](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/base/llms/generic_utils.py:220)     messages = prompt_to_messages(prompt)
--> [221](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/base/llms/generic_utils.py:221)     chat_response = await func(messages, **kwargs)
    [222](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/base/llms/generic_utils.py:222)     # normalize output
    [223](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/base/llms/generic_utils.py:223)     return chat_response_to_completion_response(chat_response)

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:353, in Dispatcher.span.<locals>.async_wrapper(func, instance, args, kwargs)
    [345](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:345) self.span_enter(
    [346](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:346)     id_=id_,
    [347](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:347)     bound_args=bound_args,
   (...)
    [350](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:350)     tags=tags,
    [351](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:351) )
    [352](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:352) try:
--> [353](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:353)     result = await func(*args, **kwargs)
    [354](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:354) except BaseException as e:
    [355](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:355)     self.event(SpanDropEvent(span_id=id_, err_str=str(e)))

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:75, in llm_chat_callback.<locals>.wrap.<locals>.wrapped_async_llm_chat(_self, messages, **kwargs)
     [66](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:66) event_id = callback_manager.on_event_start(
     [67](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:67)     CBEventType.LLM,
     [68](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:68)     payload={
   (...)
     [72](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:72)     },
     [73](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:73) )
     [74](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:74) try:
---> [75](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:75)     f_return_val = await f(_self, messages, **kwargs)
     [76](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:76) except BaseException as e:
     [77](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:77)     callback_manager.on_event_end(
     [78](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:78)         CBEventType.LLM,
     [79](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:79)         payload={EventPayload.EXCEPTION: e},
     [80](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:80)         event_id=event_id,
     [81](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:81)     )

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:335, in Anthropic.achat(self, messages, **kwargs)
    [332](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:332) anthropic_messages, system_prompt = messages_to_anthropic_messages(messages)
    [333](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:333) all_kwargs = self._get_all_kwargs(**kwargs)
--> [335](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:335) response = await self._aclient.messages.create(
    [336](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:336)     messages=anthropic_messages,
    [337](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:337)     system=system_prompt,
    [338](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:338)     stream=False,
    [339](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:339)     **all_kwargs,
    [340](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:340) )
    [342](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:342) content, tool_calls = self._get_content_and_tool_calls(response)
    [344](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:344) return ChatResponse(
    [345](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:345)     message=ChatMessage(
    [346](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:346)         role=MessageRole.ASSISTANT,
   (...)
    [350](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:350)     raw=dict(response),
    [351](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:351) )

File ~/micromamba/envs/ragas/lib/python3.11/site-packages/anthropic/_utils/_utils.py:274, in required_args.<locals>.inner.<locals>.wrapper(*args, **kwargs)
    [272](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/anthropic/_utils/_utils.py:272)             msg = f"Missing required argument: {quote(missing[0])}"
    [273](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/anthropic/_utils/_utils.py:273)     raise TypeError(msg)
--> [274](https://file+.vscode-resource.vscode-cdn.net/Users/mithras/_code/AIMLbling-about/~/micromamba/envs/ragas/lib/python3.11/site-packages/anthropic/_utils/_utils.py:274) return func(*args, **kwargs)

TypeError: AsyncMessages.create() got an unexpected keyword argument 'n'

**Expected behavior**
Ragas should not throw an error


**Additional context**

This seems to be a combined issue between Anthropic, LlamaIndex, and Ragas:
- I successfully used Llamaindex's OpenAI and Together wrappers with success
- I have successfully run the equivalent code with Langchain using Anthropic

My guess is the problem lies with the intersection of the llamaindex llm wrapper _and_ that Anthropic strictly manages passed kwargs.

Specifically, [here](https://github.com/explodinggradients/ragas/blob/d92a573b68818482e7bb7bfd5842eaaf82cb0e9b/src/ragas/llms/base.py#L243C1-L244C86) indicates `n` isn't really supported with Llamaindex but it is still passed in `kwargs` during the `generate_text` and `agenerate_text` methods. 

<!-- 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 @ahgraber, how's it going? I'm here to help you out with any bugs, questions, or contributions you might have. Let's dive in and get that issue sorted!

<!-- Answer -->
To resolve the "TypeError: AsyncMessages.create() got an unexpected keyword argument 'n'" error, you need to modify the `check_args` method in the `LlamaIndexLLMWrapper` class. The `acomplete` method of the LLM does not expect an `n` argument, so it should be removed when the LLM is not of type "bedrock".

Here's how you can adjust the `check_args` method:

```python
def check_args(
    self,
    n: int,
    temperature: float,
    stop: t.Optional[t.List[str]],
    callbacks: Callbacks,
) -> dict[str, t.Any]:
    if n != 1:
        logger.warning("n values greater than 1 not supported for LlamaIndex LLMs")
    if temperature != 1e-8:
        logger.info("temperature kwarg passed to LlamaIndex LLM")
    if stop is not None:
        logger.info("stop kwarg passed to LlamaIndex LLM")
    if callbacks is not None:
        logger.info(
            "callbacks not supported for LlamaIndex LLMs, ignoring callbacks"
        )
    if self._signature == "bedrock":
        return {"temperature": temperature}
    else:
        return {
            "temperature": temperature,
            "stop": stop,
        }
```

By ensuring the `n` argument is not included in the dictionary returned by `check_args` when the LLM is not "bedrock", you should avoid the TypeError <sup>[[1]](https://github.com/explodinggradients/ragas/blob/main/src/ragas/llms/base.py)</sup>.


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


I can confirm that hacking the `check_args` method allows the Anthropic LLM call to work:

```py
    def check_args(
        self,
        n: int,
        temperature: float,
        stop: t.Optional[t.List[str]],
        callbacks: Callbacks,
    ) -> dict[str, t.Any]:
        if n != 1:
            logger.warning("n values greater than 1 not support for LlamaIndex LLMs")
        if temperature != 1e-8:
            logger.info("temperature kwarg passed to LlamaIndex LLM")
        if stop is not None:
            logger.info("stop kwarg passed to LlamaIndex LLM")
        if callbacks is not None:
            logger.info(
                "callbacks not supported for LlamaIndex LLMs, ignoring callbacks"
            )
        if (
            self._signature == "bedrock"
            or type(self.llm).__name__.lower() == "anthropic"
        ):
            # ref: https://github.com/explodinggradients/ragas/issues/1468
            return {"temperature": temperature}
        else:
            return {
                "n": n,
                "temperature": temperature,
                "stop": stop,
            }
```