From ef1b138828d5b54c66cbc0718605c8abf5885ba3 Mon Sep 17 00:00:00 2001 From: Ryan Nguyen <96593302+xpbowler@users.noreply.github.com> Date: Sat, 7 Sep 2024 01:18:42 -0400 Subject: [PATCH 1/3] fix extract_kwargs, add another openapi key env variable name (#141) --- src/rank_llm/rerank/api_keys.py | 12 +++++++++++- src/rank_llm/rerank/reranker.py | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rank_llm/rerank/api_keys.py b/src/rank_llm/rerank/api_keys.py index 565d4c37..92c3044f 100644 --- a/src/rank_llm/rerank/api_keys.py +++ b/src/rank_llm/rerank/api_keys.py @@ -3,10 +3,20 @@ from dotenv import load_dotenv +# Common OpenAI API key paths +paths = [ + "OPENAI_API_KEY", + "OPEN_AI_API_KEY", +] + def get_openai_api_key() -> str: load_dotenv(dotenv_path=f".env.local") - return os.getenv("OPEN_AI_API_KEY") + + for path in paths: + if os.getenv(path) is not None: + return os.getenv(path) + return None def get_azure_openai_args() -> Dict[str, str]: diff --git a/src/rank_llm/rerank/reranker.py b/src/rank_llm/rerank/reranker.py index a35853b6..efe7b6e8 100644 --- a/src/rank_llm/rerank/reranker.py +++ b/src/rank_llm/rerank/reranker.py @@ -376,7 +376,9 @@ def extract_kwargs( """ extracted_kwargs = [] for key, default in keys_and_defaults: - value = kwargs.get(key, default) + value = kwargs.get(key, None) + if value is None: + value = default if ( value is not None and default is not None From 18a6604df510fcd546b259ae542fb1e7ccbfb0cf Mon Sep 17 00:00:00 2001 From: Ryan Nguyen <96593302+xpbowler@users.noreply.github.com> Date: Sat, 7 Sep 2024 10:19:17 -0400 Subject: [PATCH 2/3] Remove retrieve_and_rerank from global namespace (#142) * fix extract_kwargs, add another openapi key env variable name * Remove retrieve_and_rerank from global namespace --- src/rank_llm/__init__.py | 3 --- src/rank_llm/api/server.py | 2 +- src/rank_llm/retrieve_and_rerank.py | 3 ++- src/rank_llm/scripts/run_rank_llm.py | 2 +- test/retrieve/test_ServiceRetriever.py | 2 +- test/test_retrieve_and_rerank.py | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/rank_llm/__init__.py b/src/rank_llm/__init__.py index 8daabe27..e69de29b 100644 --- a/src/rank_llm/__init__.py +++ b/src/rank_llm/__init__.py @@ -1,3 +0,0 @@ -from .retrieve_and_rerank import retrieve_and_rerank - -__all__ = ["retrieve_and_rerank"] diff --git a/src/rank_llm/api/server.py b/src/rank_llm/api/server.py index 30c49f6e..89d597ed 100644 --- a/src/rank_llm/api/server.py +++ b/src/rank_llm/api/server.py @@ -3,10 +3,10 @@ import torch from flask import Flask, jsonify, request -from rank_llm import retrieve_and_rerank from rank_llm.rerank import PromptMode, get_azure_openai_args, get_openai_api_key from rank_llm.rerank.listwise import RankListwiseOSLLM, SafeOpenai from rank_llm.retrieve import RetrievalMethod, RetrievalMode +from rank_llm.retrieve_and_rerank import retrieve_and_rerank """ API URL FORMAT diff --git a/src/rank_llm/retrieve_and_rerank.py b/src/rank_llm/retrieve_and_rerank.py index 992985dd..a58b3f40 100644 --- a/src/rank_llm/retrieve_and_rerank.py +++ b/src/rank_llm/retrieve_and_rerank.py @@ -2,7 +2,6 @@ from typing import Any, Dict, List, Union from rank_llm.data import Query, Request -from rank_llm.evaluation.trec_eval import EvalFunction from rank_llm.rerank import IdentityReranker, RankLLM, Reranker from rank_llm.rerank.reranker import extract_kwargs from rank_llm.retrieve import ( @@ -104,6 +103,8 @@ def retrieve_and_rerank( and dataset not in ["dl22", "dl22-passage", "news"] and TOPICS[dataset] not in ["dl22", "dl22-passage", "news"] ): + from rank_llm.evaluation.trec_eval import EvalFunction + print("Evaluating:") EvalFunction.eval(["-c", "-m", "ndcg_cut.1", TOPICS[dataset], file_name]) EvalFunction.eval(["-c", "-m", "ndcg_cut.5", TOPICS[dataset], file_name]) diff --git a/src/rank_llm/scripts/run_rank_llm.py b/src/rank_llm/scripts/run_rank_llm.py index 3639525b..c9cfedd7 100644 --- a/src/rank_llm/scripts/run_rank_llm.py +++ b/src/rank_llm/scripts/run_rank_llm.py @@ -9,9 +9,9 @@ parent = os.path.dirname(parent) sys.path.append(parent) -from rank_llm import retrieve_and_rerank from rank_llm.rerank import PromptMode from rank_llm.retrieve import TOPICS, RetrievalMethod, RetrievalMode +from rank_llm.retrieve_and_rerank import retrieve_and_rerank def main(args): diff --git a/test/retrieve/test_ServiceRetriever.py b/test/retrieve/test_ServiceRetriever.py index 820e1cdb..46c2c8a2 100644 --- a/test/retrieve/test_ServiceRetriever.py +++ b/test/retrieve/test_ServiceRetriever.py @@ -1,8 +1,8 @@ import unittest -from rank_llm import retrieve_and_rerank from rank_llm.data import Candidate, Query, Request from rank_llm.retrieve import RetrievalMethod, RetrievalMode, ServiceRetriever +from rank_llm.retrieve_and_rerank import retrieve_and_rerank class TestServiceRetriever(unittest.TestCase): diff --git a/test/test_retrieve_and_rerank.py b/test/test_retrieve_and_rerank.py index 917b635b..f99f4782 100644 --- a/test/test_retrieve_and_rerank.py +++ b/test/test_retrieve_and_rerank.py @@ -1,7 +1,7 @@ import unittest from unittest.mock import MagicMock, patch -from rank_llm import retrieve_and_rerank +from rank_llm.retrieve_and_rerank import retrieve_and_rerank # Anserini API must be hosted at 8081 From da75f4f2f88c544bd5c1612ecbb7a346fd7b28f1 Mon Sep 17 00:00:00 2001 From: Ronak Date: Sat, 7 Sep 2024 19:16:12 -0400 Subject: [PATCH 3/3] Update RankLLM to 0.20.2 --- README.md | 2 +- pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 10e07a36..46a639fa 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ We offer a suite of rerankers - pointwise models like monoT5 and listwise models with a focus on open source LLMs compatible with [FastChat](https://github.com/lm-sys/FastChat?tab=readme-ov-file#supported-models) (e.g., Vicuna, Zephyr, etc.) or [vLLM](https://https://github.com/vllm-project/vllm). We also support RankGPT variants, which are proprietary listwise rerankers. Some of the code in this repository is borrowed from [RankGPT](https://github.com/sunnweiwei/RankGPT), [PyGaggle](https://github.com/castorini/pygaggle), and [LiT5](https://github.com/castorini/LiT5)! # Releases -current_version = 0.20.1 +current_version = 0.20.2 ## 📟 Instructions diff --git a/pyproject.toml b/pyproject.toml index 977c513d..7add470d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "rank-llm" -version = "0.20.1" +version = "0.20.2" description = "A Package for running prompt decoders like RankVicuna" readme = "README.md" authors = [ @@ -35,7 +35,7 @@ vllm = [ Homepage = "https://github.com/castorini/rank_llm" [tool.bumpver] -current_version = "0.20.1" +current_version = "0.20.2" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true