-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #46 fixes #53 You can now use langchains LLM abstraction to access all the LLM endpoints langchain supports. eg ```python from langchain.chat_models import ChatOpenAI gpt4 = ChatOpenAI(model_name="gpt-4") gpt4.generate_prompt(prompts=[prompts]) # init a new Metric with llm cr = ContextRelevancy(llm=gpt4) cr.init_model() result = cr.score(ds.select(range(4))) result["context_relavency"] # [0.46687018871307373, 0.1532887363433838,0.17359847468989234, 0.17340516530234237] ``` We're also now using OpenAI's chat models as default which brings a 10x decrease in cost. also using `gpt-3.5-turbo-16k` as default for even bigger context size
- Loading branch information
Showing
9 changed files
with
208 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Async utils.""" | ||
import asyncio | ||
from typing import Any, Coroutine, List | ||
|
||
|
||
def run_async_tasks( | ||
tasks: List[Coroutine], | ||
show_progress: bool = False, | ||
progress_bar_desc: str = "Running async tasks", | ||
) -> List[Any]: | ||
"""Run a list of async tasks.""" | ||
|
||
tasks_to_execute: List[Any] = tasks | ||
if show_progress: | ||
try: | ||
import nest_asyncio | ||
from tqdm.asyncio import tqdm | ||
|
||
# jupyter notebooks already have an event loop running | ||
# we need to reuse it instead of creating a new one | ||
nest_asyncio.apply() | ||
loop = asyncio.get_event_loop() | ||
|
||
async def _tqdm_gather() -> List[Any]: | ||
return await tqdm.gather(*tasks_to_execute, desc=progress_bar_desc) | ||
|
||
tqdm_outputs: List[Any] = loop.run_until_complete(_tqdm_gather()) | ||
return tqdm_outputs | ||
# run the operation w/o tqdm on hitting a fatal | ||
# may occur in some environments where tqdm.asyncio | ||
# is not supported | ||
except Exception: | ||
pass | ||
|
||
async def _gather() -> List[Any]: | ||
return await asyncio.gather(*tasks_to_execute) | ||
|
||
outputs: List[Any] = asyncio.run(_gather()) | ||
return outputs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.