mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-27 04:24:16 +00:00
feat(core): AWEL flow 2.0 backend code (#1879)
Co-authored-by: yhjun1026 <460342015@qq.com>
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
import io
|
||||
import json
|
||||
from functools import cache
|
||||
from typing import List, Optional, Union
|
||||
from typing import Dict, List, Literal, Optional, Union
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, Query, Request, UploadFile
|
||||
from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from starlette.responses import JSONResponse, StreamingResponse
|
||||
|
||||
from dbgpt.component import SystemApp
|
||||
from dbgpt.core.awel.flow import ResourceMetadata, ViewMetadata
|
||||
from dbgpt.core.awel.flow.flow_factory import FlowCategory
|
||||
from dbgpt.serve.core import Result
|
||||
from dbgpt.serve.core import Result, blocking_func_to_async
|
||||
from dbgpt.util import PaginationResult
|
||||
|
||||
from ..config import APP_NAME, SERVE_SERVICE_COMPONENT_NAME, ServeConfig
|
||||
from ..service.service import Service
|
||||
from .schemas import ServeRequest, ServerResponse
|
||||
from ..service.variables_service import VariablesService
|
||||
from .schemas import (
|
||||
FlowDebugRequest,
|
||||
RefreshNodeRequest,
|
||||
ServeRequest,
|
||||
ServerResponse,
|
||||
VariablesRequest,
|
||||
VariablesResponse,
|
||||
)
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -23,7 +34,12 @@ global_system_app: Optional[SystemApp] = None
|
||||
|
||||
def get_service() -> Service:
|
||||
"""Get the service instance"""
|
||||
return global_system_app.get_component(SERVE_SERVICE_COMPONENT_NAME, Service)
|
||||
return Service.get_instance(global_system_app)
|
||||
|
||||
|
||||
def get_variable_service() -> VariablesService:
|
||||
"""Get the service instance"""
|
||||
return VariablesService.get_instance(global_system_app)
|
||||
|
||||
|
||||
get_bearer_token = HTTPBearer(auto_error=False)
|
||||
@@ -102,7 +118,9 @@ async def test_auth():
|
||||
|
||||
|
||||
@router.post(
|
||||
"/flows", response_model=Result[None], dependencies=[Depends(check_api_key)]
|
||||
"/flows",
|
||||
response_model=Result[ServerResponse],
|
||||
dependencies=[Depends(check_api_key)],
|
||||
)
|
||||
async def create(
|
||||
request: ServeRequest, service: Service = Depends(get_service)
|
||||
@@ -239,20 +257,236 @@ async def query_page(
|
||||
|
||||
|
||||
@router.get("/nodes", dependencies=[Depends(check_api_key)])
|
||||
async def get_nodes() -> Result[List[Union[ViewMetadata, ResourceMetadata]]]:
|
||||
async def get_nodes(
|
||||
user_name: Optional[str] = Query(default=None, description="user name"),
|
||||
sys_code: Optional[str] = Query(default=None, description="system code"),
|
||||
tags: Optional[str] = Query(default=None, description="tags"),
|
||||
):
|
||||
"""Get the operator or resource nodes
|
||||
|
||||
Args:
|
||||
user_name (Optional[str]): The username
|
||||
sys_code (Optional[str]): The system code
|
||||
tags (Optional[str]): The tags encoded in JSON format
|
||||
|
||||
Returns:
|
||||
Result[List[Union[ViewMetadata, ResourceMetadata]]]:
|
||||
The operator or resource nodes
|
||||
"""
|
||||
from dbgpt.core.awel.flow.base import _OPERATOR_REGISTRY
|
||||
|
||||
return Result.succ(_OPERATOR_REGISTRY.metadata_list())
|
||||
tags_dict: Optional[Dict[str, str]] = None
|
||||
if tags:
|
||||
try:
|
||||
tags_dict = json.loads(tags)
|
||||
except json.JSONDecodeError:
|
||||
return Result.fail("Invalid JSON format for tags")
|
||||
|
||||
metadata_list = await blocking_func_to_async(
|
||||
global_system_app,
|
||||
_OPERATOR_REGISTRY.metadata_list,
|
||||
tags_dict,
|
||||
user_name,
|
||||
sys_code,
|
||||
)
|
||||
return Result.succ(metadata_list)
|
||||
|
||||
|
||||
@router.post("/nodes/refresh", dependencies=[Depends(check_api_key)])
|
||||
async def refresh_nodes(refresh_request: RefreshNodeRequest):
|
||||
"""Refresh the operator or resource nodes
|
||||
|
||||
Returns:
|
||||
Result[None]: The response
|
||||
"""
|
||||
from dbgpt.core.awel.flow.base import _OPERATOR_REGISTRY
|
||||
|
||||
# Make sure the variables provider is initialized
|
||||
_ = get_variable_service().variables_provider
|
||||
|
||||
new_metadata = await _OPERATOR_REGISTRY.refresh(
|
||||
refresh_request.id,
|
||||
refresh_request.flow_type == "operator",
|
||||
refresh_request.refresh,
|
||||
"http",
|
||||
global_system_app,
|
||||
)
|
||||
return Result.succ(new_metadata)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/variables",
|
||||
response_model=Result[VariablesResponse],
|
||||
dependencies=[Depends(check_api_key)],
|
||||
)
|
||||
async def create_variables(
|
||||
variables_request: VariablesRequest,
|
||||
) -> Result[VariablesResponse]:
|
||||
"""Create a new Variables entity
|
||||
|
||||
Args:
|
||||
variables_request (VariablesRequest): The request
|
||||
Returns:
|
||||
VariablesResponse: The response
|
||||
"""
|
||||
res = await blocking_func_to_async(
|
||||
global_system_app, get_variable_service().create, variables_request
|
||||
)
|
||||
return Result.succ(res)
|
||||
|
||||
|
||||
@router.put(
|
||||
"/variables/{v_id}",
|
||||
response_model=Result[VariablesResponse],
|
||||
dependencies=[Depends(check_api_key)],
|
||||
)
|
||||
async def update_variables(
|
||||
v_id: int, variables_request: VariablesRequest
|
||||
) -> Result[VariablesResponse]:
|
||||
"""Update a Variables entity
|
||||
|
||||
Args:
|
||||
v_id (int): The variable id
|
||||
variables_request (VariablesRequest): The request
|
||||
Returns:
|
||||
VariablesResponse: The response
|
||||
"""
|
||||
res = await blocking_func_to_async(
|
||||
global_system_app, get_variable_service().update, v_id, variables_request
|
||||
)
|
||||
return Result.succ(res)
|
||||
|
||||
|
||||
@router.post("/flow/debug", dependencies=[Depends(check_api_key)])
|
||||
async def debug_flow(
|
||||
flow_debug_request: FlowDebugRequest, service: Service = Depends(get_service)
|
||||
):
|
||||
"""Run the flow in debug mode."""
|
||||
# Return the no-incremental stream by default
|
||||
stream_iter = service.debug_flow(flow_debug_request, default_incremental=False)
|
||||
|
||||
headers = {
|
||||
"Content-Type": "text/event-stream",
|
||||
"Cache-Control": "no-cache",
|
||||
"Connection": "keep-alive",
|
||||
"Transfer-Encoding": "chunked",
|
||||
}
|
||||
return StreamingResponse(
|
||||
service._wrapper_chat_stream_flow_str(stream_iter),
|
||||
headers=headers,
|
||||
media_type="text/event-stream",
|
||||
)
|
||||
|
||||
|
||||
@router.get("/flow/export/{uid}", dependencies=[Depends(check_api_key)])
|
||||
async def export_flow(
|
||||
uid: str,
|
||||
export_type: Literal["json", "dbgpts"] = Query(
|
||||
"json", description="export type(json or dbgpts)"
|
||||
),
|
||||
format: Literal["file", "json"] = Query(
|
||||
"file", description="response format(file or json)"
|
||||
),
|
||||
file_name: Optional[str] = Query(default=None, description="file name to export"),
|
||||
user_name: Optional[str] = Query(default=None, description="user name"),
|
||||
sys_code: Optional[str] = Query(default=None, description="system code"),
|
||||
service: Service = Depends(get_service),
|
||||
):
|
||||
"""Export the flow to a file."""
|
||||
flow = service.get({"uid": uid, "user_name": user_name, "sys_code": sys_code})
|
||||
if not flow:
|
||||
raise HTTPException(status_code=404, detail=f"Flow {uid} not found")
|
||||
package_name = flow.name.replace("_", "-")
|
||||
file_name = file_name or package_name
|
||||
if export_type == "json":
|
||||
flow_dict = {"flow": flow.to_dict()}
|
||||
if format == "json":
|
||||
return JSONResponse(content=flow_dict)
|
||||
else:
|
||||
# Return the json file
|
||||
return StreamingResponse(
|
||||
io.BytesIO(json.dumps(flow_dict, ensure_ascii=False).encode("utf-8")),
|
||||
media_type="application/file",
|
||||
headers={
|
||||
"Content-Disposition": f"attachment;filename={file_name}.json"
|
||||
},
|
||||
)
|
||||
|
||||
elif export_type == "dbgpts":
|
||||
from ..service.share_utils import _generate_dbgpts_zip
|
||||
|
||||
if format == "json":
|
||||
raise HTTPException(
|
||||
status_code=400, detail="json response is not supported for dbgpts"
|
||||
)
|
||||
|
||||
zip_buffer = await blocking_func_to_async(
|
||||
global_system_app, _generate_dbgpts_zip, package_name, flow
|
||||
)
|
||||
return StreamingResponse(
|
||||
zip_buffer,
|
||||
media_type="application/x-zip-compressed",
|
||||
headers={"Content-Disposition": f"attachment;filename={file_name}.zip"},
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/flow/import",
|
||||
response_model=Result[ServerResponse],
|
||||
dependencies=[Depends(check_api_key)],
|
||||
)
|
||||
async def import_flow(
|
||||
file: UploadFile = File(...),
|
||||
save_flow: bool = Query(
|
||||
False, description="Whether to save the flow after importing"
|
||||
),
|
||||
service: Service = Depends(get_service),
|
||||
):
|
||||
"""Import the flow from a file."""
|
||||
filename = file.filename
|
||||
file_extension = filename.split(".")[-1].lower()
|
||||
if file_extension == "json":
|
||||
# Handle json file
|
||||
json_content = await file.read()
|
||||
json_dict = json.loads(json_content)
|
||||
if "flow" not in json_dict:
|
||||
raise HTTPException(
|
||||
status_code=400, detail="invalid json file, missing 'flow' key"
|
||||
)
|
||||
flow = ServeRequest.parse_obj(json_dict["flow"])
|
||||
elif file_extension == "zip":
|
||||
from ..service.share_utils import _parse_flow_from_zip_file
|
||||
|
||||
# Handle zip file
|
||||
flow = await _parse_flow_from_zip_file(file, global_system_app)
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=400, detail=f"invalid file extension {file_extension}"
|
||||
)
|
||||
if save_flow:
|
||||
return Result.succ(service.create_and_save_dag(flow))
|
||||
else:
|
||||
return Result.succ(flow)
|
||||
|
||||
|
||||
def init_endpoints(system_app: SystemApp) -> None:
|
||||
"""Initialize the endpoints"""
|
||||
from .variables_provider import (
|
||||
BuiltinAllSecretVariablesProvider,
|
||||
BuiltinAllVariablesProvider,
|
||||
BuiltinEmbeddingsVariablesProvider,
|
||||
BuiltinFlowVariablesProvider,
|
||||
BuiltinLLMVariablesProvider,
|
||||
BuiltinNodeVariablesProvider,
|
||||
)
|
||||
|
||||
global global_system_app
|
||||
system_app.register(Service)
|
||||
system_app.register(VariablesService)
|
||||
system_app.register(BuiltinFlowVariablesProvider)
|
||||
system_app.register(BuiltinNodeVariablesProvider)
|
||||
system_app.register(BuiltinAllVariablesProvider)
|
||||
system_app.register(BuiltinAllSecretVariablesProvider)
|
||||
system_app.register(BuiltinLLMVariablesProvider)
|
||||
system_app.register(BuiltinEmbeddingsVariablesProvider)
|
||||
global_system_app = system_app
|
||||
|
@@ -1,7 +1,9 @@
|
||||
from dbgpt._private.pydantic import ConfigDict
|
||||
from typing import Any, Dict, List, Literal, Optional, Union
|
||||
|
||||
# Define your Pydantic schemas here
|
||||
from dbgpt.core.awel.flow.flow_factory import FlowPanel
|
||||
from dbgpt._private.pydantic import BaseModel, ConfigDict, Field
|
||||
from dbgpt.core.awel import CommonLLMHttpRequestBody
|
||||
from dbgpt.core.awel.flow.flow_factory import FlowPanel, VariablesRequest
|
||||
from dbgpt.core.awel.util.parameter_util import RefreshOptionRequest
|
||||
|
||||
from ..config import SERVE_APP_NAME_HUMP
|
||||
|
||||
@@ -14,3 +16,71 @@ class ServerResponse(FlowPanel):
|
||||
# TODO define your own fields here
|
||||
|
||||
model_config = ConfigDict(title=f"ServerResponse for {SERVE_APP_NAME_HUMP}")
|
||||
|
||||
|
||||
class VariablesResponse(VariablesRequest):
|
||||
"""Variable response model."""
|
||||
|
||||
id: int = Field(
|
||||
...,
|
||||
description="The id of the variable",
|
||||
examples=[1],
|
||||
)
|
||||
|
||||
|
||||
class RefreshNodeRequest(BaseModel):
|
||||
"""Flow response model"""
|
||||
|
||||
model_config = ConfigDict(title=f"RefreshNodeRequest")
|
||||
id: str = Field(
|
||||
...,
|
||||
title="The id of the node",
|
||||
description="The id of the node to refresh",
|
||||
examples=["operator_llm_operator___$$___llm___$$___v1"],
|
||||
)
|
||||
flow_type: Literal["operator", "resource"] = Field(
|
||||
"operator",
|
||||
title="The type of the node",
|
||||
description="The type of the node to refresh",
|
||||
examples=["operator", "resource"],
|
||||
)
|
||||
type_name: str = Field(
|
||||
...,
|
||||
title="The type of the node",
|
||||
description="The type of the node to refresh",
|
||||
examples=["LLMOperator"],
|
||||
)
|
||||
type_cls: str = Field(
|
||||
...,
|
||||
title="The class of the node",
|
||||
description="The class of the node to refresh",
|
||||
examples=["dbgpt.core.operator.llm.LLMOperator"],
|
||||
)
|
||||
refresh: List[RefreshOptionRequest] = Field(
|
||||
...,
|
||||
title="The refresh options",
|
||||
description="The refresh options",
|
||||
)
|
||||
|
||||
|
||||
class FlowDebugRequest(BaseModel):
|
||||
"""Flow response model"""
|
||||
|
||||
model_config = ConfigDict(title=f"FlowDebugRequest")
|
||||
flow: ServeRequest = Field(
|
||||
...,
|
||||
title="The flow to debug",
|
||||
description="The flow to debug",
|
||||
)
|
||||
request: Union[CommonLLMHttpRequestBody, Dict[str, Any]] = Field(
|
||||
...,
|
||||
title="The request to debug",
|
||||
description="The request to debug",
|
||||
)
|
||||
variables: Optional[Dict[str, Any]] = Field(
|
||||
None,
|
||||
title="The variables to debug",
|
||||
description="The variables to debug",
|
||||
)
|
||||
user_name: Optional[str] = Field(None, description="User name")
|
||||
sys_code: Optional[str] = Field(None, description="System code")
|
||||
|
260
dbgpt/serve/flow/api/variables_provider.py
Normal file
260
dbgpt/serve/flow/api/variables_provider.py
Normal file
@@ -0,0 +1,260 @@
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
from dbgpt.core.interface.variables import (
|
||||
BUILTIN_VARIABLES_CORE_EMBEDDINGS,
|
||||
BUILTIN_VARIABLES_CORE_FLOW_NODES,
|
||||
BUILTIN_VARIABLES_CORE_FLOWS,
|
||||
BUILTIN_VARIABLES_CORE_LLMS,
|
||||
BUILTIN_VARIABLES_CORE_SECRETS,
|
||||
BUILTIN_VARIABLES_CORE_VARIABLES,
|
||||
BuiltinVariablesProvider,
|
||||
StorageVariables,
|
||||
)
|
||||
|
||||
from ..service.service import Service
|
||||
from .endpoints import get_service, get_variable_service
|
||||
from .schemas import ServerResponse
|
||||
|
||||
|
||||
class BuiltinFlowVariablesProvider(BuiltinVariablesProvider):
|
||||
"""Builtin flow variables provider.
|
||||
|
||||
Provide all flows by variables "${dbgpt.core.flow.flows}"
|
||||
"""
|
||||
|
||||
name = BUILTIN_VARIABLES_CORE_FLOWS
|
||||
|
||||
def get_variables(
|
||||
self,
|
||||
key: str,
|
||||
scope: str = "global",
|
||||
scope_key: Optional[str] = None,
|
||||
sys_code: Optional[str] = None,
|
||||
user_name: Optional[str] = None,
|
||||
) -> List[StorageVariables]:
|
||||
service: Service = get_service()
|
||||
page_result = service.get_list_by_page(
|
||||
{
|
||||
"user_name": user_name,
|
||||
"sys_code": sys_code,
|
||||
},
|
||||
1,
|
||||
1000,
|
||||
)
|
||||
flows: List[ServerResponse] = page_result.items
|
||||
variables = []
|
||||
for flow in flows:
|
||||
variables.append(
|
||||
StorageVariables(
|
||||
key=key,
|
||||
name=flow.name,
|
||||
label=flow.label,
|
||||
value=flow.uid,
|
||||
scope=scope,
|
||||
scope_key=scope_key,
|
||||
sys_code=sys_code,
|
||||
user_name=user_name,
|
||||
)
|
||||
)
|
||||
return variables
|
||||
|
||||
|
||||
class BuiltinNodeVariablesProvider(BuiltinVariablesProvider):
|
||||
"""Builtin node variables provider.
|
||||
|
||||
Provide all nodes by variables "${dbgpt.core.flow.nodes}"
|
||||
"""
|
||||
|
||||
name = BUILTIN_VARIABLES_CORE_FLOW_NODES
|
||||
|
||||
def get_variables(
|
||||
self,
|
||||
key: str,
|
||||
scope: str = "global",
|
||||
scope_key: Optional[str] = None,
|
||||
sys_code: Optional[str] = None,
|
||||
user_name: Optional[str] = None,
|
||||
) -> List[StorageVariables]:
|
||||
"""Get the builtin variables."""
|
||||
from dbgpt.core.awel.flow.base import _OPERATOR_REGISTRY
|
||||
|
||||
metadata_list = _OPERATOR_REGISTRY.metadata_list()
|
||||
variables = []
|
||||
for metadata in metadata_list:
|
||||
variables.append(
|
||||
StorageVariables(
|
||||
key=key,
|
||||
name=metadata["name"],
|
||||
label=metadata["label"],
|
||||
value=metadata["id"],
|
||||
scope=scope,
|
||||
scope_key=scope_key,
|
||||
sys_code=sys_code,
|
||||
user_name=user_name,
|
||||
)
|
||||
)
|
||||
return variables
|
||||
|
||||
|
||||
class BuiltinAllVariablesProvider(BuiltinVariablesProvider):
|
||||
"""Builtin all variables provider.
|
||||
|
||||
Provide all variables by variables "${dbgpt.core.variables}"
|
||||
"""
|
||||
|
||||
name = BUILTIN_VARIABLES_CORE_VARIABLES
|
||||
|
||||
def _get_variables_from_db(
|
||||
self,
|
||||
key: str,
|
||||
scope: str,
|
||||
scope_key: Optional[str],
|
||||
sys_code: Optional[str],
|
||||
user_name: Optional[str],
|
||||
category: Literal["common", "secret"] = "common",
|
||||
) -> List[StorageVariables]:
|
||||
storage_variables = get_variable_service().list_all_variables(category)
|
||||
variables = []
|
||||
for var in storage_variables:
|
||||
variables.append(
|
||||
StorageVariables(
|
||||
key=key,
|
||||
name=var.name,
|
||||
label=var.label,
|
||||
value=var.value,
|
||||
scope=scope,
|
||||
scope_key=scope_key,
|
||||
sys_code=sys_code,
|
||||
user_name=user_name,
|
||||
)
|
||||
)
|
||||
return variables
|
||||
|
||||
def get_variables(
|
||||
self,
|
||||
key: str,
|
||||
scope: str = "global",
|
||||
scope_key: Optional[str] = None,
|
||||
sys_code: Optional[str] = None,
|
||||
user_name: Optional[str] = None,
|
||||
) -> List[StorageVariables]:
|
||||
"""Get the builtin variables.
|
||||
|
||||
TODO: Return all builtin variables
|
||||
"""
|
||||
return self._get_variables_from_db(key, scope, scope_key, sys_code, user_name)
|
||||
|
||||
|
||||
class BuiltinAllSecretVariablesProvider(BuiltinAllVariablesProvider):
|
||||
"""Builtin all secret variables provider.
|
||||
|
||||
Provide all secret variables by variables "${dbgpt.core.secrets}"
|
||||
"""
|
||||
|
||||
name = BUILTIN_VARIABLES_CORE_SECRETS
|
||||
|
||||
def get_variables(
|
||||
self,
|
||||
key: str,
|
||||
scope: str = "global",
|
||||
scope_key: Optional[str] = None,
|
||||
sys_code: Optional[str] = None,
|
||||
user_name: Optional[str] = None,
|
||||
) -> List[StorageVariables]:
|
||||
"""Get the builtin variables."""
|
||||
return self._get_variables_from_db(
|
||||
key, scope, scope_key, sys_code, user_name, "secret"
|
||||
)
|
||||
|
||||
|
||||
class BuiltinLLMVariablesProvider(BuiltinVariablesProvider):
|
||||
"""Builtin LLM variables provider.
|
||||
|
||||
Provide all LLM variables by variables "${dbgpt.core.llmv}"
|
||||
"""
|
||||
|
||||
name = BUILTIN_VARIABLES_CORE_LLMS
|
||||
|
||||
def support_async(self) -> bool:
|
||||
"""Whether the dynamic options support async."""
|
||||
return True
|
||||
|
||||
async def _get_models(
|
||||
self,
|
||||
key: str,
|
||||
scope: str,
|
||||
scope_key: Optional[str],
|
||||
sys_code: Optional[str],
|
||||
user_name: Optional[str],
|
||||
expect_worker_type: str = "llm",
|
||||
) -> List[StorageVariables]:
|
||||
from dbgpt.model.cluster.controller.controller import BaseModelController
|
||||
|
||||
controller = BaseModelController.get_instance(self.system_app)
|
||||
models = await controller.get_all_instances(healthy_only=True)
|
||||
model_dict = {}
|
||||
for model in models:
|
||||
worker_name, worker_type = model.model_name.split("@")
|
||||
if expect_worker_type == worker_type:
|
||||
model_dict[worker_name] = model
|
||||
variables = []
|
||||
for worker_name, model in model_dict.items():
|
||||
variables.append(
|
||||
StorageVariables(
|
||||
key=key,
|
||||
name=worker_name,
|
||||
label=worker_name,
|
||||
value=worker_name,
|
||||
scope=scope,
|
||||
scope_key=scope_key,
|
||||
sys_code=sys_code,
|
||||
user_name=user_name,
|
||||
)
|
||||
)
|
||||
return variables
|
||||
|
||||
async def async_get_variables(
|
||||
self,
|
||||
key: str,
|
||||
scope: str = "global",
|
||||
scope_key: Optional[str] = None,
|
||||
sys_code: Optional[str] = None,
|
||||
user_name: Optional[str] = None,
|
||||
) -> List[StorageVariables]:
|
||||
"""Get the builtin variables."""
|
||||
return await self._get_models(key, scope, scope_key, sys_code, user_name)
|
||||
|
||||
def get_variables(
|
||||
self,
|
||||
key: str,
|
||||
scope: str = "global",
|
||||
scope_key: Optional[str] = None,
|
||||
sys_code: Optional[str] = None,
|
||||
user_name: Optional[str] = None,
|
||||
) -> List[StorageVariables]:
|
||||
"""Get the builtin variables."""
|
||||
raise NotImplementedError(
|
||||
"Not implemented get variables sync, please use async_get_variables"
|
||||
)
|
||||
|
||||
|
||||
class BuiltinEmbeddingsVariablesProvider(BuiltinLLMVariablesProvider):
|
||||
"""Builtin embeddings variables provider.
|
||||
|
||||
Provide all embeddings variables by variables "${dbgpt.core.embeddings}"
|
||||
"""
|
||||
|
||||
name = BUILTIN_VARIABLES_CORE_EMBEDDINGS
|
||||
|
||||
async def async_get_variables(
|
||||
self,
|
||||
key: str,
|
||||
scope: str = "global",
|
||||
scope_key: Optional[str] = None,
|
||||
sys_code: Optional[str] = None,
|
||||
user_name: Optional[str] = None,
|
||||
) -> List[StorageVariables]:
|
||||
"""Get the builtin variables."""
|
||||
return await self._get_models(
|
||||
key, scope, scope_key, sys_code, user_name, "text2vec"
|
||||
)
|
Reference in New Issue
Block a user