-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from jin10086/deepseek
add llm_provider Deepseek
- Loading branch information
Showing
2 changed files
with
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
from functools import cached_property | ||
|
||
from .openai import OpenAI | ||
|
||
|
||
class Deepseek(OpenAI): | ||
NAME = "deepseek" | ||
DEFAULT_MODEL = "deepseek-chat" | ||
|
||
def __init__(self, api_key: str | None = None): | ||
api_key = api_key or os.getenv("DEEPSEEK_API_KEY") | ||
super().__init__(api_key=api_key) | ||
self.endpoint = "https://api.deepseek.com/v1" | ||
|
||
@cached_property | ||
def client(self): | ||
"""The raw OpenAI client.""" | ||
if not self.api_key: | ||
raise ValueError("DEEPSEEK API key is required") | ||
try: | ||
import openai as oa | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Please install the `openai` package: `pip install openai`" | ||
) from exc | ||
return oa.OpenAI(api_key=self.api_key, base_url=self.endpoint) |