Skip to content

Commit 2b003f0

Browse files
committed
Made agents/skills part of a project
1 parent 37eea1e commit 2b003f0

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

mindsdb_sdk/agents.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Agents(CollectionBase):
102102
def __init__(self, api, project: str, skills: Skills = None):
103103
self.api = api
104104
self.project = project
105-
self.skills = skills or Skills(self.api)
105+
self.skills = skills or Skills(self.api, project)
106106

107107
def list(self) -> List[Agent]:
108108
"""
@@ -208,10 +208,10 @@ def update(self, name: str, updated_agent: Agent):
208208
)
209209
return Agent.from_json(data, self)
210210

211-
def delete(self, name: str):
211+
def drop(self, name: str):
212212
"""
213-
Delete an agent by name.
213+
Drop an agent by name.
214214
215-
:param name: Name of the agent to be deleted
215+
:param name: Name of the agent to be dropped
216216
"""
217217
_ = self.api.delete_agent(self.project, name)

mindsdb_sdk/projects.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from mindsdb_sdk.utils.sql import dict_to_binary_op
88

9+
from mindsdb_sdk.agents import Agents
10+
from mindsdb_sdk.skills import Skills
911
from mindsdb_sdk.utils.objects_collection import CollectionBase
1012

1113
from .models import Models
@@ -45,7 +47,7 @@ class Project:
4547
4648
"""
4749

48-
def __init__(self, api, name):
50+
def __init__(self, api, name, agents: Agents = None, skills: Skills = None):
4951
self.name = name
5052
self.api = api
5153

@@ -73,6 +75,9 @@ def __init__(self, api, name):
7375
self.create_job = self.jobs.create
7476
self.drop_job = self.jobs.drop
7577

78+
self.skills = skills or Skills(api, name)
79+
self.agents = agents or Agents(api, name, self.skills)
80+
7681
def __repr__(self):
7782
return f'{self.__class__.__name__}({self.name})'
7883

mindsdb_sdk/server.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Server(Project):
2828
def __init__(self, api, skills: Skills = None, agents: Agents = None):
2929
# server is also mindsdb project
3030
project_name = 'mindsdb'
31-
super().__init__(api, project_name)
31+
super().__init__(api, project_name, skills=skills, agents=agents)
3232

3333
self.projects = Projects(api)
3434

@@ -51,9 +51,6 @@ def __init__(self, api, skills: Skills = None, agents: Agents = None):
5151
self.ml_handlers = Handlers(self.api, 'ml')
5252
self.data_handlers = Handlers(self.api, 'data')
5353

54-
self.skills = skills or Skills(api, project_name)
55-
self.agents = agents or Agents(api, project_name, self.skills)
56-
5754
def status(self) -> dict:
5855
"""
5956
Get server information. It could content version

mindsdb_sdk/skills.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def __repr__(self):
4545

4646
@classmethod
4747
def from_json(cls, json: dict):
48-
return cls(json['name'], json['type'], json['params'])
48+
if json['type'] == 'sql':
49+
return SQLSkill.from_json(json)
50+
raise NotImplementedError(f'Unknown skill type: {json["type"]}')
4951

5052

5153
class SQLSkill(Skill):
@@ -111,10 +113,10 @@ def update(self, name: str, updated_skill: Skill) -> Skill:
111113
data = self.api.update_skill(self.project, name, updated_skill.name, updated_skill.type, updated_skill.params)
112114
return Skill.from_json(data)
113115

114-
def delete(self, name: str):
116+
def drop(self, name: str):
115117
"""
116-
Delete a skill by name.
118+
Drop a skill by name.
117119
118-
:param name: Name of the skill to be deleted
120+
:param name: Name of the skill to be dropped
119121
"""
120122
_ = self.api.delete_skill(self.project, name)

tests/test_sdk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ def test_completion(self, mock_post):
12891289
@patch('requests.Session.delete')
12901290
def test_delete(self, mock_delete):
12911291
server = mindsdb_sdk.connect()
1292-
server.agents.delete('test_agent')
1292+
server.agents.drop('test_agent')
12931293
# Check API call.
12941294
assert mock_delete.call_args.args[0] == f'{DEFAULT_LOCAL_API_URL}/api/projects/mindsdb/agents/test_agent'
12951295

@@ -1399,6 +1399,6 @@ def test_update(self, mock_put):
13991399
@patch('requests.Session.delete')
14001400
def test_delete(self, mock_delete):
14011401
server = mindsdb_sdk.connect()
1402-
server.skills.delete('test_skill')
1402+
server.skills.drop('test_skill')
14031403
# Check API call.
14041404
assert mock_delete.call_args.args[0] == f'{DEFAULT_LOCAL_API_URL}/api/projects/mindsdb/skills/test_skill'

0 commit comments

Comments
 (0)