diff --git a/pyproject.toml b/pyproject.toml index 3edbf780b..3faeecb8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ dependencies = [ "langchain", "openai", "pysbd>=0.3.4", + "nest-asyncio", ] dynamic = ["version", "readme"] diff --git a/src/ragas/embeddings/base.py b/src/ragas/embeddings/base.py index 2947dac69..634a7da15 100644 --- a/src/ragas/embeddings/base.py +++ b/src/ragas/embeddings/base.py @@ -64,7 +64,7 @@ def __init__( openai_api_key = api_key super(BaseAzureOpenAIEmbeddings, self).__init__( - azure_endpoint=azure_endpoint, + azure_endpoint=azure_endpoint, # type: ignore (pydantic bug I think) deployment=deployment, api_version=api_version, api_key=openai_api_key, @@ -152,6 +152,5 @@ def predict(self, texts: List[List[str]]) -> List[List[float]]: def embedding_factory() -> RagasEmbeddings: - oai_key = os.getenv("OPENAI_API_KEY", "no-key") - openai_embeddings = OpenAIEmbeddings(api_key=oai_key) + openai_embeddings = OpenAIEmbeddings() return openai_embeddings diff --git a/src/ragas/evaluation.py b/src/ragas/evaluation.py index 7d8aa45a1..e7e270b03 100644 --- a/src/ragas/evaluation.py +++ b/src/ragas/evaluation.py @@ -1,5 +1,6 @@ from __future__ import annotations +import typing as t from dataclasses import dataclass, field import numpy as np @@ -133,6 +134,7 @@ def __post_init__(self): value = np.mean(self.scores[cn]) self[cn] = value if cn not in self.binary_columns: + value = t.cast(float, value) values.append(value + 1e-10) def to_pandas(self, batch_size: int | None = None, batched: bool = False): diff --git a/src/ragas/llms/base.py b/src/ragas/llms/base.py index f8e76675f..b291bf72b 100644 --- a/src/ragas/llms/base.py +++ b/src/ragas/llms/base.py @@ -49,7 +49,7 @@ async def agenerate( self, prompts: ChatPromptTemplate, n: int = 1, - temperature: float = 0, + temperature: float = 1e-8, callbacks: t.Optional[Callbacks] = None, ) -> LLMResult: ... diff --git a/src/ragas/llms/langchain.py b/src/ragas/llms/langchain.py index 986b93723..1fe3099c7 100644 --- a/src/ragas/llms/langchain.py +++ b/src/ragas/llms/langchain.py @@ -188,11 +188,11 @@ def generate( self, prompts: list[ChatPromptTemplate], n: int = 1, - temperature: float = 0, + temperature: float = 1e-8, callbacks: t.Optional[Callbacks] = None, ) -> LLMResult: # set temperature to 0.2 for multiple completions - temperature = 0.2 if n > 1 else 0 + temperature = 0.2 if n > 1 else 1e-8 if isBedrock(self.llm) and ("model_kwargs" in self.llm.__dict__): self.llm.model_kwargs = {"temperature": temperature} else: