Skip to content

Commit

Permalink
feat(Agent): change plugin path
Browse files Browse the repository at this point in the history
change plugin path
  • Loading branch information
yhjun1026 committed Dec 26, 2023
1 parent fa5378f commit 954834e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
6 changes: 3 additions & 3 deletions dbgpt/agent/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any, Dict, List, Optional, Union

from ..memory.gpts_memory import GptsMemory
from dbgpt.core import LLMClient
from dbgpt.core.interface.llm import ModelMetadata

class Agent:
"""
Expand Down Expand Up @@ -166,13 +166,13 @@ def to_dict(self) -> Dict[str, Any]:
@dataclass
class AgentContext:
conv_id: str
llm_provider: Optional[LLMClient]
llm_provider: Optional['LLMClient']

gpts_name: Optional[str] = None
resource_db: Optional[AgentResource] = None
resource_knowledge: Optional[AgentResource] = None
resource_internet: Optional[AgentResource] = None
llm_models: Optional[List[str]] = None
llm_models: Optional[List[ModelMetadata]] = None
model_priority: Optional[dict] = None
agents: Optional[List[str]] = None

Expand Down
28 changes: 16 additions & 12 deletions dbgpt/agent/agents/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,29 +637,33 @@ def _get_model_priority(self):
return None


def _filter_health_models(self, need_uses: Optional[list]):
all_modes = self.agent_context.llm_models
can_uses = []
for item in all_modes:
if item.model in need_uses:
can_uses.append(item)
return can_uses


def _select_llm_model(self, old_model: str = None):
"""
LLM model selector, currently only supports manual selection, more strategies will be opened in the future
Returns:
"""
all_modes = self.agent_context.llm_models
model_priority = self._get_model_priority()
if model_priority and len(model_priority) > 0:
for model in model_priority:
if old_model and model == old_model:
continue
if model in all_modes:
return model
can_uses = self._filter_health_models(model_priority)
if len(can_uses) > 0:
return can_uses[0].model

now_model = all_modes[0]
if old_model:
filtered_list = [item for item in all_modes if item != old_model]
filtered_list = [item for item in all_modes if item.model != old_model]
if filtered_list and len(filtered_list) >= 1:
return filtered_list[0]
else:
return all_modes[0]
else:
return all_modes[0]
now_model= filtered_list[0]
return now_model.model

async def a_reasoning_reply(
self, messages: Union[List[Dict]]
Expand Down
1 change: 0 additions & 1 deletion dbgpt/agent/agents/planner_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def __init__(
super().__init__(
name=self.NAME,
memory=memory,
llm_operator=llm_operator,
system_message=self.DEFAULT_SYSTEM_MESSAGE,
is_termination_msg=is_termination_msg,
max_consecutive_auto_reply=max_consecutive_auto_reply,
Expand Down
8 changes: 6 additions & 2 deletions dbgpt/serve/agent/agents/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from dbgpt._private.config import Config
from dbgpt.model.cluster.controller.controller import BaseModelController
from dbgpt.agent.memory.gpts_memory import GptsMessage
from dbgpt.model.cluster import WorkerManager, WorkerManagerFactory

from dbgpt.model.cluster.client import DefaultLLMClient

Expand Down Expand Up @@ -100,7 +101,10 @@ async def plan_chat(
)

### init chat param
llm_task = DefaultLLMClient()
worker_manager = CFG.SYSTEM_APP.get_component(
ComponentType.WORKER_MANAGER_FACTORY, WorkerManagerFactory
).create()
llm_task = DefaultLLMClient(worker_manager)
context: AgentContext = AgentContext(
conv_id=conv_id, llm_provider=llm_task
)
Expand All @@ -110,7 +114,7 @@ async def plan_chat(
context.resource_knowledge = resource_knowledge
context.agents = agents_names

context.llm_models = llm_task.models()
context.llm_models = await llm_task.models()
context.model_priority = llm_models_priority

agent_map = defaultdict()
Expand Down

0 comments on commit 954834e

Please sign in to comment.