Skip to content

Commit

Permalink
Improvements and solved 3 issues (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
izam-mohammed authored May 9, 2024
2 parents 2b18d9a + 4a82e63 commit f21a155
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 183 deletions.
15 changes: 13 additions & 2 deletions docs/docs/get_started/basic_evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ Set your `OPENAI_API_KEY` as an environment variable
By default, we are using the OpenAI LLM for internal operations. You can change it later on. So please set your valid `OPENAI_API_KEY`, otherwise you will get internal error 🤓.
```

Set the API key with running this in the terminal. replace `<your_api_key>` with your actual API key.
```bash
export OPENAI_API_KEY="..."
export OPENAI_API_KEY="<your_api_key>"
```

Performing the evaluation in python
Alternatively, you can set the API key in python with `os` module. replace `<your_api_key>` with your actual API key.

```python
import os

os.environ["OPENAI_API_KEY"] = "<your_api_key>"
```

To perform the evaluation in Python, open the `main.py` file and add the following code:

```python
from ragrank import evaluate
Expand All @@ -35,6 +44,8 @@ result = evaluate(data, metrics=[response_relevancy])
result.to_dataframe()
```

After adding the code, run the `main.py` file.

Congratulations 🎉, you have done your first step.
> A journey of thousand miles starts with the first step 🌱.
Expand Down
63 changes: 1 addition & 62 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,105 +6,52 @@ anyio==4.3.0 ; python_version >= "3.9" and python_version < "4.0"
async-timeout==4.0.3 ; python_version >= "3.9" and python_version < "3.11"
attrs==23.2.0 ; python_version >= "3.9" and python_version < "4.0"
babel==2.14.0 ; python_version >= "3.9" and python_version < "4.0"
bandit==1.7.8 ; python_version >= "3.9" and python_version < "4.0"
beautifulsoup4==4.12.3 ; python_version >= "3.9" and python_version < "4.0"
bs4==0.0.2 ; python_version >= "3.9" and python_version < "4.0"
certifi==2024.2.2 ; python_version >= "3.9" and python_version < "4.0"
charset-normalizer==3.3.2 ; python_version >= "3.9" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.9" and python_version < "4.0"
codespell==2.2.6 ; python_version >= "3.9" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.9" and python_version < "4.0" and (platform_system == "Windows" or sys_platform == "win32")
coverage[toml]==7.4.4 ; python_version >= "3.9" and python_version < "4.0"
dataclasses-json==0.6.4 ; python_version >= "3.9" and python_version < "4.0"
datasets==2.18.0 ; python_version >= "3.9" and python_version < "4.0"
deprecated==1.2.14 ; python_version >= "3.9" and python_version < "4.0"
dill==0.3.8 ; python_version >= "3.9" and python_version < "4.0"
dirtyjson==1.0.8 ; python_version >= "3.9" and python_version < "4.0"
distro==1.9.0 ; python_version >= "3.9" and python_version < "4.0"
docutils==0.20.1 ; python_version >= "3.9" and python_version < "4.0"
exceptiongroup==1.2.0 ; python_version >= "3.9" and python_version < "3.11"
filelock==3.13.1 ; python_version >= "3.9" and python_version < "4.0"
flake8==7.0.0 ; python_version >= "3.9" and python_version < "4.0"
frozenlist==1.4.1 ; python_version >= "3.9" and python_version < "4.0"
fsspec==2024.2.0 ; python_version >= "3.9" and python_version < "4.0"
fsspec[http]==2024.2.0 ; python_version >= "3.9" and python_version < "4.0"
furo==2024.1.29 ; python_version >= "3.9" and python_version < "4.0"
greenlet==3.0.3 ; python_version >= "3.9" and python_version < "4.0"
h11==0.14.0 ; python_version >= "3.9" and python_version < "4.0"
httpcore==1.0.4 ; python_version >= "3.9" and python_version < "4.0"
httpx==0.27.0 ; python_version >= "3.9" and python_version < "4.0"
huggingface-hub==0.21.4 ; python_version >= "3.9" and python_version < "4.0"
idna==3.6 ; python_version >= "3.9" and python_version < "4.0"
imagesize==1.4.1 ; python_version >= "3.9" and python_version < "4.0"
importlib-metadata==7.0.2 ; python_version >= "3.9" and python_version < "3.10"
iniconfig==2.0.0 ; python_version >= "3.9" and python_version < "4.0"
isort==5.13.2 ; python_version >= "3.9" and python_version < "4.0"
importlib-metadata==7.1.0 ; python_version >= "3.9" and python_version < "3.10"
jinja2==3.1.3 ; python_version >= "3.9" and python_version < "4.0"
joblib==1.3.2 ; python_version >= "3.9" and python_version < "4.0"
jsonpatch==1.33 ; python_version >= "3.9" and python_version < "4.0"
jsonpointer==2.4 ; python_version >= "3.9" and python_version < "4.0"
langchain-core==0.1.32 ; python_version >= "3.9" and python_version < "4.0"
langchain-openai==0.0.8 ; python_version >= "3.9" and python_version < "4.0"
langsmith==0.1.31 ; python_version >= "3.9" and python_version < "4.0"
linkify-it-py==2.0.3 ; python_version >= "3.9" and python_version < "4.0"
llama-index-agent-openai==0.1.6 ; python_version >= "3.9" and python_version < "4.0"
llama-index-cli==0.1.10 ; python_version >= "3.9" and python_version < "4.0"
llama-index-core==0.10.20.post2 ; python_version >= "3.9" and python_version < "4.0"
llama-index-embeddings-openai==0.1.7 ; python_version >= "3.9" and python_version < "4.0"
llama-index-indices-managed-llama-cloud==0.1.4 ; python_version >= "3.9" and python_version < "4.0"
llama-index-legacy==0.9.48 ; python_version >= "3.9" and python_version < "4.0"
llama-index-llms-openai==0.1.12 ; python_version >= "3.9" and python_version < "4.0"
llama-index-multi-modal-llms-openai==0.1.4 ; python_version >= "3.9" and python_version < "4.0"
llama-index-program-openai==0.1.4 ; python_version >= "3.9" and python_version < "4.0"
llama-index-question-gen-openai==0.1.3 ; python_version >= "3.9" and python_version < "4.0"
llama-index-readers-file==0.1.11 ; python_version >= "3.9" and python_version < "4.0"
llama-index-readers-llama-parse==0.1.3 ; python_version >= "3.9" and python_version < "4.0"
llama-index==0.10.20 ; python_version >= "3.9" and python_version < "4.0"
llama-parse==0.3.9 ; python_version >= "3.9" and python_version < "4.0"
llamaindex-py-client==0.1.13 ; python_version >= "3.9" and python_version < "4.0"
markdown-it-py==3.0.0 ; python_version >= "3.9" and python_version < "4.0"
markupsafe==2.1.5 ; python_version >= "3.9" and python_version < "4.0"
marshmallow==3.21.1 ; python_version >= "3.9" and python_version < "4.0"
mccabe==0.7.0 ; python_version >= "3.9" and python_version < "4.0"
mdit-py-plugins==0.4.0 ; python_version >= "3.9" and python_version < "4.0"
mdurl==0.1.2 ; python_version >= "3.9" and python_version < "4.0"
multidict==6.0.5 ; python_version >= "3.9" and python_version < "4.0"
multiprocess==0.70.16 ; python_version >= "3.9" and python_version < "4.0"
mypy-extensions==1.0.0 ; python_version >= "3.9" and python_version < "4.0"
myst-parser==2.0.0 ; python_version >= "3.9" and python_version < "4.0"
nest-asyncio==1.6.0 ; python_version >= "3.9" and python_version < "4.0"
networkx==3.2.1 ; python_version >= "3.9" and python_version < "4.0"
nltk==3.8.1 ; python_version >= "3.9" and python_version < "4.0"
numpy==1.26.4 ; python_version >= "3.9" and python_version < "4.0"
openai==1.14.2 ; python_version >= "3.9" and python_version < "4.0"
orjson==3.9.15 ; python_version >= "3.9" and python_version < "4.0"
packaging==23.2 ; python_version >= "3.9" and python_version < "4.0"
pandas==2.2.1 ; python_version >= "3.9" and python_version < "4.0"
pathlib==1.0.1 ; python_version >= "3.9" and python_version < "4.0"
pbr==6.0.0 ; python_version >= "3.9" and python_version < "4.0"
pillow==10.2.0 ; python_version >= "3.9" and python_version < "4.0"
pluggy==1.4.0 ; python_version >= "3.9" and python_version < "4.0"
pockets==0.9.1 ; python_version >= "3.9" and python_version < "4.0"
pyarrow-hotfix==0.6 ; python_version >= "3.9" and python_version < "4.0"
pyarrow==15.0.2 ; python_version >= "3.9" and python_version < "4.0"
pycodestyle==2.11.1 ; python_version >= "3.9" and python_version < "4.0"
pydantic-core==2.16.3 ; python_version >= "3.9" and python_version < "4.0"
pydantic==2.6.4 ; python_version >= "3.9" and python_version < "4.0"
pyflakes==3.2.0 ; python_version >= "3.9" and python_version < "4.0"
pygments==2.17.2 ; python_version >= "3.9" and python_version < "4.0"
pymupdf==1.23.26 ; python_version >= "3.9" and python_version < "4.0"
pymupdfb==1.23.22 ; python_version >= "3.9" and python_version < "4.0"
pypdf==4.1.0 ; python_version >= "3.9" and python_version < "4.0"
pytest-cov==4.1.0 ; python_version >= "3.9" and python_version < "4.0"
pytest==8.1.1 ; python_version >= "3.9" and python_version < "4.0"
python-dateutil==2.9.0.post0 ; python_version >= "3.9" and python_version < "4.0"
pytz==2024.1 ; python_version >= "3.9" and python_version < "4.0"
pyyaml==6.0.1 ; python_version >= "3.9" and python_version < "4.0"
regex==2023.12.25 ; python_version >= "3.9" and python_version < "4.0"
requests-toolbelt==1.0.0 ; python_version >= "3.9" and python_version < "4.0"
requests==2.31.0 ; python_version >= "3.9" and python_version < "4.0"
rich==13.7.1 ; python_version >= "3.9" and python_version < "4.0"
ruff==0.2.2 ; python_version >= "3.9" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.9" and python_version < "4.0"
sniffio==1.3.1 ; python_version >= "3.9" and python_version < "4.0"
snowballstemmer==2.2.0 ; python_version >= "3.9" and python_version < "4.0"
Expand All @@ -125,19 +72,11 @@ sphinxcontrib-napoleon==0.7 ; python_version >= "3.9" and python_version < "4.0"
sphinxcontrib-qthelp==1.0.7 ; python_version >= "3.9" and python_version < "4.0"
sphinxcontrib-serializinghtml==1.1.10 ; python_version >= "3.9" and python_version < "4.0"
sphinxext-opengraph==0.9.1 ; python_version >= "3.9" and python_version < "4.0"
sqlalchemy[asyncio]==2.0.28 ; python_version >= "3.9" and python_version < "4.0"
stevedore==5.2.0 ; python_version >= "3.9" and python_version < "4.0"
striprtf==0.0.26 ; python_version >= "3.9" and python_version < "4.0"
tenacity==8.2.3 ; python_version >= "3.9" and python_version < "4.0"
tiktoken==0.6.0 ; python_version >= "3.9" and python_version < "4.0"
tomli==2.0.1 ; python_version >= "3.9" and python_full_version <= "3.11.0a6"
tqdm==4.66.2 ; python_version >= "3.9" and python_version < "4.0"
typing-extensions==4.10.0 ; python_version >= "3.9" and python_version < "4.0"
typing-inspect==0.9.0 ; python_version >= "3.9" and python_version < "4.0"
tzdata==2024.1 ; python_version >= "3.9" and python_version < "4.0"
uc-micro-py==1.0.3 ; python_version >= "3.9" and python_version < "4.0"
urllib3==2.2.1 ; python_version >= "3.9" and python_version < "4.0"
wrapt==1.16.0 ; python_version >= "3.9" and python_version < "4.0"
xxhash==3.4.1 ; python_version >= "3.9" and python_version < "4.0"
yarl==1.9.4 ; python_version >= "3.9" and python_version < "4.0"
zipp==3.18.1 ; python_version >= "3.9" and python_version < "3.10"
Expand Down
106 changes: 0 additions & 106 deletions src/ragrank/_trace.py

This file was deleted.

17 changes: 17 additions & 0 deletions src/ragrank/dataset/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ def to_dataset(self) -> Dataset:
logger.info("DataNode converted to Dataset succesfully !")
return dataset

def __add__(self, other: DataNode) -> Dataset:
"""
Concatenate two Datanodes.
Args:
other (DataNode): The datanode to concatenate with.
Returns:
Dataset: The concatenated dataset.
"""
combined_dataset = Dataset(
question=[self.question, other.question],
context=[self.context, other.context],
response=[self.response, other.response],
)
return combined_dataset


class Dataset(BaseModel):
"""
Expand Down
14 changes: 1 addition & 13 deletions src/ragrank/evaluation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
from time import time
from typing import List, Optional

from numpy import mean

from ragrank._trace import EvaluationEvent, trace
from ragrank.bridge.pydantic import validate_call
from ragrank.dataset import DataNode, Dataset, from_dict
from ragrank.evaluation.outputs import EvalResult
Expand Down Expand Up @@ -87,14 +84,5 @@ def evaluate(
response_time=delta,
scores=scores,
)
evaluation_event = EvaluationEvent(
llm=llm.name,
time_cost=delta,
metrics={
metrics[i].name: mean(scores[i])
for i in range(len(metrics))
},
data_size=len(data),
)
trace(evaluation_event)

return result

0 comments on commit f21a155

Please sign in to comment.