Skip to content

Commit

Permalink
Merge branch 'main' into feat/lighter-embeddings
Browse files Browse the repository at this point in the history
  • Loading branch information
jjmachan committed Nov 15, 2023
2 parents eb24c4a + 2802019 commit 521155d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies = [
"langchain",
"openai",
"pysbd>=0.3.4",
"nest-asyncio",
]
dynamic = ["version", "readme"]

Expand Down
5 changes: 2 additions & 3 deletions src/ragas/embeddings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/ragas/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import typing as t
from dataclasses import dataclass, field

import numpy as np
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/ragas/llms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
...
4 changes: 2 additions & 2 deletions src/ragas/llms/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 521155d

Please sign in to comment.