Skip to content

Commit

Permalink
database bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
lnxpy committed Dec 9, 2023
1 parent ad1a2e0 commit 953fbb1
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions hey/middlewares/mindsdb.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from getpass import getuser

import mindsdb_sdk
from mindsdb_sdk.server import Server, Database
from mindsdb_sdk.server import Databases, Server
from pandas import DataFrame
from requests.exceptions import HTTPError, ConnectionError
from requests.exceptions import ConnectionError, HTTPError
from rich.markdown import Markdown

from hey.constants.service import MINDSDB_HOST
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(self, email: str, password: str) -> None:
self.password = password

self.is_authenticated: bool = False
self.database: Database
self.database: Databases

def authenticate(self) -> None:
"""
Expand All @@ -54,15 +54,19 @@ def authenticate(self) -> None:
password=self.password,
)
except HTTPError:
raise CredentialsError('Email or password is incorrect. Make sure to enter the right credentials.')
raise CredentialsError(
"Email or password is incorrect. Make sure to enter the right credentials."
)
except ConnectionError:
raise NetworkError('Make sure you have access to the internet and try again.')
raise NetworkError(
"Make sure you have access to the internet and try again."
)

self.is_authenticated = True
self.database = self.collect_database(server)

@staticmethod
def collect_database(server: Server) -> Database:
def collect_database(server: Server) -> Databases:
return server.list_databases()[0]

def answer(self, question: str) -> Markdown:
Expand All @@ -75,11 +79,13 @@ def answer(self, question: str) -> Markdown:
response from MindsDB in Markdown format
"""

return Markdown(to_data(
self.database.query(
SQL_ASK_QUERY.substitute(
ask=question,
user=getuser(),
)
).fetch()
))
return Markdown(
to_data(
self.database.query(
SQL_ASK_QUERY.substitute(
ask=question,
user=getuser(),
)
).fetch()
)
)

0 comments on commit 953fbb1

Please sign in to comment.