From bdb869ad341989ef42368a1c689753854eb471b8 Mon Sep 17 00:00:00 2001 From: Better-Boy Date: Sun, 13 Oct 2024 12:44:52 +0530 Subject: [PATCH 1/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 55aefd8..3ea610a 100644 --- a/README.md +++ b/README.md @@ -149,3 +149,5 @@ client.datasources.drop('my_datasource') ``` >Note: The SDK currently does not support automatically removing a data source if it is no longer connected to any mind. +### Other SDKs +#### [Command-Line](https://github.com/Better-Boy/minds-cli-sdk) From 4dae76aa84e6cb4d7ae848839dc4e7942acde10a Mon Sep 17 00:00:00 2001 From: Abhilash Date: Wed, 16 Oct 2024 23:41:32 +0530 Subject: [PATCH 2/4] reuse openai client for chat completion --- minds/minds.py | 29 +++++++---------------------- minds/utils.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 minds/utils.py diff --git a/minds/minds.py b/minds/minds.py index 4aaf68e..46e14b2 100644 --- a/minds/minds.py +++ b/minds/minds.py @@ -1,7 +1,5 @@ from typing import List, Union, Iterable -from urllib.parse import urlparse, urlunparse -from datetime import datetime - +import utils from openai import OpenAI import minds.exceptions as exc @@ -10,7 +8,6 @@ DEFAULT_PROMPT_TEMPLATE = 'Use your database tools to answer the user\'s question: {{question}}' - class Mind: def __init__( self, client, name, @@ -35,7 +32,11 @@ def __init__( self.parameters = parameters self.created_at = created_at self.updated_at = updated_at - + base_url = utils.create_base_url_openai(self.api.base_url) + self.openai_client = OpenAI( + api_key=self.api.api_key, + base_url=base_url + ) self.datasources = datasources def __repr__(self): @@ -156,23 +157,7 @@ def completion(self, message: str, stream: bool = False) -> Union[str, Iterable[ :return: string if stream mode is off or iterator of ChoiceDelta objects (by openai) """ - parsed = urlparse(self.api.base_url) - - netloc = parsed.netloc - if netloc == 'mdb.ai': - llm_host = 'llm.mdb.ai' - else: - llm_host = 'ai.' + netloc - - parsed = parsed._replace(path='', netloc=llm_host) - - base_url = urlunparse(parsed) - openai_client = OpenAI( - api_key=self.api.api_key, - base_url=base_url - ) - - response = openai_client.chat.completions.create( + response = self.openai_client.chat.completions.create( model=self.name, messages=[ {'role': 'user', 'content': message} diff --git a/minds/utils.py b/minds/utils.py new file mode 100644 index 0000000..11248a1 --- /dev/null +++ b/minds/utils.py @@ -0,0 +1,15 @@ +from urllib.parse import urlparse, urlunparse + +def create_base_url_openai(base_url: str) -> str: + parsed = urlparse(base_url) + + netloc = parsed.netloc + if netloc == 'mdb.ai': + llm_host = 'llm.mdb.ai' + else: + llm_host = 'ai.' + netloc + + parsed = parsed._replace(path='', netloc=llm_host) + + return urlunparse(parsed) + \ No newline at end of file From 5ab710c7ad90f5fbda9d61abc8632b6bdd5cd61f Mon Sep 17 00:00:00 2001 From: Abhilash Date: Sat, 19 Oct 2024 00:27:37 +0530 Subject: [PATCH 3/4] change in method name --- minds/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minds/utils.py b/minds/utils.py index 11248a1..72e2147 100644 --- a/minds/utils.py +++ b/minds/utils.py @@ -1,6 +1,6 @@ from urllib.parse import urlparse, urlunparse -def create_base_url_openai(base_url: str) -> str: +def get_openai_base_url(base_url: str) -> str: parsed = urlparse(base_url) netloc = parsed.netloc From a19e2ad24423519ec6177feb57aebc18610e750a Mon Sep 17 00:00:00 2001 From: Better-Boy Date: Sat, 19 Oct 2024 09:31:51 +0530 Subject: [PATCH 4/4] Update minds.py --- minds/minds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minds/minds.py b/minds/minds.py index 46e14b2..a60bd4e 100644 --- a/minds/minds.py +++ b/minds/minds.py @@ -32,7 +32,7 @@ def __init__( self.parameters = parameters self.created_at = created_at self.updated_at = updated_at - base_url = utils.create_base_url_openai(self.api.base_url) + base_url = utils.get_openai_base_url(self.api.base_url) self.openai_client = OpenAI( api_key=self.api.api_key, base_url=base_url