agenthink 0.1.19__tar.gz → 0.1.21__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agenthink
3
- Version: 0.1.19
3
+ Version: 0.1.21
4
4
  Summary: A unified agent framework for connecting workflows, databases, and agents
5
5
  Author: Ritobroto
6
6
  Requires-Python: >=3.10
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "agenthink"
3
- version = "0.1.19"
3
+ version = "0.1.21"
4
4
  description = "A unified agent framework for connecting workflows, databases, and agents"
5
5
  authors = [
6
6
  { name = "Ritobroto" }
@@ -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.info("Data inserted into MySQL database '%s', table '%s'", db_name, table_name)
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
+
@@ -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
+
@@ -0,0 +1,19 @@
1
+ from pydantic import BaseModel
2
+ from typing import List, Optional
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
+
12
+ class ConnectionRequest(BaseModel):
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agenthink
3
- Version: 0.1.19
3
+ Version: 0.1.21
4
4
  Summary: A unified agent framework for connecting workflows, databases, and agents
5
5
  Author: Ritobroto
6
6
  Requires-Python: >=3.10
@@ -2,6 +2,7 @@ README.md
2
2
  pyproject.toml
3
3
  src/agenthink/__init__.py
4
4
  src/agenthink/connection.py
5
+ src/agenthink/data_source.py
5
6
  src/agenthink/models.py
6
7
  src/agenthink/utils.py
7
8
  src/agenthink.egg-info/PKG-INFO
@@ -1,10 +0,0 @@
1
- from pydantic import BaseModel
2
- from typing import List, Optional
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] = []
File without changes
File without changes