Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for empower API #16

Merged
merged 16 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions eval/collect_rag_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
import asyncio
import json
import logging
from typing import Dict, Any
from typing import Dict, Any, List, Optional

import aiohttp
from tqdm.asyncio import tqdm_asyncio


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


async def fetch_recommendation(
session: aiohttp.ClientSession, query: Dict[str, Any], endpoint: str
) -> Dict[str, Any]:
) -> Optional[Dict[str, Any]]:
"""Fetch recommendation from the RAG system API."""
try:
async with session.post(
Expand All @@ -41,19 +40,19 @@ async def fetch_recommendation(


async def process_samples(
samples_file: str, output_file: str, batch_size: int = 5
samples_file: str, output_file: str, endpoint: str, batch_size: int = 5
) -> None:
"""Process samples in batches and save results."""
# Load samples
with open(samples_file, "r") as f:
samples = json.load(f)

results = []
results: List[Dict[str, Any]] = []
async with aiohttp.ClientSession() as session:
# Process in batches
for i in range(0, len(samples), batch_size):
batch = samples[i : i + batch_size]
tasks = [fetch_recommendation(session, query) for query in batch]
tasks = [fetch_recommendation(session, query, endpoint) for query in batch]
batch_results = await tqdm_asyncio.gather(*tasks)
results.extend([r for r in batch_results if r is not None])

Expand Down Expand Up @@ -89,7 +88,9 @@ def main() -> None:

args = parser.parse_args()

asyncio.run(process_samples(args.input, args.output, args.batch_size))
asyncio.run(
process_samples(args.input, args.output, args.endpoint, args.batch_size)
)


if __name__ == "__main__":
Expand Down
Loading