Skip to content

Commit

Permalink
Merge pull request #141 from mindsdb/staging
Browse files Browse the repository at this point in the history
Release 3.0.2
  • Loading branch information
ea-rus authored Jul 30, 2024
2 parents d18ec43 + ea32d30 commit 31d1441
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
7 changes: 5 additions & 2 deletions examples/using_agents_with_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@

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

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


question = "what are the rules for the game takaido?"
answer = agent.completion([{'question': question, 'answer': None}])
print(answer.content)
print(answer.context)
print(answer)

2 changes: 1 addition & 1 deletion mindsdb_sdk/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'mindsdb_sdk'
__package_name__ = 'mindsdb_sdk'
__version__ = '3.0.1'
__version__ = '3.0.2'
__description__ = "MindsDB Python SDK, provides an SDK to use a remote mindsdb instance"
__email__ = "[email protected]"
__author__ = 'MindsDB Inc'
Expand Down
18 changes: 15 additions & 3 deletions mindsdb_sdk/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@
_DEFAULT_LLM_MODEL = 'gpt-4o'

class AgentCompletion:
"""Represents a full MindsDB agent completion"""
def __init__(self, content: str):
"""
Represents a full MindsDB agent completion response.
Attributes:
content: The completion content.
context: Only relevant for retrieval agents. Contains the context retrieved from the knowledge base.
"""
def __init__(self, content: str, context: List[dict] = None):
self.content = content
self.context = context

def __repr__(self):
return self.content
return f'{self.__class__.__name__}(content: {self.content}, context: {self.context})'


class Agent:
Expand Down Expand Up @@ -208,6 +217,9 @@ def completion(self, name: str, messages: List[dict]) -> AgentCompletion:
:return: completion from querying the agent
"""
data = self.api.agent_completion(self.project, name, messages)
if 'context' in data['message']:
return AgentCompletion(data['message']['content'], data['message'].get('context'))

return AgentCompletion(data['message']['content'])

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

0 comments on commit 31d1441

Please sign in to comment.