agenthink 0.1.19__py3-none-any.whl → 0.1.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agenthink/connection.py +108 -7
- agenthink/data_source.py +24 -0
- agenthink/models.py +15 -6
- {agenthink-0.1.19.dist-info → agenthink-0.1.21.dist-info}/METADATA +1 -1
- agenthink-0.1.21.dist-info/RECORD +9 -0
- agenthink-0.1.19.dist-info/RECORD +0 -8
- {agenthink-0.1.19.dist-info → agenthink-0.1.21.dist-info}/WHEEL +0 -0
- {agenthink-0.1.19.dist-info → agenthink-0.1.21.dist-info}/top_level.txt +0 -0
agenthink/connection.py
CHANGED
|
@@ -48,11 +48,6 @@ class DBConnector:
|
|
|
48
48
|
f"EndpointSuffix=core.windows.net"
|
|
49
49
|
)
|
|
50
50
|
|
|
51
|
-
logger.debug("DEBUG TEST: debug level log")
|
|
52
|
-
logger.info("INFO TEST: info level log")
|
|
53
|
-
logger.warning("WARNING TEST: warning level log")
|
|
54
|
-
logger.error("ERROR TEST: error level log")
|
|
55
|
-
|
|
56
51
|
|
|
57
52
|
try:
|
|
58
53
|
blob_service = BlobServiceClient.from_connection_string(connection_str)
|
|
@@ -372,7 +367,7 @@ class DBConnector:
|
|
|
372
367
|
cursor.execute(sql, values)
|
|
373
368
|
database_connection.commit()
|
|
374
369
|
cursor.close()
|
|
375
|
-
logger.
|
|
370
|
+
logger.debug("Data inserted into MySQL database '%s', table '%s'", db_name, table_name)
|
|
376
371
|
except Exception as e:
|
|
377
372
|
logger.exception("Failed to insert data into MySQL database '%s', table '%s': %s", db_name, table_name, e)
|
|
378
373
|
if database_type == "mssql":
|
|
@@ -396,6 +391,109 @@ class DBConnector:
|
|
|
396
391
|
except Exception as e:
|
|
397
392
|
logger.exception("Insert failed for %s database '%s', table '%s'", database_type, db_name, table_name)
|
|
398
393
|
|
|
394
|
+
def get_data(self, db_name: str, table_name: str, num_rows: int = 5):
|
|
395
|
+
"""
|
|
396
|
+
Retrieve a limited number of rows from a table for display.
|
|
397
|
+
|
|
398
|
+
Parameters
|
|
399
|
+
----------
|
|
400
|
+
db_name : str
|
|
401
|
+
Name of the database connection.
|
|
402
|
+
table_name : str
|
|
403
|
+
Target table name (must be trusted).
|
|
404
|
+
num_rows : int, optional
|
|
405
|
+
Number of rows to retrieve (default is 5).
|
|
406
|
+
|
|
407
|
+
Returns
|
|
408
|
+
-------
|
|
409
|
+
list[tuple] or None
|
|
410
|
+
Retrieved rows if successful, otherwise None.
|
|
411
|
+
"""
|
|
412
|
+
db = self.connection_object_dict[db_name]
|
|
413
|
+
db_type = db["database_type"]
|
|
414
|
+
conn = db["connection_object"]
|
|
415
|
+
|
|
416
|
+
cursor = conn.cursor()
|
|
417
|
+
try:
|
|
418
|
+
if db_type == "mysql":
|
|
419
|
+
sql = f"SELECT * FROM {table_name} LIMIT %s"
|
|
420
|
+
cursor.execute(sql, (num_rows,))
|
|
421
|
+
elif db_type == "mssql":
|
|
422
|
+
sql = f"SELECT TOP ({num_rows}) * FROM [{table_name}]"
|
|
423
|
+
cursor.execute(sql)
|
|
424
|
+
else:
|
|
425
|
+
return None
|
|
426
|
+
|
|
427
|
+
return cursor.fetchall()
|
|
428
|
+
except Exception:
|
|
429
|
+
logger.exception(
|
|
430
|
+
"Failed to retrieve data from %s database '%s', table '%s'",
|
|
431
|
+
db_type, db_name, table_name
|
|
432
|
+
)
|
|
433
|
+
return None
|
|
434
|
+
finally:
|
|
435
|
+
cursor.close()
|
|
436
|
+
|
|
437
|
+
def get_schema(self, db_name: str, table_name: str):
|
|
438
|
+
"""
|
|
439
|
+
Retrieve column metadata for a table from a database.
|
|
440
|
+
|
|
441
|
+
Parameters
|
|
442
|
+
----------
|
|
443
|
+
db_name : str
|
|
444
|
+
Name of the database connection.
|
|
445
|
+
table_name : str
|
|
446
|
+
Target table name (must be trusted).
|
|
447
|
+
|
|
448
|
+
Returns
|
|
449
|
+
-------
|
|
450
|
+
list[tuple] or None
|
|
451
|
+
List of (column_name, data_type, is_nullable) ordered by column position,
|
|
452
|
+
or None if the schema cannot be retrieved.
|
|
453
|
+
|
|
454
|
+
Notes
|
|
455
|
+
-----
|
|
456
|
+
- Uses INFORMATION_SCHEMA for portability.
|
|
457
|
+
- Supports MySQL and MSSQL.
|
|
458
|
+
- Errors are logged and not raised.
|
|
459
|
+
"""
|
|
460
|
+
|
|
461
|
+
db = self.connection_object_dict[db_name]
|
|
462
|
+
db_type = db["database_type"]
|
|
463
|
+
conn = db["connection_object"]
|
|
464
|
+
|
|
465
|
+
cursor = conn.cursor()
|
|
466
|
+
try:
|
|
467
|
+
if db_type == "mysql":
|
|
468
|
+
sql = """
|
|
469
|
+
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE
|
|
470
|
+
FROM INFORMATION_SCHEMA.COLUMNS
|
|
471
|
+
WHERE TABLE_SCHEMA = DATABASE()
|
|
472
|
+
AND TABLE_NAME = %s
|
|
473
|
+
ORDER BY ORDINAL_POSITION
|
|
474
|
+
"""
|
|
475
|
+
cursor.execute(sql, (table_name,))
|
|
476
|
+
result = cursor.fetchall()
|
|
477
|
+
if db_type == "mssql":
|
|
478
|
+
sql = """
|
|
479
|
+
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE
|
|
480
|
+
FROM INFORMATION_SCHEMA.COLUMNS
|
|
481
|
+
WHERE TABLE_NAME = ?
|
|
482
|
+
ORDER BY ORDINAL_POSITION
|
|
483
|
+
"""
|
|
484
|
+
cursor.execute(sql, (table_name,))
|
|
485
|
+
result = cursor.fetchall()
|
|
486
|
+
except Exception:
|
|
487
|
+
logger.exception(
|
|
488
|
+
"Failed to retrieve schema from %s database '%s', table '%s'",
|
|
489
|
+
db_type, db_name, table_name
|
|
490
|
+
)
|
|
491
|
+
return None
|
|
492
|
+
finally:
|
|
493
|
+
cursor.close()
|
|
494
|
+
return result
|
|
495
|
+
|
|
496
|
+
|
|
399
497
|
def _debugging_function(self):
|
|
400
498
|
prefix = f"{self._workflow_id}/{self._user_id}/"
|
|
401
499
|
all_blob_list = self.__container_client.list_blobs(name_starts_with=prefix)
|
|
@@ -411,5 +509,8 @@ class DBConnector:
|
|
|
411
509
|
Json data: {self.json_data}\n
|
|
412
510
|
Number of datastores: {self.no_of_datastores}\n
|
|
413
511
|
Current connection_object_dict: {self.connection_object_dict}\n
|
|
512
|
+
D365 connection:
|
|
414
513
|
"""
|
|
415
|
-
return output_message
|
|
514
|
+
return output_message
|
|
515
|
+
|
|
516
|
+
|
agenthink/data_source.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# ...existing code...
|
|
2
|
+
import json
|
|
3
|
+
from fastapi import FastAPI
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
import mysql.connector
|
|
6
|
+
from fastapi import APIRouter
|
|
7
|
+
import mysql.connector
|
|
8
|
+
from azure.identity import ClientSecretCredential
|
|
9
|
+
from azure.keyvault.secrets import SecretClient
|
|
10
|
+
from mysql.connector import pooling
|
|
11
|
+
import json
|
|
12
|
+
from azure.storage.blob import BlobServiceClient
|
|
13
|
+
from azure.storage.blob import BlobPrefix
|
|
14
|
+
import pyodbc
|
|
15
|
+
import agenthink.utils as utils
|
|
16
|
+
import os
|
|
17
|
+
import json
|
|
18
|
+
import dotenv
|
|
19
|
+
import logging
|
|
20
|
+
import re
|
|
21
|
+
dotenv.load_dotenv()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
agenthink/models.py
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
from pydantic import BaseModel
|
|
2
2
|
from typing import List, Optional
|
|
3
3
|
|
|
4
|
+
# class ConnectionRequest(BaseModel):
|
|
5
|
+
# query: str
|
|
6
|
+
# user_id: str
|
|
7
|
+
# session_id: str
|
|
8
|
+
# workflow_id: str
|
|
9
|
+
# datastore: Optional[List] = []
|
|
10
|
+
# tools: Optional[List] = []
|
|
11
|
+
|
|
4
12
|
class ConnectionRequest(BaseModel):
|
|
5
|
-
query: str
|
|
6
|
-
user_id: str
|
|
7
|
-
session_id: str
|
|
8
|
-
workflow_id: str
|
|
9
|
-
datastore: Optional[List] =
|
|
10
|
-
tools: Optional[List] =
|
|
13
|
+
query: Optional[str] = None
|
|
14
|
+
user_id: Optional[str] = None
|
|
15
|
+
session_id: Optional[str] = None
|
|
16
|
+
workflow_id: Optional[str] = None
|
|
17
|
+
datastore: Optional[List] = None
|
|
18
|
+
tools: Optional[List] = None
|
|
19
|
+
d365request: Optional[dict] = None
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
agenthink/__init__.py,sha256=6oUldrZgE76j8OhwsQgVY5vdaPTDFyChOljske-so8U,78
|
|
2
|
+
agenthink/connection.py,sha256=5EIZkthtAf_bCICCcEHaLRxP_tEflpJNA1hPHMGDf44,20895
|
|
3
|
+
agenthink/data_source.py,sha256=HDi-UDAphTCKiFqWEB_-MfHwXpJKqfn_i05-LdID3M0,561
|
|
4
|
+
agenthink/models.py,sha256=O5lWUNP1soAxU1X0iuE_lxYoyuXiKI0LXI6S_6zmxiE,559
|
|
5
|
+
agenthink/utils.py,sha256=r5o74RbenFhQ7E3N7naoLJ-fYEe9otz0nkcvwKHDTaU,911
|
|
6
|
+
agenthink-0.1.21.dist-info/METADATA,sha256=KLsNFvne6GMA0zrxB77X7TRgsC02Gy26HRdaGPnKa70,1722
|
|
7
|
+
agenthink-0.1.21.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
agenthink-0.1.21.dist-info/top_level.txt,sha256=rYw4Lx2uqOzbGCSoJEaikme7vS9NvgbVMc26QUIZoZM,10
|
|
9
|
+
agenthink-0.1.21.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
agenthink/__init__.py,sha256=6oUldrZgE76j8OhwsQgVY5vdaPTDFyChOljske-so8U,78
|
|
2
|
-
agenthink/connection.py,sha256=ZWWXsn1RiylzgOyL_-TQEuYYxNEMpqqAF0_HFedBoH4,17648
|
|
3
|
-
agenthink/models.py,sha256=PhXEMmfU31MTt1IwXxXV9DVPl5PLroQFHjRgRDs8iTo,251
|
|
4
|
-
agenthink/utils.py,sha256=r5o74RbenFhQ7E3N7naoLJ-fYEe9otz0nkcvwKHDTaU,911
|
|
5
|
-
agenthink-0.1.19.dist-info/METADATA,sha256=-DF_4vTTRb6FF1T7rEGFnSGDYYOWfAHe2r3pplPy7-o,1722
|
|
6
|
-
agenthink-0.1.19.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
-
agenthink-0.1.19.dist-info/top_level.txt,sha256=rYw4Lx2uqOzbGCSoJEaikme7vS9NvgbVMc26QUIZoZM,10
|
|
8
|
-
agenthink-0.1.19.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|