-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BFCL] Add New Model
DeepSeek-V3
(#857)
This PR adds new model `DeepSeek-V3` to the leaderboard. Even though this model is open-sourced on huggingface, due to its huge model size (685B), we will use its hosted API endpoint for inference.
- Loading branch information
1 parent
859e707
commit 0cea216
Showing
7 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
berkeley-function-call-leaderboard/bfcl/model_handler/proprietary_model/deepseek.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
import time | ||
|
||
from bfcl.model_handler.model_style import ModelStyle | ||
from bfcl.model_handler.proprietary_model.openai import OpenAIHandler | ||
from bfcl.model_handler.utils import retry_with_backoff | ||
from openai import OpenAI, RateLimitError | ||
from overrides import override | ||
|
||
|
||
# For setup instructions, please refer to https://github.com/MeetKai/functionary for setup details. | ||
class DeepSeekAPIHandler(OpenAIHandler): | ||
def __init__(self, model_name, temperature) -> None: | ||
super().__init__(model_name, temperature) | ||
self.model_style = ModelStyle.OpenAI | ||
self.is_fc_model = True | ||
self.client = OpenAI( | ||
base_url="https://api.deepseek.com", api_key=os.getenv("DEEPSEEK_API_KEY") | ||
) | ||
|
||
@retry_with_backoff(RateLimitError) | ||
def generate_with_backoff(self, **kwargs): | ||
""" | ||
Per the DeepSeek API documentation: | ||
https://api-docs.deepseek.com/quick_start/rate_limit | ||
DeepSeek API does NOT constrain user's rate limit. We will try out best to serve every request. | ||
But please note that when our servers are under high traffic pressure, you may receive 429 (Rate Limit Reached) or 503 (Server Overloaded). When this happens, please wait for a while and retry. | ||
Thus, backoff is still useful for handling 429 and 503 errors. | ||
""" | ||
start_time = time.time() | ||
api_response = self.client.chat.completions.create(**kwargs) | ||
end_time = time.time() | ||
|
||
return api_response, end_time - start_time | ||
|
||
@override | ||
def _query_FC(self, inference_data: dict): | ||
message: list[dict] = inference_data["message"] | ||
tools = inference_data["tools"] | ||
inference_data["inference_input_log"] = {"message": repr(message), "tools": tools} | ||
|
||
if len(tools) > 0: | ||
return self.generate_with_backoff( | ||
# The model name is always "deepseek-chat", as per https://api-docs.deepseek.com/quick_start/pricing | ||
# Note: Currently, it points to `DeepSeek-V3` | ||
model="deepseek-chat", | ||
messages=message, | ||
tools=tools, | ||
) | ||
else: | ||
return self.generate_with_backoff( | ||
model="deepseek-chat", | ||
messages=message, | ||
) |