MindsDB 25.4.3.2__py3-none-any.whl → 25.4.5.0__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.

Potentially problematic release.


This version of MindsDB might be problematic. Click here for more details.

Files changed (68) hide show
  1. mindsdb/__about__.py +1 -1
  2. mindsdb/__main__.py +18 -4
  3. mindsdb/api/executor/command_executor.py +12 -2
  4. mindsdb/api/executor/data_types/response_type.py +1 -0
  5. mindsdb/api/executor/datahub/classes/tables_row.py +3 -10
  6. mindsdb/api/executor/datahub/datanodes/datanode.py +7 -2
  7. mindsdb/api/executor/datahub/datanodes/information_schema_datanode.py +44 -10
  8. mindsdb/api/executor/datahub/datanodes/integration_datanode.py +57 -38
  9. mindsdb/api/executor/datahub/datanodes/mindsdb_tables.py +2 -1
  10. mindsdb/api/executor/datahub/datanodes/project_datanode.py +39 -7
  11. mindsdb/api/executor/datahub/datanodes/system_tables.py +116 -109
  12. mindsdb/api/executor/planner/query_plan.py +1 -0
  13. mindsdb/api/executor/planner/query_planner.py +15 -1
  14. mindsdb/api/executor/planner/steps.py +8 -2
  15. mindsdb/api/executor/sql_query/sql_query.py +24 -8
  16. mindsdb/api/executor/sql_query/steps/apply_predictor_step.py +25 -8
  17. mindsdb/api/executor/sql_query/steps/fetch_dataframe_partition.py +4 -2
  18. mindsdb/api/executor/sql_query/steps/insert_step.py +2 -1
  19. mindsdb/api/executor/sql_query/steps/prepare_steps.py +2 -3
  20. mindsdb/api/http/namespaces/config.py +19 -11
  21. mindsdb/api/litellm/start.py +82 -0
  22. mindsdb/api/mysql/mysql_proxy/libs/constants/mysql.py +133 -0
  23. mindsdb/integrations/handlers/chromadb_handler/chromadb_handler.py +7 -2
  24. mindsdb/integrations/handlers/chromadb_handler/settings.py +1 -0
  25. mindsdb/integrations/handlers/mssql_handler/mssql_handler.py +13 -4
  26. mindsdb/integrations/handlers/mysql_handler/mysql_handler.py +14 -5
  27. mindsdb/integrations/handlers/openai_handler/helpers.py +3 -5
  28. mindsdb/integrations/handlers/openai_handler/openai_handler.py +20 -8
  29. mindsdb/integrations/handlers/oracle_handler/oracle_handler.py +14 -4
  30. mindsdb/integrations/handlers/pgvector_handler/pgvector_handler.py +34 -19
  31. mindsdb/integrations/handlers/postgres_handler/postgres_handler.py +21 -18
  32. mindsdb/integrations/handlers/snowflake_handler/snowflake_handler.py +14 -4
  33. mindsdb/integrations/handlers/togetherai_handler/__about__.py +9 -0
  34. mindsdb/integrations/handlers/togetherai_handler/__init__.py +20 -0
  35. mindsdb/integrations/handlers/togetherai_handler/creation_args.py +14 -0
  36. mindsdb/integrations/handlers/togetherai_handler/icon.svg +15 -0
  37. mindsdb/integrations/handlers/togetherai_handler/model_using_args.py +5 -0
  38. mindsdb/integrations/handlers/togetherai_handler/requirements.txt +2 -0
  39. mindsdb/integrations/handlers/togetherai_handler/settings.py +33 -0
  40. mindsdb/integrations/handlers/togetherai_handler/togetherai_handler.py +234 -0
  41. mindsdb/integrations/handlers/web_handler/urlcrawl_helpers.py +1 -1
  42. mindsdb/integrations/libs/response.py +80 -32
  43. mindsdb/integrations/utilities/handler_utils.py +4 -0
  44. mindsdb/integrations/utilities/rag/rerankers/base_reranker.py +360 -0
  45. mindsdb/integrations/utilities/rag/rerankers/reranker_compressor.py +8 -153
  46. mindsdb/interfaces/agents/litellm_server.py +345 -0
  47. mindsdb/interfaces/agents/mcp_client_agent.py +252 -0
  48. mindsdb/interfaces/agents/run_mcp_agent.py +205 -0
  49. mindsdb/interfaces/functions/controller.py +3 -2
  50. mindsdb/interfaces/knowledge_base/controller.py +106 -82
  51. mindsdb/interfaces/query_context/context_controller.py +55 -15
  52. mindsdb/interfaces/query_context/query_task.py +19 -0
  53. mindsdb/interfaces/skills/skill_tool.py +7 -1
  54. mindsdb/interfaces/skills/sql_agent.py +8 -3
  55. mindsdb/interfaces/storage/db.py +2 -2
  56. mindsdb/interfaces/tasks/task_monitor.py +5 -1
  57. mindsdb/interfaces/tasks/task_thread.py +6 -0
  58. mindsdb/migrations/versions/2025-04-22_53502b6d63bf_query_database.py +27 -0
  59. mindsdb/utilities/config.py +20 -2
  60. mindsdb/utilities/context.py +1 -0
  61. mindsdb/utilities/starters.py +7 -0
  62. {mindsdb-25.4.3.2.dist-info → mindsdb-25.4.5.0.dist-info}/METADATA +226 -221
  63. {mindsdb-25.4.3.2.dist-info → mindsdb-25.4.5.0.dist-info}/RECORD +67 -53
  64. {mindsdb-25.4.3.2.dist-info → mindsdb-25.4.5.0.dist-info}/WHEEL +1 -1
  65. mindsdb/integrations/handlers/snowflake_handler/tests/test_snowflake_handler.py +0 -230
  66. /mindsdb/{integrations/handlers/snowflake_handler/tests → api/litellm}/__init__.py +0 -0
  67. {mindsdb-25.4.3.2.dist-info → mindsdb-25.4.5.0.dist-info}/licenses/LICENSE +0 -0
  68. {mindsdb-25.4.3.2.dist-info → mindsdb-25.4.5.0.dist-info}/top_level.txt +0 -0
@@ -340,14 +340,24 @@ class SnowflakeHandler(DatabaseHandler):
340
340
  raise ValueError("Invalid table name provided.")
341
341
 
342
342
  query = f"""
343
- SELECT COLUMN_NAME AS FIELD, DATA_TYPE AS TYPE
343
+ SELECT
344
+ COLUMN_NAME,
345
+ DATA_TYPE,
346
+ ORDINAL_POSITION,
347
+ COLUMN_DEFAULT,
348
+ IS_NULLABLE,
349
+ CHARACTER_MAXIMUM_LENGTH,
350
+ CHARACTER_OCTET_LENGTH,
351
+ NUMERIC_PRECISION,
352
+ NUMERIC_SCALE,
353
+ DATETIME_PRECISION,
354
+ CHARACTER_SET_NAME,
355
+ COLLATION_NAME
344
356
  FROM INFORMATION_SCHEMA.COLUMNS
345
357
  WHERE TABLE_NAME = '{table_name}'
346
358
  AND TABLE_SCHEMA = current_schema()
347
359
  """
348
360
  result = self.native_query(query)
349
- if result.resp_type is RESPONSE_TYPE.TABLE:
350
- result.data_frame = result.data_frame.rename(columns={'FIELD': 'Field', 'TYPE': 'Type'})
351
- result.data_frame['mysql_data_type'] = result.data_frame['Type'].apply(_map_type)
361
+ result.to_columns_table_response(map_type_fn=_map_type)
352
362
 
353
363
  return result
@@ -0,0 +1,9 @@
1
+ __title__ = 'MindsDB TogetherAI handler'
2
+ __package_name__ = 'mindsdb_togetherai_handler'
3
+ __version__ = '0.0.1'
4
+ __description__ = "MindsDB handler for TogetherAI"
5
+ __author__ = 'MindsDB Inc'
6
+ __github__ = 'https://github.com/mindsdb/mindsdb'
7
+ __pypi__ = 'https://pypi.org/project/mindsdb/'
8
+ __license__ = 'MIT'
9
+ __copyright__ = 'Copyright 2022- mindsdb'
@@ -0,0 +1,20 @@
1
+ from .__about__ import __description__ as description
2
+ from .__about__ import __version__ as version
3
+ from mindsdb.integrations.libs.const import HANDLER_TYPE
4
+ from .creation_args import creation_args
5
+ from .model_using_args import model_using_args
6
+
7
+ try:
8
+ from .togetherai_handler import TogetherAIHandler as Handler
9
+ import_error = None
10
+ except Exception as e:
11
+ Handler = None
12
+ import_error = e
13
+
14
+ title = "TogetherAI"
15
+ name = "togetherai"
16
+ type = HANDLER_TYPE.ML
17
+ icon_path = "icon.svg"
18
+ permanent = False
19
+
20
+ __all__ = ["Handler", "version", "name", "type", "title", "description", "import_error", "icon_path", "creation_args", "model_using_args"]
@@ -0,0 +1,14 @@
1
+ from collections import OrderedDict
2
+
3
+ from mindsdb.integrations.libs.const import HANDLER_CONNECTION_ARG_TYPE as ARG_TYPE
4
+
5
+
6
+ creation_args = OrderedDict(
7
+ togetherai_api_key={
8
+ "type": ARG_TYPE.STR,
9
+ "description": "Key for TogetherAI API.",
10
+ "required": False,
11
+ "label": "TogetherAI API key",
12
+ "secret": True,
13
+ }
14
+ )
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="2159" height="500">
3
+ <path d="M0 0 C5.21472868 4.37393195 9.07563628 9.32300204 12.8984375 14.9375 C14.33685421 17.25535975 14.33685421 17.25535975 16.52734375 18.16015625 C16.60082031 16.70609375 16.60082031 16.70609375 16.67578125 15.22265625 C17.07581468 7.86000402 17.62657175 0.54247325 18.52734375 -6.77734375 C18.65181885 -7.8147168 18.65181885 -7.8147168 18.77880859 -8.87304688 C19.40169667 -13.71419667 19.40169667 -13.71419667 20.52734375 -14.83984375 C22.74589639 -14.92767917 24.96722871 -14.94678984 27.1875 -14.9375 C28.1841996 -14.93537758 28.1841996 -14.93537758 29.20103455 -14.93321228 C31.33068274 -14.92759893 33.46022714 -14.91504429 35.58984375 -14.90234375 C37.03059744 -14.89733046 38.47135278 -14.89276726 39.91210938 -14.88867188 C43.45055477 -14.8776252 46.98893914 -14.86035167 50.52734375 -14.83984375 C50.5741884 11.56068443 50.60939345 37.96120632 50.63096809 64.36176777 C50.64125449 76.62164517 50.65526408 88.88149666 50.67822266 101.14135742 C50.69823761 111.83447815 50.71107932 122.5275801 50.71552074 133.22071904 C50.71811446 138.87587669 50.72415512 144.53098065 50.73880386 150.18612099 C50.75251623 155.52370518 50.7565392 160.86121425 50.75355911 166.19881439 C50.75410323 168.14364469 50.75799848 170.08847786 50.7657547 172.03329277 C50.87590076 201.11138857 48.27469909 231.40270391 26.90234375 253.34765625 C8.91396912 271.03678925 -17.35712696 278.14823056 -42.08203125 278.3984375 C-42.88285126 278.40818604 -43.68367126 278.41793457 -44.50875854 278.42797852 C-77.95226345 278.75185126 -77.95226345 278.75185126 -92.47265625 274.16015625 C-93.66503906 273.78632813 -94.85742188 273.4125 -96.0859375 273.02734375 C-115.87462848 266.00480007 -132.32564432 254.16617977 -142.28515625 235.41015625 C-146.56707626 226.36833446 -149.47265625 217.22198872 -149.47265625 207.16015625 C-137.92265625 207.16015625 -126.37265625 207.16015625 -114.47265625 207.16015625 C-112.82265625 211.45015625 -111.17265625 215.74015625 -109.47265625 220.16015625 C-100.34939099 234.46709496 -87.16872495 241.45499613 -71.00390625 245.4140625 C-66.46659992 246.37271904 -62.10476306 246.99394961 -57.47265625 247.16015625 C-56.49167969 247.20011719 -55.51070312 247.24007813 -54.5 247.28125 C-35.47357117 247.6742625 -15.76731114 244.27675188 -1.23046875 231.1328125 C10.24100504 219.16352003 14.69243459 202.94704782 14.625 186.6953125 C14.62358505 186.01713974 14.6221701 185.33896698 14.62071228 184.64024353 C14.6151712 182.50100047 14.60263028 180.361867 14.58984375 178.22265625 C14.58482111 176.76106923 14.58025955 175.29948056 14.57617188 173.83789062 C14.5652212 170.27861099 14.5479982 166.71939434 14.52734375 163.16015625 C13.93493896 163.89838623 13.34253418 164.63661621 12.73217773 165.3972168 C11.94141846 166.374729 11.15065918 167.35224121 10.3359375 168.359375 C9.55790771 169.32447998 8.77987793 170.28958496 7.97827148 171.28393555 C-5.84688049 187.50807295 -24.5829186 195.10781566 -45.47265625 197.16015625 C-70.50819324 198.90540989 -99.10177305 194.16653072 -118.7578125 177.44921875 C-121.76245948 174.78403578 -124.61600677 171.98259436 -127.47265625 169.16015625 C-128.1275 168.5775 -128.78234375 167.99484375 -129.45703125 167.39453125 C-146.527719 151.88996164 -154.42662453 125.5333822 -155.6953125 103.24926758 C-155.83628872 99.03200935 -155.85928159 94.81694961 -155.84765625 90.59765625 C-155.84711243 89.8520343 -155.8465686 89.10641235 -155.8460083 88.3381958 C-155.80557481 76.24922911 -154.99263271 64.79900563 -151.47265625 53.16015625 C-151.15917236 52.10755615 -151.15917236 52.10755615 -150.83935547 51.03369141 C-145.84818345 34.92360883 -137.24055656 22.07266978 -125.47265625 10.16015625 C-124.89128906 9.50660156 -124.30992187 8.85304687 -123.7109375 8.1796875 C-93.87793179 -24.65916261 -33.88513542 -25.21311024 0 0 Z M-99.26171875 31.765625 C-116.35888411 49.66341291 -121.16476905 71.62808532 -120.72265625 95.66796875 C-120.31097314 107.56149379 -117.7352924 118.43066225 -112.47265625 129.16015625 C-112.09238281 129.94777344 -111.71210938 130.73539062 -111.3203125 131.546875 C-103.21361329 147.18707247 -90.37831305 157.75801484 -73.78515625 163.41796875 C-55.84697641 168.76538141 -36.48552865 167.43022163 -19.66015625 159.09765625 C-2.52215656 149.05937858 8.58988492 133.12036782 13.67578125 114.05859375 C19.0820041 89.30900472 16.55171052 63.57256998 2.71484375 41.91015625 C-6.95731488 28.11073141 -20.73990214 17.92611663 -37.48828125 14.78173828 C-60.39772949 10.90340768 -81.89123933 15.5385805 -99.26171875 31.765625 Z " fill="#13171B" transform="translate(615.47265625,158.83984375)"/>
4
+ <path d="M0 0 C2.15267145 -0.00960264 4.30434307 -0.04063747 6.45678711 -0.07226562 C29.65448492 -0.25091399 51.19621422 5.82214652 68.50170898 21.86523438 C85.7751752 39.97182597 87.54091759 63.12628918 87.52610397 86.87690544 C87.5251293 90.32841746 87.5381876 93.77962608 87.55508423 97.23109436 C87.60110036 107.0343299 87.62598937 116.83752904 87.63256836 126.64086914 C87.63757945 132.66007813 87.6617935 138.67896208 87.69789505 144.69806099 C87.70768719 146.98456434 87.71002822 149.27111238 87.70472336 151.55763054 C87.69766117 154.74767902 87.71491334 157.9367527 87.73754883 161.12670898 C87.72937637 162.06654129 87.72120392 163.0063736 87.71278381 163.97468567 C87.78264289 169.50730718 88.35569077 172.98109077 92.25170898 177.24023438 C98.52842763 180.04507428 98.52842763 180.04507428 111.25170898 180.24023438 C111.25170898 190.47023438 111.25170898 200.70023438 111.25170898 211.24023438 C103.98139648 211.36398437 103.98139648 211.36398437 96.56420898 211.49023438 C95.06414307 211.52665039 93.56407715 211.56306641 92.01855469 211.60058594 C82.28586005 211.67987469 71.7078901 211.05923109 63.68920898 204.86523438 C57.65347575 198.36521397 55.60118781 191.66336592 53.25170898 183.24023438 C52.48600586 184.16642578 52.48600586 184.16642578 51.70483398 185.11132812 C36.68537627 202.60739855 17.1189192 212.27189032 -5.74829102 214.24023438 C-28.47911377 215.37575252 -54.64830556 212.84839421 -72.54589844 197.30151367 C-85.67976348 185.34260205 -91.52965396 172.69358939 -92.93188477 154.91210938 C-93.47217946 137.74980729 -88.11411525 120.68798276 -76.48657227 107.88867188 C-57.13545601 89.53772567 -29.43427568 86.8716908 -4.09594727 87.04492188 C-2.45828934 87.04866409 -0.82062913 87.05150532 0.81703186 87.05349731 C5.07317574 87.06103884 9.32917742 87.08060263 13.58526611 87.10290527 C17.94997231 87.12357121 22.31470207 87.13254283 26.67944336 87.14257812 C35.20359628 87.16386011 43.72763482 87.19787741 52.25170898 87.24023438 C52.13198502 83.54053641 51.99600808 79.84160452 51.85717773 76.14257812 C51.82362183 75.09952515 51.79006592 74.05647217 51.75549316 72.98181152 C51.25384885 60.12494792 47.47523498 50.92341438 38.06420898 42.05273438 C25.84174339 32.15064856 9.02307074 30.35147502 -6.13452148 31.63427734 C-20.14229949 33.12085553 -33.30659408 37.7730522 -42.84594727 48.62695312 C-47.09365601 54.37173119 -48.96456746 59.28092549 -51.74829102 66.24023438 C-62.96829102 66.24023438 -74.18829102 66.24023438 -85.74829102 66.24023438 C-83.81500402 46.90736443 -76.55192707 30.98226801 -61.44360352 18.30664062 C-43.17020039 4.85621767 -22.34178575 0.05994442 0 0 Z M-50.81079102 129.11523438 C-56.43792673 136.2757988 -58.62716677 145.21606366 -57.74829102 154.24023438 C-55.54421443 164.72580459 -50.53476608 172.06938628 -41.74829102 178.24023438 C-23.77120642 186.9707324 -2.3386476 186.37862905 16.38061523 180.20898438 C30.86749649 174.73246222 41.78337736 164.89915518 48.22045898 150.76367188 C48.56077148 149.9309375 48.90108398 149.09820312 49.25170898 148.24023438 C49.57139648 147.469375 49.89108398 146.69851563 50.22045898 145.90429688 C52.43340389 139.40889376 52.39694192 133.13206414 52.32592773 126.35351562 C52.32057007 125.37983032 52.3152124 124.40614502 52.30969238 123.4029541 C52.29578082 121.01528983 52.27630139 118.62780853 52.25170898 116.24023438 C43.2708297 116.17017386 34.29004705 116.11714255 25.30895233 116.08479786 C21.13693974 116.06926012 16.96511654 116.04824461 12.79321289 116.01391602 C8.75367928 115.98089142 4.71432574 115.96329245 0.67466736 115.95560265 C-0.85281706 115.95013526 -2.38029363 115.9394638 -3.90769958 115.9230442 C-20.12987291 115.75587641 -38.95086658 116.53877284 -50.81079102 129.11523438 Z " fill="#13171B" transform="translate(1908.748291015625,141.759765625)"/>
5
+ <path d="M0 0 C0.90878906 0.46148437 1.81757812 0.92296875 2.75390625 1.3984375 C24.17105053 13.29303128 37.63282581 33.23855762 44.48071289 56.35742188 C46.93356607 65.08344436 48.14170276 73.4740983 48.6875 82.5 C48.73616211 83.27126221 48.78482422 84.04252441 48.83496094 84.8371582 C49.14388561 91.10740484 48.58231634 96.59452031 48 103 C-5.46 103 -58.92 103 -114 103 C-110.312591 129.28195864 -110.312591 129.28195864 -97 151 C-96.38382813 151.72703125 -95.76765625 152.4540625 -95.1328125 153.203125 C-85.24289758 163.95481674 -70.58698956 170.18926943 -56.06689453 171.12451172 C-37.76204013 171.81035802 -20.95617111 168.99071359 -6.5625 156.6875 C1.63765887 148.72931303 5.51441633 140.76540081 10 130 C21.55 130 33.1 130 45 130 C41.62430483 146.87847584 35.39951341 161.03833105 24 174 C23.34515625 174.75023437 22.6903125 175.50046875 22.015625 176.2734375 C6.16227341 193.25917134 -16.26582997 201.98180415 -39.2421875 203.11010742 C-71.01725642 203.934395 -98.66670494 196.22152113 -122.1875 174.25 C-144.57978816 150.67668399 -150.73263429 120.29025519 -150.24609375 88.7109375 C-149.40936862 59.1633009 -138.85154744 32.99994986 -117.546875 12.30859375 C-86.3460903 -15.97309913 -36.57139212 -18.67650396 0 0 Z M-98.50390625 40.8203125 C-106.95457564 51.48458393 -109.75309395 60.5185637 -112 74 C-70.75 74 -29.5 74 13 74 C9.57417802 55.72894944 5.06342512 42.44639679 -9.62890625 30.94140625 C-37.64449412 11.97889044 -75.74553969 15.1860837 -98.50390625 40.8203125 Z " fill="#13171B" transform="translate(857,153)"/>
6
+ <path d="M0 0 C4.29039754 3.37292225 8.1705337 7.11901621 12 11 C12.66644531 11.66773438 13.33289062 12.33546875 14.01953125 13.0234375 C31.58432936 31.81737498 38.21562581 58.33206775 38.125 83.375 C38.12886719 84.46683594 38.13273437 85.55867188 38.13671875 86.68359375 C38.13478516 88.24400391 38.13478516 88.24400391 38.1328125 89.8359375 C38.13168457 90.78001465 38.13055664 91.7240918 38.12939453 92.69677734 C38 95 38 95 37 97 C-16.13 97 -69.26 97 -124 97 C-121.62786096 118.34925139 -117.90277611 137.73004767 -100.65625 151.9296875 C-85.28413172 163.26419244 -66.67184988 167.37686508 -47.83203125 164.69091797 C-32.65178038 161.9445833 -18.95439882 155.56081746 -9.70703125 142.84765625 C-5.65013275 136.5147564 -3.44128953 131.32386858 -1 124 C10.55 124 22.1 124 34 124 C33.2961517 130.33463468 32.6100909 135.13264607 30.375 140.875 C30.10921143 141.56553467 29.84342285 142.25606934 29.56958008 142.9675293 C20.80063798 164.90136556 3.24717182 180.69389901 -17.9375 190.3125 C-42.6732538 200.46050156 -73.44120969 199.57120757 -98.40625 190.5078125 C-108.96038198 186.07966582 -118.48816832 180.73297127 -127 173 C-127.89203125 172.20078125 -128.7840625 171.4015625 -129.703125 170.578125 C-147.99645794 153.30676597 -158.97005576 128.47256162 -160.17700195 103.30981445 C-160.73750917 67.21181 -156.45431667 35.71211914 -130.5234375 8.390625 C-96.77525738 -23.48876339 -37.78105135 -26.82711204 0 0 Z M-109 35 C-116.3189089 44.59120553 -122 55.76350312 -122 68 C-81.08 68 -40.16 68 2 68 C0.34308674 49.77395417 -6.09517711 36.8959108 -20 25 C-48.00642889 4.67400451 -86.2191423 10.21496128 -109 35 Z " fill="#13171B" transform="translate(1476,159)"/>
7
+ <path d="M0 0 C11.22 0 22.44 0 34 0 C34.33 35.64 34.66 71.28 35 108 C37.31 105.03 39.62 102.06 42 99 C54.85689647 84.93018877 72.1767082 76.02659355 91.25878906 74.78857422 C117.28325006 73.78431079 141.94051848 77.1456432 162.1875 95.0625 C178.42779879 110.20033791 185.30210493 132.34922693 187 154 C187.13491695 158.38014217 187.12663271 162.75699561 187.11352539 167.13891602 C187.11367142 168.42770157 187.11381744 169.71648712 187.1139679 171.04432678 C187.11425295 174.55196064 187.10840371 178.05955979 187.10139394 181.56718564 C187.0951115 185.24270018 187.09455275 188.91821566 187.09336853 192.59373474 C187.09026957 199.54205541 187.08207564 206.49036021 187.07201904 213.43867391 C187.06081319 221.35408653 187.05533621 229.26949994 187.05032361 237.18491852 C187.03989173 253.45662308 187.02156422 269.7283058 187 286 C175.78 286 164.56 286 153 286 C152.98018066 282.44863281 152.96036133 278.89726562 152.93994141 275.23828125 C152.87279473 263.45573361 152.79525515 251.67326964 152.71247292 239.89082336 C152.66257173 232.7527577 152.61612843 225.61470225 152.578125 218.4765625 C152.54495206 212.24743878 152.50498616 206.01839996 152.45720994 199.78937054 C152.43219323 196.49797778 152.4113566 193.20664888 152.39665604 189.91519165 C152.36408773 152.52464337 152.36408773 152.52464337 134.9375 120.25 C124.65082182 110.7193583 110.15660677 107.13080025 96.5 106.625 C81.03408974 107.21896406 65.98082667 111.95292988 54.5 122.625 C35.3049796 143.75565271 34.71145943 170.51245595 34.5859375 197.5234375 C34.56719999 200.08176276 34.54762471 202.64008201 34.5272522 205.19839478 C34.48139583 211.20799419 34.44389122 217.21758777 34.41057932 223.227265 C34.37212403 230.07878523 34.32277672 236.93021417 34.27259517 243.78165698 C34.16976314 257.85437666 34.08178414 271.92714306 34 286 C22.78 286 11.56 286 0 286 C0 191.62 0 97.24 0 0 Z " fill="#13171B" transform="translate(1090,67)"/>
8
+ <path d="M0 0 C20.45814844 17.39537331 32.01652432 41.2645894 35.3125 67.6875 C35.52038519 72.41184841 35.54045192 77.13480236 35.55273438 81.86303711 C35.56234079 84.08812302 35.59337503 86.31224334 35.625 88.53710938 C35.72521545 101.88641819 34.00609038 114.71232227 29.1875 127.25 C28.8874707 128.04027588 28.58744141 128.83055176 28.27832031 129.64477539 C23.01171261 142.97906375 15.46263855 153.65319756 5.3125 163.6875 C4.12720703 164.88826172 4.12720703 164.88826172 2.91796875 166.11328125 C-16.77885612 185.02615289 -43.84591864 192.30222575 -70.61108398 192.03930664 C-95.89138483 191.28275627 -119.62704696 183.69674535 -138.6875 166.6875 C-139.50734375 165.96175781 -140.3271875 165.23601562 -141.171875 164.48828125 C-159.59366166 147.18209969 -170.76723355 120.91321805 -171.81005859 95.72753906 C-172.55526356 65.07929129 -168.59803524 37.37955214 -148.6875 12.6875 C-148.01074219 11.84574219 -147.33398438 11.00398438 -146.63671875 10.13671875 C-110.80595702 -31.98243992 -41.91228948 -32.91848823 0 0 Z M-114.82421875 25.69921875 C-131.01758216 42.97892939 -137.27084612 65.09656929 -136.90234375 88.328125 C-136.46669764 100.35304001 -133.69138257 111.74777966 -128.6875 122.6875 C-128.05908203 124.08548828 -128.05908203 124.08548828 -127.41796875 125.51171875 C-119.91754123 140.66387925 -106.51490658 151.98712797 -90.6875 157.6875 C-72.01238311 163.34456095 -52.76272136 161.90025607 -35.38671875 153.01367188 C-29.34150535 149.72436458 -24.44695104 145.65966394 -19.6875 140.6875 C-19.06746094 140.09839844 -18.44742188 139.50929688 -17.80859375 138.90234375 C-3.25215685 124.08538897 0.58889955 101.65368811 0.6315918 81.8112793 C0.41171918 63.79732871 -4.46802717 46.97111457 -15.6875 32.6875 C-16.25984375 31.92695313 -16.8321875 31.16640625 -17.421875 30.3828125 C-27.68910145 17.70234906 -43.53205074 10.24303036 -59.5 8.25 C-79.56259325 6.21235974 -99.87011765 11.73586555 -114.82421875 25.69921875 Z " fill="#13171B" transform="translate(389.6875,164.3125)"/>
9
+ <path d="M0 0 C11.22 0 22.44 0 34 0 C34 19.14 34 38.28 34 58 C51.49 58 68.98 58 87 58 C87 68.56 87 79.12 87 90 C69.51 90 52.02 90 34 90 C34.06294415 106.66420195 34.13818203 123.32819564 34.23571491 139.99222469 C34.28061303 147.73023552 34.32004136 155.46820093 34.34643555 163.20629883 C34.36946425 169.95360302 34.40291633 176.70076279 34.44870156 183.44795233 C34.47256842 187.01804156 34.49133985 190.58798835 34.49761391 194.15815544 C34.50482683 198.15113437 34.53531812 202.1436198 34.56762695 206.13647461 C34.56619186 207.3103624 34.56475677 208.48425018 34.5632782 209.69371033 C34.64910643 217.20854091 35.11418178 224.3694545 39.9375 230.4375 C46.44492389 235.36736659 53.68996014 235.16460385 61.5546875 235.31640625 C62.45623566 235.33718735 63.35778381 235.35796844 64.28665161 235.37937927 C67.1493614 235.4444458 70.01215819 235.50355914 72.875 235.5625 C74.82292544 235.60572607 76.77084229 235.64934164 78.71875 235.69335938 C83.47907904 235.80081144 88.23947976 235.90020319 93 236 C93 246.23 93 256.46 93 267 C85.74429658 267.0924948 78.49068946 267.17193427 71.23486328 267.21972656 C68.77352923 267.23967724 66.31224155 267.26684764 63.85107422 267.30175781 C26.32436352 267.82020892 26.32436352 267.82020892 12.015625 255.2578125 C1.26100002 244.18146797 -0.31087638 228.97626021 -0.22705078 214.31030273 C-0.22648561 212.94938668 -0.22680529 211.58847002 -0.22793579 210.22755432 C-0.22850618 206.55872841 -0.21680309 202.89003509 -0.20278788 199.22123981 C-0.19022785 195.3775671 -0.18910588 191.53389087 -0.18673706 187.69020081 C-0.18053771 180.42311495 -0.16414795 173.15608975 -0.14403808 165.88903052 C-0.12163081 157.6108742 -0.11067354 149.33271488 -0.10064721 141.05453575 C-0.07978024 124.03631612 -0.04312347 107.01817999 0 90 C-12.54 90 -25.08 90 -38 90 C-38 79.44 -38 68.88 -38 58 C-25.46 58 -12.92 58 0 58 C0 38.86 0 19.72 0 0 Z " fill="#13171B" transform="translate(101,86)"/>
10
+ <path d="M0 0 C11.22 0 22.44 0 34 0 C34 19.14 34 38.28 34 58 C51.49 58 68.98 58 87 58 C87 68.56 87 79.12 87 90 C69.51 90 52.02 90 34 90 C34.08555206 106.40339091 34.17920052 122.80666832 34.28752708 139.20992184 C34.33757121 146.82685797 34.38401481 154.44378378 34.421875 162.06079102 C34.45489719 168.70259104 34.4947843 175.344309 34.54279006 181.98601824 C34.56795379 185.50019069 34.58976446 189.0143094 34.60334396 192.52854729 C34.61866136 196.45915278 34.64931054 200.38956037 34.68115234 204.32006836 C34.68331253 205.47525467 34.68547272 206.63044098 34.68769836 207.82063293 C34.7410911 220.18219699 34.7410911 220.18219699 40 231 C47.1323603 234.69826089 53.60357558 235.16571964 61.45703125 235.31640625 C62.35999435 235.33718735 63.26295746 235.35796844 64.19328308 235.37937927 C67.06628097 235.4445528 69.93936714 235.50360955 72.8125 235.5625 C74.76498294 235.60571586 76.71745708 235.64933112 78.66992188 235.69335938 C83.44652556 235.80094968 88.2232001 235.90026229 93 236 C93 246.23 93 256.46 93 267 C85.74429658 267.0924948 78.49068946 267.17193427 71.23486328 267.21972656 C68.77352923 267.23967724 66.31224155 267.26684764 63.85107422 267.30175781 C25.99500343 267.8247592 25.99500343 267.8247592 12.23828125 255.41015625 C1.18132671 243.57336613 -0.47740356 227.42034199 -0.34057617 211.92626953 C-0.33972702 210.58432026 -0.34021064 209.24236961 -0.34190369 207.90042114 C-0.34275386 204.3061969 -0.32528968 200.71228162 -0.30418181 197.1181283 C-0.28524905 193.34389528 -0.28365165 189.56965282 -0.28010559 185.79537964 C-0.27083334 178.67008598 -0.2462859 171.54493273 -0.21605712 164.4197005 C-0.18236171 156.29863128 -0.1659893 148.17755485 -0.15097082 140.05643296 C-0.11973117 123.37086049 -0.06478057 106.68548109 0 90 C-12.54 90 -25.08 90 -38 90 C-38 79.44 -38 68.88 -38 58 C-25.46 58 -12.92 58 0 58 C0 38.86 0 19.72 0 0 Z " fill="#13171B" transform="translate(961,86)"/>
11
+ <path d="M0 0 C10.23 0 20.46 0 31 0 C32.32 9.24 33.64 18.48 35 28 C39.6556108 23.55429851 39.6556108 23.55429851 41.9609375 20.46875 C52.48498114 7.72699602 68.59486084 1.84433069 84.5402832 0.18310547 C88.88086629 -0.14001486 93.2126141 -0.10365692 97.5625 -0.0625 C100.676875 -0.041875 103.79125 -0.02125 107 0 C107 11.22 107 22.44 107 34 C94.25 34.3125 94.25 34.3125 90.30957031 34.38793945 C76.70925834 34.81025195 63.74330936 37.50760699 53.375 46.8125 C39.49962137 61.64564812 35.8990542 83.07296942 35.79467773 102.62670898 C35.78477814 103.7786525 35.77487854 104.93059601 35.76467896 106.1174469 C35.73318937 109.91030855 35.70835618 113.70318271 35.68359375 117.49609375 C35.6630134 120.1316815 35.64201664 122.76726603 35.62062073 125.40284729 C35.57083623 131.62163353 35.52584497 137.84044473 35.48259836 144.0592795 C35.43310374 151.14277061 35.37823121 158.22621691 35.32291877 165.30966461 C35.20931757 179.87306842 35.10314128 194.43651824 35 209 C23.45 209 11.9 209 0 209 C0 140.03 0 71.06 0 0 Z " fill="#13171B" transform="translate(1555,144)"/>
12
+ <path d="M0 0 C11.22 0 22.44 0 34 0 C34 68.97 34 137.94 34 209 C22.78 209 11.56 209 0 209 C0 140.03 0 71.06 0 0 Z " fill="#13171B" transform="translate(2057,144)"/>
13
+ <path d="M0 0 C8.3634326 4.82327351 13.28160398 11.63918142 15.9375 20.875 C18.01634 30.76827472 16.62534926 38.39042946 11.796875 47.265625 C6.72751114 54.97987435 -0.63132322 59.6092498 -9.59375 61.56640625 C-18.03980625 62.71924439 -25.95558279 61.20604575 -33.4375 57.125 C-40.40389783 51.34798717 -46.40266915 45.1483494 -48 36 C-48.87317863 24.98451573 -47.83673557 16.39591419 -40.75 7.6875 C-30.31898591 -3.36892821 -13.87868252 -7.08698682 0 0 Z " fill="#0262F2" transform="translate(1737,291)"/>
14
+ <path d="M0 0 C5.04885564 3.02931338 8.65629405 7.96888215 10.5 13.5 C10.64648082 15.76763574 10.7209626 18.04032366 10.75 20.3125 C10.77578125 21.51519531 10.8015625 22.71789062 10.828125 23.95703125 C10.23746631 30.33473874 7.31446315 34.43445334 2.5 38.5 C-3.54543815 42.72767542 -9.25587887 43.33667481 -16.5 42.5 C-22.68760017 41.38579927 -26.21825582 38.39939701 -30.08984375 33.53125 C-34.08699723 27.77357739 -34.38551063 21.307363 -33.5 14.5 C-31.23945815 7.37525649 -27.9374761 3.19558813 -21.5 -0.5 C-15.00873511 -2.66375496 -6.33310407 -2.79148471 0 0 Z " fill="#13171B" transform="translate(2085.5,65.5)"/>
15
+ </svg>
@@ -0,0 +1,5 @@
1
+ model_using_args = {
2
+ 'togetherai_api_key': {
3
+ 'secret': True
4
+ }
5
+ }
@@ -0,0 +1,2 @@
1
+ pydantic-settings >= 2.1.0
2
+ -r mindsdb/integrations/handlers/openai_handler/requirements.txt
@@ -0,0 +1,33 @@
1
+ from pydantic_settings import BaseSettings
2
+
3
+
4
+ class TogetherAIConfig(BaseSettings):
5
+ """
6
+ Configuration for TogetherAI handler.
7
+
8
+ Attributes
9
+ ----------
10
+
11
+ BASE_URL : str
12
+ Base URL for the TogetherAI API.
13
+ DEFAULT_MODEL : str
14
+ Default model to use for TogetherAI API.
15
+ DEFAULT_MODE : str
16
+ Defat mode to use for TogetherAI API.
17
+ SUPPORTED_MODES : list[str]
18
+ List of supported modes for TogetherAI API.
19
+ """
20
+
21
+ BASE_URL: str = "https://api.together.xyz/v1"
22
+ DEFAULT_MODEL: str = "meta-llama/Llama-3.2-3B-Instruct-Turbo"
23
+ DEFAULT_EMBEDDING_MODEL: str = "togethercomputer/m2-bert-80M-32k-retrieval"
24
+ DEFAULT_MODE: str = "default"
25
+ SUPPORTED_MODES: list[str] = [
26
+ "default",
27
+ "conversational",
28
+ "conversational-full",
29
+ "embedding",
30
+ ]
31
+
32
+
33
+ togetherai_handler_config = TogetherAIConfig()
@@ -0,0 +1,234 @@
1
+ import os
2
+ import textwrap
3
+ from typing import Optional, Dict, Any
4
+ import requests
5
+ import pandas as pd
6
+ from openai import OpenAI, AuthenticationError
7
+ from mindsdb.integrations.handlers.openai_handler import Handler as OpenAIHandler
8
+ from mindsdb.integrations.utilities.handler_utils import get_api_key
9
+ from mindsdb.integrations.handlers.togetherai_handler.settings import (
10
+ togetherai_handler_config,
11
+ )
12
+
13
+ from mindsdb.utilities import log
14
+
15
+ logger = log.getLogger(__name__)
16
+
17
+
18
+ class TogetherAIHandler(OpenAIHandler):
19
+ """
20
+ This handler handles connection to the TogetherAI.
21
+ """
22
+
23
+ name = "togetherai"
24
+
25
+ def __init__(self, *args, **kwargs):
26
+ super().__init__(*args, **kwargs)
27
+ self.generative = True
28
+ self.api_base = togetherai_handler_config.BASE_URL
29
+ self.default_model = togetherai_handler_config.DEFAULT_MODEL
30
+ self.default_embedding_model = togetherai_handler_config.DEFAULT_EMBEDDING_MODEL
31
+ self.default_mode = togetherai_handler_config.DEFAULT_MODE
32
+ self.supported_modes = togetherai_handler_config.SUPPORTED_MODES
33
+
34
+ @staticmethod
35
+ def _check_client_connection(client: OpenAI):
36
+ """
37
+ Check the TogetherAI engine client connection by listing models.
38
+
39
+ Args:
40
+ client (OpenAI): OpenAI client configured with the TogetherAI API credentials.
41
+
42
+ Raises:
43
+ Exception: If the client connection (API key) is invalid.
44
+
45
+ Returns:
46
+ None
47
+ """
48
+
49
+ try:
50
+ TogetherAIHandler._get_supported_models(client.api_key, client.base_url)
51
+
52
+ except Exception as e:
53
+ raise Exception(f"Something went wrong: {e}")
54
+
55
+ def create_engine(self, connection_args):
56
+ """
57
+ Validate the TogetherAI API credentials on engine creation.
58
+
59
+ Args:
60
+ connection_args (dict): Connection arguments.
61
+
62
+ Raises:
63
+ Exception: If the handler is not configured with valid API credentials.
64
+
65
+ Returns:
66
+ None
67
+ """
68
+
69
+ connection_args = {k.lower(): v for k, v in connection_args.items()}
70
+ api_key = connection_args.get("togetherai_api_key")
71
+ if api_key is not None:
72
+ api_base = connection_args.get("api_base") or os.environ.get(
73
+ "TOGETHERAI_API_BASE", togetherai_handler_config.BASE_URL
74
+ )
75
+ client = self._get_client(api_key=api_key, base_url=api_base)
76
+ TogetherAIHandler._check_client_connection(client)
77
+
78
+ @staticmethod
79
+ def create_validation(target, args=None, **kwargs):
80
+ """
81
+ Validate the TogetherAI API credentials on model creation.
82
+
83
+ Args:
84
+ target (str): Target column, not required for LLMs.
85
+ args (dict): Handler arguments.
86
+ kwargs (dict): Handler keyword arguments.
87
+
88
+ Raises:
89
+ Exception: If the handler is not configured with valid API credentials.
90
+
91
+ Returns:
92
+ None
93
+ """
94
+ if "using" not in args:
95
+ raise Exception(
96
+ "TogetherAI engine require a USING clause! Refer to its documentation for more details"
97
+ )
98
+ else:
99
+ args = args["using"]
100
+
101
+ if (
102
+ len(set(args.keys()) & {"question_column", "prompt_template", "prompt"})
103
+ == 0
104
+ ):
105
+ raise Exception(
106
+ "One of `question_column`, `prompt_template` or `prompt` is required for this engine."
107
+ )
108
+
109
+ keys_collection = [
110
+ ["prompt_template"],
111
+ ["question_column", "context_column"],
112
+ ["prompt", "user_column", "assistant_column"],
113
+ ]
114
+ for keys in keys_collection:
115
+ if keys[0] in args and any(
116
+ x[0] in args for x in keys_collection if x != keys
117
+ ):
118
+ raise Exception(
119
+ textwrap.dedent(
120
+ """\
121
+ Please provide one of
122
+ 1) a `prompt_template`
123
+ 2) a `question_column` and an optional `context_column`
124
+ 3) a `prompt`, `user_column` and `assistant_column`
125
+ """
126
+ )
127
+ )
128
+
129
+ engine_storage = kwargs["handler_storage"]
130
+ connection_args = engine_storage.get_connection_args()
131
+ api_key = get_api_key("togetherai", args, engine_storage=engine_storage)
132
+ api_base = connection_args.get("api_base") or os.environ.get(
133
+ "TOGETHERAI_API_BASE", togetherai_handler_config.BASE_URL
134
+ )
135
+ client = TogetherAIHandler._get_client(api_key=api_key, base_url=api_base)
136
+ TogetherAIHandler._check_client_connection(client)
137
+
138
+ def create(self, target, args: Dict = None, **kwargs: Any) -> None:
139
+ """
140
+ Create a model for TogetherAI engine.
141
+
142
+ Args:
143
+ target (str): Target column, not required for LLMs.
144
+ args (dict): Handler arguments.
145
+ kwargs (dict): Handler keyword arguments.
146
+
147
+ Raises:
148
+ Exception: If the handler is not configured with valid API credentials.
149
+
150
+ Returns:
151
+ None
152
+ """
153
+ args = args["using"]
154
+ args["target"] = target
155
+ try:
156
+ api_key = get_api_key(self.api_key_name, args, self.engine_storage)
157
+ connection_args = self.engine_storage.get_connection_args()
158
+ api_base = (
159
+ args.get("api_base")
160
+ or connection_args.get("api_base")
161
+ or os.environ.get("TOGETHERAI_API_BASE")
162
+ or self.api_base
163
+ )
164
+ available_models = self._get_supported_models(api_key, api_base)
165
+
166
+ if args.get("mode") is None:
167
+ args["mode"] = self.default_mode
168
+ elif args["mode"] not in self.supported_modes:
169
+ raise Exception(
170
+ f"Invalid operation mode. Please use one of {self.supported_modes}"
171
+ )
172
+
173
+ if not args.get("model_name"):
174
+ if args["mode"] == "embedding":
175
+ args["model_name"] = self.default_embedding_model
176
+ else:
177
+ args["model_name"] = self.default_model
178
+ elif args["model_name"] not in available_models:
179
+ raise Exception(
180
+ f"Invalid model name. Please use one of {available_models}"
181
+ )
182
+ finally:
183
+ self.model_storage.json_set("args", args)
184
+
185
+ def predict(self, df: pd.DataFrame, args: Optional[Dict] = None) -> pd.DataFrame:
186
+ """
187
+ Call the TogetherAI engine to predict the next token.
188
+
189
+ Args:
190
+ df (pd.DataFrame): Input data.
191
+ args (dict): Handler arguments.
192
+
193
+ Returns:
194
+ pd.DataFrame: Predicted data.
195
+ """
196
+
197
+ api_key = get_api_key("togetherai", args, engine_storage=self.engine_storage)
198
+ supported_models = self._get_supported_models(api_key, self.api_base)
199
+ self.chat_completion_models = supported_models
200
+ return super().predict(df, args)
201
+
202
+ @staticmethod
203
+ def _get_supported_models(api_key, base_url):
204
+ """
205
+ Get the list of supported models from the TogetherAI engine.
206
+
207
+ Args:
208
+ api_key (str): TogetherAI API key.
209
+ base_url (str): TogetherAI API base URL.
210
+
211
+ Returns:
212
+ list: List of supported models.
213
+ """
214
+
215
+ list_model_endpoint = f"{base_url}/models"
216
+ headers = {
217
+ "accept": "application/json",
218
+ "authorization": f"Bearer {api_key}",
219
+ }
220
+ response = requests.get(url=list_model_endpoint, headers=headers)
221
+
222
+ if response.status_code == 200:
223
+ model_list = response.json()
224
+ chat_completion_models = list(map(lambda model: model["id"], model_list))
225
+ return chat_completion_models
226
+ elif response.status_code == 401:
227
+ raise AuthenticationError(message="Invalid API key")
228
+ else:
229
+ raise Exception(f"Failed to get supported models: {response.text}")
230
+
231
+ def finetune(
232
+ self, df: Optional[pd.DataFrame] = None, args: Optional[Dict] = None
233
+ ) -> None:
234
+ raise NotImplementedError("Fine-tuning is not supported for TogetherAI engine")
@@ -151,7 +151,7 @@ def get_all_website_links(url) -> dict:
151
151
  # Parse HTML content with BeautifulSoup
152
152
  soup = BeautifulSoup(content_html, "html.parser")
153
153
  content_text = get_readable_text_from_soup(soup)
154
- for a_tag in soup.findAll("a"):
154
+ for a_tag in soup.find_all("a"):
155
155
  href = a_tag.attrs.get("href")
156
156
  if href == "" or href is None:
157
157
  continue
@@ -1,5 +1,8 @@
1
- from typing import Optional
2
- from pandas import DataFrame
1
+ from typing import Callable
2
+ from dataclasses import dataclass, fields
3
+
4
+ import numpy
5
+ import pandas
3
6
 
4
7
  from mindsdb.utilities import log
5
8
  from mindsdb.api.executor.data_types.response_type import RESPONSE_TYPE
@@ -8,9 +11,36 @@ from mindsdb_sql_parser.ast import ASTNode
8
11
 
9
12
  logger = log.getLogger(__name__)
10
13
 
14
+
15
+ @dataclass(frozen=True)
16
+ class _INFORMATION_SCHEMA_COLUMNS_NAMES:
17
+ """Set of DataFrame columns that must be returned when calling `handler.get_columns(...)`.
18
+ These column names match the standard INFORMATION_SCHEMA.COLUMNS structure
19
+ used in SQL databases to describe table metadata.
20
+ """
21
+ COLUMN_NAME: str = 'COLUMN_NAME'
22
+ DATA_TYPE: str = 'DATA_TYPE'
23
+ ORDINAL_POSITION: str = 'ORDINAL_POSITION'
24
+ COLUMN_DEFAULT: str = 'COLUMN_DEFAULT'
25
+ IS_NULLABLE: str = 'IS_NULLABLE'
26
+ CHARACTER_MAXIMUM_LENGTH: str = 'CHARACTER_MAXIMUM_LENGTH'
27
+ CHARACTER_OCTET_LENGTH: str = 'CHARACTER_OCTET_LENGTH'
28
+ NUMERIC_PRECISION: str = 'NUMERIC_PRECISION'
29
+ NUMERIC_SCALE: str = 'NUMERIC_SCALE'
30
+ DATETIME_PRECISION: str = 'DATETIME_PRECISION'
31
+ CHARACTER_SET_NAME: str = 'CHARACTER_SET_NAME'
32
+ COLLATION_NAME: str = 'COLLATION_NAME'
33
+ MYSQL_DATA_TYPE: str = 'MYSQL_DATA_TYPE'
34
+
35
+
36
+ INF_SCHEMA_COLUMNS_NAMES = _INFORMATION_SCHEMA_COLUMNS_NAMES()
37
+ INF_SCHEMA_COLUMNS_NAMES_SET = set(f.name for f in fields(INF_SCHEMA_COLUMNS_NAMES))
38
+
39
+
40
+
11
41
  class HandlerResponse:
12
- def __init__(self, resp_type: RESPONSE_TYPE, data_frame: DataFrame = None, query: ASTNode = 0, error_code: int = 0,
13
- error_message: Optional[str] = None, affected_rows: Optional[int] = None) -> None:
42
+ def __init__(self, resp_type: RESPONSE_TYPE, data_frame: pandas.DataFrame = None, query: ASTNode = 0, error_code: int = 0,
43
+ error_message: str | None = None, affected_rows: int | None = None) -> None:
14
44
  self.resp_type = resp_type
15
45
  self.query = query
16
46
  self.data_frame = data_frame
@@ -24,6 +54,51 @@ class HandlerResponse:
24
54
  def type(self):
25
55
  return self.resp_type
26
56
 
57
+ def to_columns_table_response(self, map_type_fn: Callable) -> None:
58
+ """Transform the response to a `columns table` response.
59
+ NOTE: original dataframe will be mutated
60
+ """
61
+ if self.resp_type == RESPONSE_TYPE.COLUMNS_TABLE:
62
+ return
63
+ if self.resp_type != RESPONSE_TYPE.TABLE:
64
+ if self.resp_type == RESPONSE_TYPE.ERROR:
65
+ raise ValueError(
66
+ f"Cannot convert {self.resp_type} to {RESPONSE_TYPE.COLUMNS_TABLE}, "
67
+ f"the error is: {self.error_message}"
68
+ )
69
+ raise ValueError(f"Cannot convert {self.resp_type} to {RESPONSE_TYPE.COLUMNS_TABLE}")
70
+
71
+ self.data_frame.columns = [name.upper() for name in self.data_frame.columns]
72
+ self.data_frame[INF_SCHEMA_COLUMNS_NAMES.MYSQL_DATA_TYPE] = self.data_frame[
73
+ INF_SCHEMA_COLUMNS_NAMES.DATA_TYPE
74
+ ].apply(map_type_fn)
75
+
76
+ # region validate df
77
+ current_columns_set = set(self.data_frame.columns)
78
+ if INF_SCHEMA_COLUMNS_NAMES_SET != current_columns_set:
79
+ raise ValueError(
80
+ f'Columns set for INFORMATION_SCHEMA.COLUMNS is wrong: {list(current_columns_set)}'
81
+ )
82
+ # endregion
83
+
84
+ self.data_frame = self.data_frame.astype({
85
+ INF_SCHEMA_COLUMNS_NAMES.COLUMN_NAME: 'string',
86
+ INF_SCHEMA_COLUMNS_NAMES.DATA_TYPE: 'string',
87
+ INF_SCHEMA_COLUMNS_NAMES.ORDINAL_POSITION: 'Int32',
88
+ INF_SCHEMA_COLUMNS_NAMES.COLUMN_DEFAULT: 'string',
89
+ INF_SCHEMA_COLUMNS_NAMES.IS_NULLABLE: 'string',
90
+ INF_SCHEMA_COLUMNS_NAMES.CHARACTER_MAXIMUM_LENGTH: 'Int32',
91
+ INF_SCHEMA_COLUMNS_NAMES.CHARACTER_OCTET_LENGTH: 'Int32',
92
+ INF_SCHEMA_COLUMNS_NAMES.NUMERIC_PRECISION: 'Int32',
93
+ INF_SCHEMA_COLUMNS_NAMES.NUMERIC_SCALE: 'Int32',
94
+ INF_SCHEMA_COLUMNS_NAMES.DATETIME_PRECISION: 'Int32',
95
+ INF_SCHEMA_COLUMNS_NAMES.CHARACTER_SET_NAME: 'string',
96
+ INF_SCHEMA_COLUMNS_NAMES.COLLATION_NAME: 'string',
97
+ })
98
+ self.data_frame.replace([numpy.NaN, pandas.NA], None, inplace=True)
99
+
100
+ self.resp_type = RESPONSE_TYPE.COLUMNS_TABLE
101
+
27
102
  def to_json(self):
28
103
  try:
29
104
  data = None
@@ -49,6 +124,7 @@ class HandlerResponse:
49
124
  self.affected_rows
50
125
  )
51
126
 
127
+
52
128
  class HandlerStatusResponse:
53
129
  def __init__(self, success: bool = True,
54
130
  error_message: str = None,
@@ -70,31 +146,3 @@ class HandlerStatusResponse:
70
146
  return f"{self.__class__.__name__}: success={self.success},\
71
147
  error={self.error_message},\
72
148
  redirect_url={self.redirect_url}"
73
-
74
-
75
- class ExecutorResponse:
76
- def __init__(self, resp_type: RESPONSE_TYPE, query: object, error_code: int = 0, error_message: str = None):
77
- self.resp_type = resp_type
78
- self.query = query
79
-
80
- self.error_code = error_code
81
- self.error_message = error_message
82
-
83
- @property
84
- def type(self):
85
- return self.resp_type
86
-
87
- def to_json(self):
88
- return {"type": self.resp_type,
89
- "query": self.query,
90
- "error_code": self.error_code,
91
- "error": self.error_message}
92
-
93
- def __repr__(self):
94
- return "%s: resp_type=%s, query=%s, err_code=%s, error=%s" % (
95
- self.__class__.__name__,
96
- self.resp_type,
97
- self.query,
98
- self.error_code,
99
- self.error_message,
100
- )
@@ -63,6 +63,10 @@ def get_api_key(
63
63
  if f"{api_name.lower()}_api_key" in api_cfg:
64
64
  return api_cfg[f"{api_name.lower()}_api_key"]
65
65
 
66
+ # 6
67
+ if 'api_keys' in create_args and api_name in create_args['api_keys']:
68
+ return create_args['api_keys'][api_name]
69
+
66
70
  if strict:
67
71
  raise Exception(
68
72
  f"Missing API key '{api_name.lower()}_api_key'. Either re-create this ML_ENGINE specifying the '{api_name.lower()}_api_key' parameter, or re-create this model and pass the API key with `USING` syntax."