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

Add Agents Support to SDK #96

Merged
merged 14 commits into from
Apr 16, 2024
Merged

Add Agents Support to SDK #96

merged 14 commits into from
Apr 16, 2024

Conversation

tmichaeldb
Copy link
Contributor

@tmichaeldb tmichaeldb commented Apr 12, 2024

Fixes RAG-26.

Depends on changes in #9067

This PR adds support for creating & using agents from underlying MindsDB Langchain models. Currently, only text-to-SQL is supported. A follow-up PR will add a retrieval skill for RAG functionality.

See /examples/using_agents.py for example usage:

import mindsdb_sdk

con = mindsdb_sdk.connect()

# We currently support Langchain as a backend.
print('Creating underlying langchain model for the agent to use...')
try:
    langchain_engine = con.ml_engines.get('langchain')
except Exception:
    # Create the engine if it doesn't exist.
    langchain_engine = con.ml_engines.create('langchain', handler='langchain')

# Actually create the underlying model the agent will use.
langchain_model = con.models.create(
    'agent_model',
    predict='answer',
    engine='langchain',
    prompt_template='You are a spicy, cheeky assistant. Add some personality and flare when responding to the user question: {{question}}',
    model_name='gpt-4-0125-preview' # This is the underlying LLM. Can use OpenAI, Claude, local Ollama, etc
    # Can optionally set LLM args here. For example:
    # temperature=0.0,
    # max_tokens=1000,
    # top_p=1.0,
    # top_k=0,
    # ...
)
print('Agent ready to use.')

# Now create an agent that will use the model we just created.
agent = con.agents.create('new_agent', langchain_model)
print('Ask a question: ')
question = input()
answer = agent.completion([{'question': question, 'answer': None}])
print(answer.content)

@tmichaeldb tmichaeldb self-assigned this Apr 12, 2024
@tmichaeldb tmichaeldb added the enhancement New feature or request label Apr 12, 2024
@tmichaeldb
Copy link
Contributor Author

Note streaming responses will be tracked by this issue. https://linear.app/mindsdb/issue/RAG-22/update-api-endpoints-to-fully-support-agents

We need to add streaming support to our underlying API

@ea-rus
Copy link
Contributor

ea-rus commented Apr 13, 2024

I've merged #97. Now if you update this branch from staging - CI should be fine

mindsdb_sdk/agents.py Show resolved Hide resolved
mindsdb_sdk/agents.py Show resolved Hide resolved
tests/test_sdk.py Outdated Show resolved Hide resolved
@tmichaeldb tmichaeldb requested a review from ea-rus April 16, 2024 00:29
@tmichaeldb
Copy link
Contributor Author

Ready for another round of reviews. Tests are passing locally for me (looks to be only failing on 3.7)

Copy link

github-actions bot commented Apr 16, 2024

Coverage

Coverage Report
FileStmtsMissCoverMissing
mindsdb_sdk
   agents.py871879%16, 75, 78, 82, 84, 86, 88, 90, 166–168, 189–191, 195–199
   databases.py42295%107, 134
   handlers.py39197%77
   jobs.py65395%96–99
   ml_engines.py42393%94, 126, 128
   models.py1811393%107, 195, 204, 206, 276, 308, 336, 457, 465, 484, 500, 527, 531
   projects.py59198%162
   query.py13192%14
   skills.py44491%43, 45, 49, 107
   tables.py108496%177, 189, 205, 297
   views.py37295%105, 138
mindsdb_sdk/connectors
   rest_api.py1611988%16–26, 32–33, 48, 69–71, 88, 91, 98–101
TOTAL9507193% 

Tests Skipped Failures Errors Time
14 0 💤 0 ❌ 0 🔥 8.417s ⏱️

@ea-rus
Copy link
Contributor

ea-rus commented Apr 16, 2024

I've added some fixes for tests and docs, CI works now

Copy link
Contributor

@dusvyat dusvyat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice looks good to me

mindsdb_sdk/agents.py Outdated Show resolved Hide resolved
mindsdb_sdk/server.py Outdated Show resolved Hide resolved
mindsdb_sdk/skills.py Outdated Show resolved Hide resolved
mindsdb_sdk/agents.py Outdated Show resolved Hide resolved
@tmichaeldb tmichaeldb requested a review from ea-rus April 16, 2024 16:11
@tmichaeldb tmichaeldb merged commit 9c535ce into staging Apr 16, 2024
4 checks passed
This was referenced Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: merged
Development

Successfully merging this pull request may close these issues.

None yet

3 participants