Skip to content

Commit

Permalink
Support Python 3.8 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurCamara authored May 31, 2024
1 parent 6e7cc2a commit d868c81
Show file tree
Hide file tree
Showing 21 changed files with 279 additions and 226 deletions.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
]
description = "RAGElo: A Tool for Evaluating Retrieval-Augmented Generation Models"
readme = "README.md"
requires-python = ">=3.10"
requires-python = ">=3.8"
license = { text = "Apache-2.0" }
dynamic = ["version"]
classifiers = [
Expand Down Expand Up @@ -38,7 +38,7 @@ dev = [
"mypy==1.9.0",
"Flake8-pyproject==1.2.3",
"types-tqdm==4.66.0",
"pydantic==2.7.0",
"pydantic>=1.9.0",
"pytest-asyncio==0.23.6",
"pytest-mock==3.12.0",
]
Expand All @@ -58,7 +58,7 @@ profile = "black"

[tool.mypy]
plugins = ["pydantic.mypy"]
python_version = "3.11"
python_version = "3.8"
show_column_numbers = true
namespace_packages = true
follow_imports = "silent"
Expand Down
19 changes: 9 additions & 10 deletions ragelo/agent_rankers/base_agent_ranker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import csv
from collections import defaultdict
from typing import Optional, Type, get_type_hints
from typing import Dict, List, Optional, Tuple, Type, get_type_hints

# from ragelo.agent_rankers import *
from ragelo.logger import logger
from ragelo.types import AgentRankerConfig
from ragelo.types.types import Query
Expand All @@ -13,7 +12,7 @@

class AgentRanker:
config: AgentRankerConfig
ranking: defaultdict[str, list[str]]
ranking: Dict[str, List[str]]
output_file: str = "agents_ranking.csv"
name: str = "Agent Ranker"

Expand All @@ -28,17 +27,17 @@ def __init__(

def run(
self,
queries: Optional[list[Query]] = None,
queries: Optional[List[Query]] = None,
evaluations_file: Optional[str] = None,
) -> list[Query]:
) -> List[Query]:
"""Compute score for each agent"""
raise NotImplementedError

def _prepare_queries(
self,
queries: Optional[list[Query]] = None,
queries: Optional[List[Query]] = None,
evaluations_file: Optional[str] = None,
) -> list[Query]:
) -> List[Query]:
if queries is None:
if evaluations_file is None:
raise ValueError(
Expand All @@ -53,7 +52,7 @@ def from_config(cls, config: AgentRankerConfig):
# evaluations = cls.load_evaluations(config.evaluations_file)
# return cls(config, evaluations)

def get_agents_ratings(self) -> dict[str, float]:
def get_agents_ratings(self) -> Dict[str, float]:
"""Returns the score of all players"""
raise NotImplementedError

Expand Down Expand Up @@ -96,7 +95,7 @@ def print_ranking(self):
def get_config_class(cls) -> Type[AgentRankerConfig]:
return get_type_hints(cls)["config"]

def _flatten_evaluations(self, queries) -> list[tuple[str, str, str]]:
def _flatten_evaluations(self, queries) -> List[Tuple[str, str, str]]:
evaluations = []
for q in queries:
for game in q.pairwise_games:
Expand All @@ -111,7 +110,7 @@ def _flatten_evaluations(self, queries) -> list[tuple[str, str, str]]:


class AgentRankerFactory:
registry: dict[str, Type[AgentRanker]] = {}
registry: Dict[str, Type[AgentRanker]] = {}

@classmethod
def register(cls, name: str):
Expand Down
14 changes: 7 additions & 7 deletions ragelo/agent_rankers/elo_ranker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from typing import Optional
from typing import Dict, List, Optional, Tuple

from ragelo.agent_rankers.base_agent_ranker import AgentRanker, AgentRankerFactory
from ragelo.logger import logger
Expand All @@ -19,21 +19,21 @@ def __init__(
super().__init__(config)
self.score_map = {"A": 1, "B": 0, "C": 0.5}

self.agents: dict[str, int] = {}
self.games: list[tuple[str, str, float]] = []
self.agents: Dict[str, int] = {}
self.games: List[Tuple[str, str, float]] = []
self.computed = False
self.initial_score = self.config.initial_score
self.k = self.config.k

def run(
self,
queries: Optional[list[Query]] = None,
queries: Optional[List[Query]] = None,
evaluations_file: Optional[str] = None,
):
"""Compute score for each agent"""
queries = self._prepare_queries(queries, evaluations_file)
self.evaluations = self._flatten_evaluations(queries)
agent_scores: dict[str, list[int]] = {}
agent_scores: Dict[str, List[int]] = {}
for _ in range(self.config.rounds):
self.games = self.__get_elo_scores()
while self.games:
Expand All @@ -54,8 +54,8 @@ def get_agents_ratings(self):
raise ValueError("Ranking not computed yet, Run evaluate() first")
return self.agents

def __get_elo_scores(self) -> list[tuple[str, str, float]]:
games: list[tuple[str, str, float]] = []
def __get_elo_scores(self) -> List[Tuple[str, str, float]]:
games: List[Tuple[str, str, float]] = []
for agent_a, agent_b, score in self.evaluations:
score_val = self.score_map[score]
games.append((agent_a, agent_b, score_val))
Expand Down
4 changes: 2 additions & 2 deletions ragelo/cli/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import collections.abc
import inspect
from typing import Any, Callable, get_args, get_origin, get_type_hints
from typing import Any, Callable, Dict, get_args, get_origin, get_type_hints

from typer.models import ArgumentInfo, OptionInfo, ParameterInfo, ParamMeta

Expand All @@ -26,7 +26,7 @@ def callable(value: str):
return value


def get_params_from_function(func: Callable[..., Any]) -> dict[str, ParamMeta]:
def get_params_from_function(func: Callable[..., Any]) -> Dict[str, ParamMeta]:
signature = inspect.signature(func)

type_hints = get_type_hints(func)
Expand Down
Loading

0 comments on commit d868c81

Please sign in to comment.