Skip to content

Commit 31d1441

Browse files
authored
Merge pull request #141 from mindsdb/staging
Release 3.0.2
2 parents d18ec43 + ea32d30 commit 31d1441

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

examples/using_agents_with_retrieval.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99

1010
# Now create an agent that will use the model we just created.
1111
agent = con.agents.create(name=f'mindsdb_retrieval_agent_{model_name}_{uuid4().hex}',
12-
model='gpt-4')
12+
model='gpt-4',
13+
params={'return_context': True})
1314

1415
agent.add_file('./data/tokaido-rulebook.pdf', 'rule book for the board game Tokaido')
1516

1617

1718
question = "what are the rules for the game takaido?"
1819
answer = agent.completion([{'question': question, 'answer': None}])
19-
print(answer.content)
20+
print(answer.context)
21+
print(answer)
22+

mindsdb_sdk/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = 'mindsdb_sdk'
22
__package_name__ = 'mindsdb_sdk'
3-
__version__ = '3.0.1'
3+
__version__ = '3.0.2'
44
__description__ = "MindsDB Python SDK, provides an SDK to use a remote mindsdb instance"
55
__email__ = "[email protected]"
66
__author__ = 'MindsDB Inc'

mindsdb_sdk/agents.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,21 @@
1616
_DEFAULT_LLM_MODEL = 'gpt-4o'
1717

1818
class AgentCompletion:
19-
"""Represents a full MindsDB agent completion"""
20-
def __init__(self, content: str):
19+
"""
20+
Represents a full MindsDB agent completion response.
21+
22+
Attributes:
23+
content: The completion content.
24+
context: Only relevant for retrieval agents. Contains the context retrieved from the knowledge base.
25+
26+
27+
"""
28+
def __init__(self, content: str, context: List[dict] = None):
2129
self.content = content
30+
self.context = context
2231

2332
def __repr__(self):
24-
return self.content
33+
return f'{self.__class__.__name__}(content: {self.content}, context: {self.context})'
2534

2635

2736
class Agent:
@@ -208,6 +217,9 @@ def completion(self, name: str, messages: List[dict]) -> AgentCompletion:
208217
:return: completion from querying the agent
209218
"""
210219
data = self.api.agent_completion(self.project, name, messages)
220+
if 'context' in data['message']:
221+
return AgentCompletion(data['message']['content'], data['message'].get('context'))
222+
211223
return AgentCompletion(data['message']['content'])
212224

213225
def completion_stream(self, name, messages: List[dict]) -> Iterable[object]:

0 commit comments

Comments
 (0)