Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
41ab8713
Commit
41ab8713
authored
Aug 26, 2023
by
John Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: fulfill few comments
parent
1c114eae
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
14 deletions
+40
-14
base.py
api/core/model_providers/providers/base.py
+40
-14
No files found.
api/core/model_providers/providers/base.py
View file @
41ab8713
...
...
@@ -14,8 +14,15 @@ from models.provider import Provider, ProviderType, ProviderModel
class
BaseModelProvider
(
BaseModel
,
ABC
):
"""
This is the base class for all model providers.
"""
provider
:
Provider
"""
The corresponding Provider database table object, which exists in two types of providers: SYSTEM and CUSTOM.
System providers have three types of quota: TRAIL, FREE (third-party free trial), and PAID.
"""
class
Config
:
"""Configuration for this pydantic object."""
...
...
@@ -26,7 +33,7 @@ class BaseModelProvider(BaseModel, ABC):
@
abstractmethod
def
provider_name
(
self
):
"""
Returns the name of a provider.
Returns the
unique
name of a provider.
"""
raise
NotImplementedError
...
...
@@ -39,9 +46,14 @@ class BaseModelProvider(BaseModel, ABC):
def
get_supported_model_list
(
self
,
model_type
:
ModelType
)
->
list
[
dict
]:
"""
get supported model object list for use.
If the provider rule is for fixed models, return the fixed model list provided by `_get_fixed_model_list`,
otherwise get the list of user-configured models under the provider.
:param model_type:
:return:
:param model_type: The type of model to get the list for.
:type model_type: ModelType
:return: A list of dictionaries representing the supported models.
:rtype: list[dict]
"""
rules
=
self
.
get_rules
()
if
'custom'
not
in
rules
[
'support_provider_types'
]:
...
...
@@ -69,20 +81,26 @@ class BaseModelProvider(BaseModel, ABC):
@
abstractmethod
def
_get_fixed_model_list
(
self
,
model_type
:
ModelType
)
->
list
[
dict
]:
"""
get supported model object list
for use.
Get a list of supported fixed model objects
for use.
:param model_type:
:return:
:param model_type: The type of model to get the list for.
:type model_type: ModelType
:return: A list of dictionaries representing the supported models.
:rtype: list[dict]
"""
raise
NotImplementedError
@
abstractmethod
def
get_model_class
(
self
,
model_type
:
ModelType
)
->
Type
:
"""
get specific model class
.
Get the specific model class for the given model type
.
:param model_type:
:return:
:param model_type: The type of model to get the class for.
:type model_type: ModelType
:return: The class object for the specified model type.
:rtype: Type
"""
raise
NotImplementedError
...
...
@@ -90,9 +108,14 @@ class BaseModelProvider(BaseModel, ABC):
@
abstractmethod
def
is_provider_credentials_valid_or_raise
(
cls
,
credentials
:
dict
):
"""
check provider credentials valid
.
Check if the given credentials are valid for this provider
.
:param credentials:
:param credentials: A dictionary of credentials to check.
:type credentials: dict
:raises: CredentialsValidateFailedError if the credentials are invalid.
:return: None
"""
raise
NotImplementedError
...
...
@@ -111,10 +134,13 @@ class BaseModelProvider(BaseModel, ABC):
@
abstractmethod
def
get_provider_credentials
(
self
,
obfuscated
:
bool
=
False
)
->
dict
:
"""
get credentials for llm use
.
Get the credentials for this provider
.
:param obfuscated:
:return:
:param obfuscated: Whether to obfuscate the credentials or not.
:type obfuscated: bool
:return: A dictionary of credentials for this provider.
:rtype: dict
"""
raise
NotImplementedError
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment