Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Retrieval Skill for Adding Files to Agents #106

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mindsdb_sdk/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def add_file(self, name: str, file_path: str, description: str, knowledge_base:
'source': kb.name,
'description': description,
}
file_retrieval_skill = self.skills.create(skill_name, 'knowledge_base', retrieval_params)
file_retrieval_skill = self.skills.create(skill_name, 'retrieval', retrieval_params)
agent = self.get(name)
agent.skills.append(file_retrieval_skill)
self.update(agent.name, agent)
Expand Down
13 changes: 7 additions & 6 deletions mindsdb_sdk/skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,30 @@ def __repr__(self):
@classmethod
def from_json(cls, json: dict):
if json['type'] == 'sql':
return SQLSkill(json['name'], json['params']['tables'], json['params']['database'])
return SQLSkill(json['name'], json['params']['tables'], json['params']['database'], json['params']['description'])
if json['type'] == 'retrieval':
return RetrievalSkill(json['name'], json['params']['knowledge_base'], json['params']['description'])
return RetrievalSkill(json['name'], json['params']['source'], json['params']['description'])
return Skill(json['name'], json['type'], json['params'])


class SQLSkill(Skill):
"""Represents a MindsDB skill for agents to interact with MindsDB databases"""
def __init__(self, name: str, tables: List[str], database: str):
def __init__(self, name: str, tables: List[str], database: str, description: str):
params = {
'database': database,
'tables': tables,
'description': description
}
super().__init__(name, 'sql', params)

class RetrievalSkill(Skill):
"""Represents a MindsDB skill for agents to interact with MindsDB data sources"""
def __init__(self, name: str, knowledge_base: str, description: str):
params = {
'knowledge_base': knowledge_base,
'source': knowledge_base,
'description': description
}
super().__init__(name, 'knowledge_base', params)
super().__init__(name, 'retrieval', params)


class Skills(CollectionBase):
Expand Down Expand Up @@ -114,7 +115,7 @@ def create(self, name: str, type: str, params: dict = None) -> Skill:
"""
_ = self.api.create_skill(self.project, name, type, params)
if type == 'sql':
return SQLSkill(name, params['tables'], params['database'])
return SQLSkill(name, params['tables'], params['database'], params['description'])
return Skill(name, type, params)

def update(self, name: str, updated_skill: Skill) -> Skill:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ def test_create(self, mock_post):
new_agent = server.agents.create(
name='test_agent',
model=Model(None, {'name':'m1'}),
skills=[SQLSkill('test_skill', ['test_table'], 'test_database')],
skills=[SQLSkill('test_skill', ['test_table'], 'test_database'), 'test_description'],
params={'k1': 'v1'}
)
# Check API call.
Expand All @@ -1302,7 +1302,7 @@ def test_create(self, mock_post):
}
}

expected_skill = SQLSkill('test_skill', ['test_table'], 'test_database')
expected_skill = SQLSkill('test_skill', ['test_table'], 'test_database', 'test_descrition')
expected_agent = Agent(
'test_agent',
'test_model',
Expand Down Expand Up @@ -1354,7 +1354,7 @@ def test_update(self, mock_get, mock_put, _):
expected_agent = Agent(
'test_agent',
'updated_model',
[SQLSkill('updated_skill', ['updated_table'], 'updated_database')],
[SQLSkill('updated_skill', ['updated_table'], 'updated_database', 'test_description')],
{'k2': 'v2'},
created_at,
updated_at
Expand Down Expand Up @@ -1429,7 +1429,7 @@ def test_list(self, mock_get):
all_skills = server.skills.list()
assert len(all_skills) == 1

expected_skill = SQLSkill('test_skill', ['test_table'], 'test_database')
expected_skill = SQLSkill('test_skill', ['test_table'], 'test_database', 'test_description')
assert all_skills[0] == expected_skill

@patch('requests.Session.get')
Expand All @@ -1447,7 +1447,7 @@ def test_get(self, mock_get):
skill = server.skills.get('test_skill')
# Check API call.
assert mock_get.call_args[0][0] == f'{DEFAULT_LOCAL_API_URL}/api/projects/mindsdb/skills/test_skill'
expected_skill = SQLSkill('test_skill', ['test_table'], 'test_database')
expected_skill = SQLSkill('test_skill', ['test_table'], 'test_database', 'test_description')
assert skill == expected_skill

@patch('requests.Session.post')
Expand Down Expand Up @@ -1493,7 +1493,7 @@ def test_update(self, mock_put):
response_mock(mock_put, data)

server = mindsdb_sdk.connect()
expected_skill = SQLSkill('test_skill', ['updated_table'], 'updated_database')
expected_skill = SQLSkill('test_skill', ['updated_table'], 'updated_database', 'test_description')

updated_skill = server.skills.update('test_skill', expected_skill)
# Check API call.
Expand Down
Loading