mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-24 19:08:15 +00:00
docs(agent): Add agents development guide (#1673)
This commit is contained in:
@@ -3,16 +3,18 @@
|
||||
import dataclasses
|
||||
import logging
|
||||
from concurrent.futures import Executor, ThreadPoolExecutor
|
||||
from typing import Any, Generic, List, Optional, Tuple, Union
|
||||
from typing import TYPE_CHECKING, Any, Generic, List, Optional, Tuple, Union
|
||||
|
||||
import cachetools
|
||||
|
||||
from dbgpt.datasource.rdbms.base import RDBMSConnector
|
||||
from dbgpt.util.cache_utils import cached
|
||||
from dbgpt.util.executor_utils import blocking_func_to_async
|
||||
|
||||
from .base import P, Resource, ResourceParameters, ResourceType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from dbgpt.datasource.rdbms.base import RDBMSConnector
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_DEFAULT_PROMPT_TEMPLATE = (
|
||||
@@ -143,7 +145,7 @@ class RDBMSConnectorResource(DBResource[DBParameters]):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
connector: Optional[RDBMSConnector] = None,
|
||||
connector: Optional["RDBMSConnector"] = None,
|
||||
db_name: Optional[str] = None,
|
||||
db_type: Optional[str] = None,
|
||||
dialect: Optional[str] = None,
|
||||
@@ -168,7 +170,7 @@ class RDBMSConnectorResource(DBResource[DBParameters]):
|
||||
)
|
||||
|
||||
@property
|
||||
def connector(self) -> RDBMSConnector:
|
||||
def connector(self) -> "RDBMSConnector":
|
||||
"""Return the connector."""
|
||||
if not self._connector:
|
||||
raise ValueError("Connector is not set.")
|
||||
|
@@ -127,6 +127,10 @@ class BaseTool(Resource[ToolResourceParameters], ABC):
|
||||
parameters=parameters_string,
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return the string representation of the tool."""
|
||||
return f"Tool: {self.name} ({self.description})"
|
||||
|
||||
|
||||
class FunctionTool(BaseTool):
|
||||
"""Function tool.
|
||||
|
@@ -63,6 +63,31 @@ class ToolPack(ResourcePack):
|
||||
typed_tools = [cast(BaseTool, t) for t in tools]
|
||||
return [ToolPack(typed_tools)] # type: ignore
|
||||
|
||||
async def get_prompt(
|
||||
self,
|
||||
*,
|
||||
lang: str = "en",
|
||||
prompt_type: str = "default",
|
||||
question: Optional[str] = None,
|
||||
resource_name: Optional[str] = None,
|
||||
**kwargs,
|
||||
) -> str:
|
||||
"""Get the prompt for the resources."""
|
||||
prompt_list = []
|
||||
for name, resource in self._resources.items():
|
||||
prompt = await resource.get_prompt(
|
||||
lang=lang,
|
||||
prompt_type=prompt_type,
|
||||
question=question,
|
||||
resource_name=resource_name,
|
||||
**kwargs,
|
||||
)
|
||||
prompt_list.append(prompt)
|
||||
head_prompt = (
|
||||
"You have access to the following APIs:" if lang == "en" else "您可以使用以下API:"
|
||||
)
|
||||
return head_prompt + "\n" + self._prompt_separator.join(prompt_list)
|
||||
|
||||
def add_command(
|
||||
self,
|
||||
command_label: str,
|
||||
|
Reference in New Issue
Block a user