Skip to content

Commit 3e81fe3

Browse files
authored
feat: adding new defaults to openai Model and embeddings (#973)
change default models for OpenAI - LLM: gpt-3.5-turbo - embeddings: text-embedding-ada-002 Also fixes the MacOS runners and CI
1 parent f3a800d commit 3e81fe3

File tree

7 files changed

+30
-24
lines changed

7 files changed

+30
-24
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
fail-fast: false
5353
matrix:
5454
os: [ubuntu-latest, macos-latest, windows-latest]
55-
python-version: ["3.8", "3.9", "3.10", "3.11"]
55+
python-version: ["3.9", "3.10", "3.11", "3.12"]
5656

5757
if: ${{ (github.event_name == 'pull_request' && needs.diff.outputs.ragas == 'true') || github.event_name == 'push' }}
5858
name: python${{ matrix.python-version }}_unit_tests (${{ matrix.os }})
@@ -64,10 +64,10 @@ jobs:
6464
fetch-depth: 0 # fetch all tags and branches
6565

6666
- name: Setup python
67-
uses: actions/setup-python@v4
67+
uses: actions/setup-python@v5
6868
with:
6969
python-version: ${{ matrix.python-version }}
70-
architecture: x64
70+
architecture: ${{ matrix.os == 'macos-latest' && 'arm64' || 'x64' }}
7171

7272
- name: Get pip cache dir
7373
id: cache-dir

docs/howtos/customisations/gcp-vertexai.ipynb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@
100100
"source": [
101101
"from ragas.metrics import (\n",
102102
" context_precision,\n",
103-
" answer_relevancy, \n",
103+
" answer_relevancy,\n",
104104
" faithfulness,\n",
105105
" context_recall,\n",
106-
" answer_similarity, \n",
106+
" answer_similarity,\n",
107107
" answer_correctness,\n",
108108
")\n",
109109
"from ragas.metrics.critique import harmfulness\n",
@@ -150,13 +150,12 @@
150150
"\n",
151151
"# create Langchain LLM and Embeddings\n",
152152
"vertextai_llm = ChatVertexAI(\n",
153-
" credentials=creds,\n",
154-
" model_name=config['chat_model_id'],\n",
155-
" )\n",
156-
"vertextai_embeddings = VertexAIEmbeddings(\n",
157153
" credentials=creds,\n",
158-
" model_name=config[\"embedding_model_id\"]\n",
159-
" )"
154+
" model_name=config[\"chat_model_id\"],\n",
155+
")\n",
156+
"vertextai_embeddings = VertexAIEmbeddings(\n",
157+
" credentials=creds, model_name=config[\"embedding_model_id\"]\n",
158+
")"
160159
]
161160
},
162161
{

docs/howtos/integrations/langfuse.ipynb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
"from ragas.run_config import RunConfig\n",
163163
"from ragas.metrics.base import MetricWithLLM, MetricWithEmbeddings\n",
164164
"\n",
165+
"\n",
165166
"# util function to init Ragas Metrics\n",
166167
"def init_ragas_metrics(metrics, llm, embedding):\n",
167168
" for metric in metrics:\n",
@@ -183,7 +184,7 @@
183184
"from langchain_openai.chat_models import ChatOpenAI\n",
184185
"from langchain_openai.embeddings import OpenAIEmbeddings\n",
185186
"\n",
186-
"# wrappers \n",
187+
"# wrappers\n",
187188
"from ragas.llms import LangchainLLMWrapper\n",
188189
"from ragas.embeddings import LangchainEmbeddingsWrapper\n",
189190
"\n",
@@ -368,14 +369,16 @@
368369
"metadata": {},
369370
"outputs": [],
370371
"source": [
371-
"# the logic of the dummy application is \n",
372+
"# the logic of the dummy application is\n",
372373
"# given a question fetch the correspoinding contexts and answers from a dict\n",
373374
"\n",
374375
"import hashlib\n",
375376
"\n",
377+
"\n",
376378
"def hash_string(input_string):\n",
377379
" return hashlib.sha256(input_string.encode()).hexdigest()\n",
378380
"\n",
381+
"\n",
379382
"q_to_c = {} # map between question and context\n",
380383
"q_to_a = {} # map between question and answer\n",
381384
"for row in amnesty_qa:\n",
@@ -394,6 +397,7 @@
394397
"# if your running this in a notebook - please run this cell\n",
395398
"# to manage asyncio event loops\n",
396399
"import nest_asyncio\n",
400+
"\n",
397401
"nest_asyncio.apply()"
398402
]
399403
},
@@ -407,14 +411,17 @@
407411
"from langfuse.decorators import observe, langfuse_context\n",
408412
"from asyncio import run\n",
409413
"\n",
414+
"\n",
410415
"@observe()\n",
411416
"def retriver(question: str):\n",
412417
" return q_to_c[question]\n",
413418
"\n",
419+
"\n",
414420
"@observe()\n",
415421
"def generator(question):\n",
416422
" return q_to_a[question]\n",
417423
"\n",
424+
"\n",
418425
"@observe()\n",
419426
"def rag_pipeline(question):\n",
420427
" q_hash = hash_string(question)\n",
@@ -424,10 +431,7 @@
424431
" # score the runs\n",
425432
" score = run(score_with_ragas(question, contexts, answer=generated_answer))\n",
426433
" for s in score:\n",
427-
" langfuse_context.score_current_trace(\n",
428-
" name=s,\n",
429-
" value=score[s]\n",
430-
" )\n",
434+
" langfuse_context.score_current_trace(name=s, value=score[s])\n",
431435
" return generated_answer"
432436
]
433437
},

src/ragas/embeddings/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ def predict(self, texts: List[List[str]]) -> List[List[float]]:
153153
return predictions.tolist()
154154

155155

156-
def embedding_factory(run_config: t.Optional[RunConfig] = None) -> BaseRagasEmbeddings:
157-
openai_embeddings = OpenAIEmbeddings()
156+
def embedding_factory(
157+
model: str = "text-embedding-ada-002", run_config: t.Optional[RunConfig] = None
158+
) -> BaseRagasEmbeddings:
159+
openai_embeddings = OpenAIEmbeddings(model=model)
158160
if run_config is not None:
159161
openai_embeddings.request_timeout = run_config.timeout
160162
else:

src/ragas/llms/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def generate_text(
6161
temperature: float = 1e-8,
6262
stop: t.Optional[t.List[str]] = None,
6363
callbacks: Callbacks = None,
64-
) -> LLMResult: ...
64+
) -> LLMResult:
65+
...
6566

6667
@abstractmethod
6768
async def agenerate_text(
@@ -71,7 +72,8 @@ async def agenerate_text(
7172
temperature: float = 1e-8,
7273
stop: t.Optional[t.List[str]] = None,
7374
callbacks: Callbacks = None,
74-
) -> LLMResult: ...
75+
) -> LLMResult:
76+
...
7577

7678
async def generate(
7779
self,
@@ -202,7 +204,7 @@ def set_run_config(self, run_config: RunConfig):
202204

203205

204206
def llm_factory(
205-
model: str = "gpt-3.5-turbo-16k", run_config: t.Optional[RunConfig] = None
207+
model: str = "gpt-3.5-turbo", run_config: t.Optional[RunConfig] = None
206208
) -> BaseRagasLLM:
207209
timeout = None
208210
if run_config is not None:

src/ragas/testset/generator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def from_langchain(
104104
docstore=docstore,
105105
)
106106

107-
108107
@classmethod
109108
@deprecated("0.1.4", removal="0.2.0", alternative="from_langchain")
110109
def with_openai(

tests/benchmarks/benchmark_eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
]
3535

3636
# os.environ["PYTHONASYNCIODEBUG"] = "1"
37-
IGNORE_THREADS = False
37+
IGNORE_THREADS = True
3838
IGNORE_ASYNCIO = False
3939

4040
if __name__ == "__main__":

0 commit comments

Comments
 (0)