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

[WIP] Fix langchain handler install #9115

Merged
merged 6 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Expand Up @@ -13,6 +13,10 @@ docker/docker-compose.yml
docker/*.Dockerfile
docker/docker-compose*
docker/README.md

build
docs
helm
var

**/__pycache__
1 change: 1 addition & 0 deletions .github/workflows/test_on_deploy.yml
Expand Up @@ -75,6 +75,7 @@ jobs:
fi
env:
PROMETHEUS_MULTIPROC_DIR: ./prometheus_metrics
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
CHECK_FOR_UPDATES: False

- name: Run Learning Hub Tests
Expand Down
2 changes: 1 addition & 1 deletion default_handlers.txt
Expand Up @@ -16,4 +16,4 @@ timegpt
binance
twitter
mindsdb_inference
web
web
2 changes: 1 addition & 1 deletion docs/integrations/ai-engines/anomaly.mdx
Expand Up @@ -60,7 +60,7 @@ Before proceeding, ensure the following prerequisites are met:

## Setup

Create an AI engine from the [Anomaly Detection handler](https://github.com/mindsdb/mindsdb/tree/staging/mindsdb/integrations/handlers/anomaly_detection_handler).
Create an AI engine from the [Anomaly Detection handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/anomaly_detection_handler).

```sql
CREATE ML_ENGINE anomaly_detection_engine
Expand Down
@@ -1,2 +1,2 @@
openai == 1.6.1
tiktoken~=0.5.2
openai==1.6.1
tiktoken==0.5.2
@@ -1,8 +1,8 @@
openai == 1.6.1
openai==1.6.1
wikipedia==1.4.0
tiktoken~=0.5.2
tiktoken==0.5.2
anthropic==0.3.5
langfuse # Tracing
langfuse==2.27.1 # Tracing
litellm==1.35.0
-r mindsdb/integrations/handlers/openai_handler/requirements.txt
-r mindsdb/integrations/handlers/langchain_embedding_handler/requirements.txt
22 changes: 15 additions & 7 deletions mindsdb/integrations/handlers/mysql_handler/mysql_handler.py
Expand Up @@ -35,10 +35,9 @@ def __init__(self, name, **kwargs):
self.database = self.connection_data.get('database')

self.connection = None
self.is_connected = False

def __del__(self):
if self.is_connected is True:
if self.is_connected:
self.disconnect()

def _unpack_config(self):
Expand All @@ -54,6 +53,20 @@ def _unpack_config(self):
except ValueError as e:
raise ValueError(str(e))

@property
def is_connected(self):
"""
Checks if the handler is connected to the MySQL database.

Returns:
bool: True if the handler is connected, False otherwise.
"""
return self.connection is not None and self.connection.is_connected()

@is_connected.setter
def is_connected(self, value):
pass

def connect(self):
"""
Establishes a connection to a MySQL database.
Expand Down Expand Up @@ -83,11 +96,9 @@ def connect(self):
connection = mysql.connector.connect(**config)
connection.autocommit = True
self.connection = connection
self.is_connected = True
return self.connection
except mysql.connector.Error as e:
logger.error(f"Error connecting to MySQL {self.database}, {e}!")
self.is_connected = False
raise

def disconnect(self):
Expand All @@ -97,7 +108,6 @@ def disconnect(self):
if self.is_connected is False:
return
self.connection.close()
self.is_connected = False
return

def check_connection(self) -> StatusResponse:
Expand All @@ -120,8 +130,6 @@ def check_connection(self) -> StatusResponse:

if result.success and need_to_close:
self.disconnect()
if not result.success and self.is_connected:
self.is_connected = False

return result

Expand Down
@@ -1,2 +1,2 @@
openai == 1.6.1
tiktoken~=0.5.2
tiktoken==0.5.2