-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(improve-api-endpoints): Added available model API
This API endpoint shares the same API token with Dataset API. It is essential for patching the knowledge base in terms of embedding model. Related to: #11727
- Loading branch information
1 parent
a47b514
commit d7854a5
Showing
2 changed files
with
23 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,22 @@ | ||
import logging | ||
|
||
from flask_login import current_user # type: ignore | ||
from flask_restful import Resource, reqparse # type: ignore | ||
from werkzeug.exceptions import Forbidden | ||
|
||
from controllers.service_api import api | ||
from controllers.service_api.wraps import validate_dataset_token | ||
from core.model_runtime.utils.encoders import jsonable_encoder | ||
from services.model_provider_service import ModelProviderService | ||
|
||
class ModelProviderAvailableModelApi(Resource): | ||
@validate_dataset_token | ||
def get(self, _, model_type): | ||
tenant_id = current_user.current_tenant_id | ||
|
||
model_provider_service = ModelProviderService() | ||
models = model_provider_service.get_models_by_model_type(tenant_id=tenant_id, model_type=model_type) | ||
|
||
return jsonable_encoder({"data": models}) | ||
|
||
api.add_resource(ModelProviderAvailableModelApi, "/workspaces/current/models/model-types/<string:model_type>") |