Skip to content

Commit e7ca6ac

Browse files
added the methods for interacting with config to server
1 parent 5e6b355 commit e7ca6ac

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

mindsdb_sdk/config.py

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
from mindsdb_sdk.connectors.rest_api import RestAPI
2+
3+
4+
class Config():
5+
"""
6+
**Configuration for MindsDB**
7+
8+
This class provides methods to set and get the various configuration aspects of MindsDB.
9+
10+
Working with configuration:
11+
12+
Set default LLM configuration:
13+
14+
>>> server.config.set_default_llm(
15+
... provider='openai',
16+
... model_name='gpt-4',
17+
... api_key='sk-...'
18+
... )
19+
20+
Get default LLM configuration:
21+
22+
>>> llm_config = server.config.get_default_llm()
23+
>>> print(llm_config)
24+
25+
Set default embedding model:
26+
27+
>>> server.config.set_default_embedding_model(
28+
... provider='openai',
29+
... model_name='text-embedding-ada-002',
30+
... api_key='sk-...'
31+
... )
32+
33+
Get default embedding model:
34+
35+
>>> embedding_config = server.config.get_default_embedding_model()
36+
37+
Set default reranking model:
38+
39+
>>> server.config.set_default_reranking_model(
40+
... provider='openai',
41+
... model_name='gpt-4',
42+
... api_key='sk-...'
43+
... )
44+
45+
Get default reranking model:
46+
47+
>>> reranking_config = server.config.get_default_reranking_model()
48+
"""
49+
def __init__(self, api: RestAPI):
50+
self.api = api
51+
52+
def set_default_llm(
53+
self,
54+
provider: str,
55+
model_name: str,
56+
api_key: str = None,
57+
**kwargs
58+
):
59+
"""
60+
Set the default LLM configuration for MindsDB.
61+
62+
:param provider: The name of the LLM provider (e.g., 'openai', 'google').
63+
:param model_name: The name of the model to use.
64+
:param api_key: Optional API key for the provider.
65+
:param kwargs: Additional parameters for the LLM configuration.
66+
"""
67+
config = {
68+
"default_llm": {
69+
"provider": provider,
70+
"model_name": model_name,
71+
"api_key": api_key,
72+
**kwargs
73+
}
74+
}
75+
self.api.update_config(config)
76+
77+
def get_default_llm(self):
78+
"""
79+
Get the default LLM configuration for MindsDB.
80+
81+
:return: Dictionary containing the default LLM configuration.
82+
"""
83+
return self.api.get_config().get("default_llm", {})
84+
85+
def set_default_embedding_model(
86+
self,
87+
provider: str,
88+
model_name: str,
89+
api_key: str = None,
90+
**kwargs
91+
):
92+
"""
93+
Set the default embedding model configuration for MindsDB.
94+
95+
:param provider: The name of the embedding model provider (e.g., 'openai', 'google').
96+
:param model_name: The name of the embedding model to use.
97+
:param api_key: Optional API key for the provider.
98+
:param kwargs: Additional parameters for the embedding model configuration.
99+
"""
100+
config = {
101+
"default_embedding_model": {
102+
"provider": provider,
103+
"model_name": model_name,
104+
"api_key": api_key,
105+
**kwargs
106+
}
107+
}
108+
self.api.update_config(config)
109+
110+
def get_default_embedding_model(self):
111+
"""
112+
Get the default embedding model configuration for MindsDB.
113+
114+
:return: Dictionary containing the default embedding model configuration.
115+
"""
116+
return self.api.get_config().get("default_embedding_model", {})
117+
118+
def set_default_reranking_model(
119+
self,
120+
provider: str,
121+
model_name: str,
122+
api_key: str = None,
123+
**kwargs
124+
):
125+
"""
126+
Set the default reranking model configuration for MindsDB.
127+
128+
:param provider: The name of the reranking model provider (e.g., 'openai', 'google').
129+
:param model_name: The name of the reranking model to use.
130+
:param api_key: Optional API key for the provider.
131+
:param kwargs: Additional parameters for the reranking model configuration.
132+
"""
133+
config = {
134+
"default_reranking_model": {
135+
"provider": provider,
136+
"model_name": model_name,
137+
"api_key": api_key,
138+
**kwargs
139+
}
140+
}
141+
self.api.update_config(config)
142+
143+
def get_default_reranking_model(self):
144+
"""
145+
Get the default reranking model configuration for MindsDB.
146+
147+
:return: Dictionary containing the default reranking model configuration.
148+
"""
149+
return self.api.get_config().get("default_reranking_model", {})
150+

mindsdb_sdk/server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .ml_engines import MLEngines
55
from .handlers import Handlers
66
from .skills import Skills
7+
from .config import Config
78

89

910
class Server(Project):
@@ -48,6 +49,8 @@ def __init__(self, api, skills: Skills = None, agents: Agents = None):
4849
self.ml_handlers = Handlers(self.api, 'ml')
4950
self.data_handlers = Handlers(self.api, 'data')
5051

52+
self.config = Config(api)
53+
5154
def status(self) -> dict:
5255
"""
5356
Get server information. It could content version

0 commit comments

Comments
 (0)