Skip to content

Commit e5a1ac4

Browse files
authored
Merge pull request #132 from mindsdb/mind-data-source-config
Update create_mind to Use New DataSourceConfig
2 parents 611d9e6 + 91df71d commit e5a1ac4

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

examples/using_database_mind_text2sql.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from uuid import uuid4
22

33
from openai import OpenAI
4-
from mindsdb_sdk.utils.mind import create_mind
4+
from mindsdb_sdk.utils.mind import create_mind, DatabaseConfig
55
import os
66

77

@@ -21,22 +21,28 @@
2121
base_url=base_url
2222
)
2323

24-
# create a database mind
25-
mind = create_mind(
26-
name = f'my_house_data_mind_{uuid4().hex}',
27-
description= 'House Sales',
28-
base_url= base_url,
29-
api_key= MINDSDB_API_KEY,
30-
model= model_name,
31-
data_source_type='postgres',
32-
data_source_connection_args={
24+
# Create a Database Config.
25+
pg_config = DatabaseConfig(
26+
description='House Sales',
27+
type='postgres',
28+
connection_args={
3329
'user': 'demo_user',
3430
'password': 'demo_password',
3531
'host': 'samples.mindsdb.com',
3632
'port': '5432',
3733
'database': 'demo',
3834
'schema': 'demo_data'
39-
}
35+
},
36+
tables=['house_sales']
37+
)
38+
39+
# create a database mind
40+
mind = create_mind(
41+
base_url= base_url,
42+
api_key= MINDSDB_API_KEY,
43+
name = f'my_house_data_mind_{uuid4().hex}',
44+
data_source_configs=[pg_config],
45+
model= model_name
4046
)
4147

4248
# Actually pass in our tool to get a SQL completion.

mindsdb_sdk/utils/mind.py

+35-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Optional
1+
from pydantic import BaseModel, Field
2+
from typing import List, Optional
3+
from uuid import uuid4
24

35
import requests
46
from logging import getLogger
@@ -16,27 +18,48 @@ def __init__(self, name):
1618
self.name = name
1719

1820

21+
class DataSourceConfig(BaseModel):
22+
"""
23+
Represents a data source that can be made available to a Mind.
24+
"""
25+
id: str = Field(default_factory=lambda: uuid4().hex)
26+
27+
# Description for underlying agent to know, based on context, whether to access this data source.
28+
description: str
29+
30+
31+
class DatabaseConfig(DataSourceConfig):
32+
"""
33+
Represents a database that can be made available to a Mind.
34+
"""
35+
36+
# Integration name (e.g. postgres)
37+
type: str
38+
39+
# Args for connecting to database.
40+
connection_args: dict
41+
42+
# Tables to make available to the Mind (defaults to ALL).
43+
tables: List[str] = []
44+
45+
1946
# Create mind entity util function
2047
def create_mind(
2148
base_url: str,
2249
api_key: str,
2350
name: str,
24-
description: str,
25-
data_source_type: str,
26-
data_source_connection_args: dict,
51+
data_source_configs: List[DataSourceConfig] = None,
2752
model: Optional[str] = None,
2853
) -> Mind:
2954
"""
3055
Create a mind entity in LiteLLM proxy.
3156
3257
Args:
33-
base_url: MindsDB base URL
34-
api_key: MindsDB API key
35-
name: Mind name
36-
description: Mind description
58+
base_url (str): MindsDB base URL
59+
api_key (str): MindsDB API key
60+
name (str): Mind name
61+
data_source_configs (List[DataSourceConfig]): Data sources to make available to the mind
3762
model: Model orchestrating the AI reasoning loop
38-
data_source_type: Data source type
39-
data_source_connection_args: Data source connection arguments
4063
4164
Returns:
4265
Mind: Mind entity
@@ -46,10 +69,8 @@ def create_mind(
4669
headers = {"Authorization": f"Bearer {api_key}"}
4770
payload = {
4871
"name": name,
49-
"description": description,
50-
"model": model,
51-
"data_source_type": data_source_type,
52-
"data_source_connection_args": data_source_connection_args
72+
"data_source_configs": [d.model_dump() for d in data_source_configs],
73+
"model": model
5374
}
5475
try:
5576
response = requests.post(url, json=payload, headers=headers)

0 commit comments

Comments
 (0)