forked from langgenius/dify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add an enumeration type and use the factory pattern to obta…
…in the corresponding class (langgenius#9356)
- Loading branch information
Showing
8 changed files
with
43 additions
and
19 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,5 @@ | ||
from enum import Enum | ||
|
||
|
||
class KeyWordType(str, Enum): | ||
JIEBA = "jieba" |
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 |
---|---|---|
@@ -1,15 +1,25 @@ | ||
from services.auth.firecrawl import FirecrawlAuth | ||
from services.auth.jina import JinaAuth | ||
from services.auth.api_key_auth_base import ApiKeyAuthBase | ||
from services.auth.auth_type import AuthType | ||
|
||
|
||
class ApiKeyAuthFactory: | ||
def __init__(self, provider: str, credentials: dict): | ||
if provider == "firecrawl": | ||
self.auth = FirecrawlAuth(credentials) | ||
elif provider == "jinareader": | ||
self.auth = JinaAuth(credentials) | ||
else: | ||
raise ValueError("Invalid provider") | ||
auth_factory = self.get_apikey_auth_factory(provider) | ||
self.auth = auth_factory(credentials) | ||
|
||
def validate_credentials(self): | ||
return self.auth.validate_credentials() | ||
|
||
@staticmethod | ||
def get_apikey_auth_factory(provider: str) -> type[ApiKeyAuthBase]: | ||
match provider: | ||
case AuthType.FIRECRAWL: | ||
from services.auth.firecrawl.firecrawl import FirecrawlAuth | ||
|
||
return FirecrawlAuth | ||
case AuthType.JINA: | ||
from services.auth.jina.jina import JinaAuth | ||
|
||
return JinaAuth | ||
case _: | ||
raise ValueError("Invalid provider") |
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,6 @@ | ||
from enum import Enum | ||
|
||
|
||
class AuthType(str, Enum): | ||
FIRECRAWL = "firecrawl" | ||
JINA = "jinareader" |
Empty file.
File renamed without changes.
Empty file.
File renamed without changes.