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

[BFCL] Handling rate limits #559

Merged
merged 7 commits into from
Aug 4, 2024
Merged
Changes from 2 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
22 changes: 18 additions & 4 deletions berkeley-function-call-leaderboard/openfunctions_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import argparse, json, os
import argparse, json, os, time
from tqdm import tqdm
from model_handler.handler_map import handler_map
from model_handler.model_style import ModelStyle
Expand Down Expand Up @@ -91,6 +91,7 @@ def collect_test_cases(test_filename_total, model_name):


def generate_results(args, model_name, test_cases_total):
retry_limit = 3
handler = build_handler(model_name, args.temperature, args.top_p, args.max_tokens)

if handler.model_style == ModelStyle.OSSMODEL:
Expand All @@ -114,9 +115,22 @@ def generate_results(args, model_name, test_cases_total):
if type(functions) is dict or type(functions) is str:
functions = [functions]

result, metadata = handler.inference(
user_question, functions, test_category
)
retry_count = 0

while retry_count < retry_limit:
try:
result, metadata = handler.inference(
user_question, functions, test_category
)
break # Success, exit the loop
except Exception as e:
if "Rate limit reached" in str(e) and retry_count < retry_limit - 1:
print(f"Rate limit reached. Sleeping for 65 seconds. Retry {retry_count + 1}/{retry_limit}")
time.sleep(65)
retry_count += 1
else:
print("Maximum retries reached or other error encountered.")
raise e # Rethrow the last caught exception
result_to_write = {
"id": test_case["id"],
"result": result,
Expand Down