tinybird 0.0.1.dev275__py3-none-any.whl → 0.0.1.dev276__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 tinybird might be problematic. Click here for more details.

tinybird/tb/__cli__.py CHANGED
@@ -4,5 +4,5 @@ __description__ = 'Tinybird Command Line Tool'
4
4
  __url__ = 'https://www.tinybird.co/docs/forward/commands'
5
5
  __author__ = 'Tinybird'
6
6
  __author_email__ = 'support@tinybird.co'
7
- __version__ = '0.0.1.dev275'
8
- __revision__ = '0c15fc3'
7
+ __version__ = '0.0.1.dev276'
8
+ __revision__ = '6716ae6'
@@ -59,6 +59,7 @@ from tinybird.tb.modules.config import CLIConfig
59
59
  from tinybird.tb.modules.deployment_common import create_deployment
60
60
  from tinybird.tb.modules.exceptions import CLIBuildException, CLIDeploymentException, CLIMockException
61
61
  from tinybird.tb.modules.feedback_manager import FeedbackManager
62
+ from tinybird.tb.modules.llm import LLM
62
63
  from tinybird.tb.modules.local_common import get_tinybird_local_client
63
64
  from tinybird.tb.modules.login_common import login
64
65
  from tinybird.tb.modules.mock_common import append_mock_data, create_mock_data
@@ -474,9 +475,13 @@ def run_agent(
474
475
  click.echo(FeedbackManager.info(message="Message history cleared!"))
475
476
  clear_messages()
476
477
  continue
477
- elif user_input.lower().startswith("select ") or user_input.lower().startswith("with "):
478
+ elif not is_natural_language(user_input, user_token, host):
478
479
  query = f"SELECT * FROM ({user_input.strip()}) FORMAT JSON"
479
- result = execute_query_local(config, query=query)
480
+ try:
481
+ result = execute_query_local(config, query=query)
482
+ except Exception as e:
483
+ click.echo(FeedbackManager.error(message=f"Error executing query: {e}"))
484
+ continue
480
485
  stats = result["statistics"]
481
486
  seconds = stats["elapsed"]
482
487
  rows_read = humanfriendly.format_number(stats["rows_read"])
@@ -725,3 +730,46 @@ def get_pipe_data_test(client: TinyB, pipe_name: str, test_params: Optional[dict
725
730
  "pipeline": pipe_name,
726
731
  }
727
732
  return client._req_raw(f"""/v0/sql?{urllib.parse.urlencode(params)}&{test_params}""")
733
+
734
+
735
+ def is_natural_language(user_input: str, user_token: str, host: str) -> bool:
736
+ stripped_input = user_input.strip().lower()
737
+ sql_keywords = ["select", "with"]
738
+ if not any(stripped_input.startswith(keyword) for keyword in sql_keywords):
739
+ return True
740
+
741
+ prompt = """Analyze the following text and determine if it's natural language or a SQL query.
742
+
743
+ Respond with only "NATURAL" if it's natural language (like a question, request, or conversational text), or "SQL" if it's a SQL query (like SELECT, WITH, INSERT, UPDATE, DELETE, etc. statements).
744
+
745
+ Examples:
746
+ - "show me all users" -> NATURAL
747
+ - "what are the top products?" -> NATURAL
748
+ - "SELECT * FROM users" -> SQL
749
+ - "WITH cte AS (SELECT...) SELECT..." -> SQL
750
+ - "select count(*) from orders" -> SQL
751
+ - "help me analyze the data" -> NATURAL"""
752
+
753
+ try:
754
+ thinking_animation = ThinkingAnimation()
755
+ thinking_animation.start()
756
+ llm = LLM(user_token=user_token, host=host)
757
+ response_text = llm.ask(
758
+ system_prompt=prompt,
759
+ prompt=f"Text: '{user_input}'",
760
+ feature="tb_agent_is_natural_language",
761
+ model="vertex_ai/gemini-2.0-flash-001",
762
+ )
763
+ thinking_animation.stop()
764
+ if "NATURAL" in response_text:
765
+ return True
766
+ elif "SQL" in response_text:
767
+ return False
768
+ else:
769
+ # If unclear, default to natural language to be safe
770
+ return True
771
+
772
+ except Exception:
773
+ # If the LLM call fails, fall back to simple heuristics
774
+ # Check if it starts with common SQL keywords
775
+ return not any(stripped_input.startswith(keyword) for keyword in sql_keywords)
@@ -20,13 +20,15 @@ class LLM:
20
20
  self.host = host
21
21
  self.user_token = user_token
22
22
 
23
- def ask(self, system_prompt: str, prompt: str, feature: Optional[str] = None) -> str:
23
+ def ask(self, system_prompt: str, prompt: str, feature: Optional[str] = None, model: Optional[str] = None) -> str:
24
24
  """
25
25
  Calls the model with the given prompt and returns the response.
26
26
 
27
27
  Args:
28
28
  system_prompt (str): The system prompt to send to the model.
29
29
  prompt (str): The user prompt to send to the model.
30
+ feature (Optional[str]): The feature to send to the model.
31
+ model (Optional[str]): The model to use.
30
32
 
31
33
  Returns:
32
34
  str: The response from the language model.
@@ -36,6 +38,8 @@ class LLM:
36
38
  params = {"origin": "cli"}
37
39
  if feature:
38
40
  params["feature"] = feature
41
+ if model:
42
+ params["model"] = model
39
43
  cli_config = CLIConfig.get_project_config()
40
44
  workspace_id = cli_config.get("id")
41
45
  params_str = urllib.parse.urlencode(params)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev275
3
+ Version: 0.0.1.dev276
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/forward/commands
6
6
  Author: Tinybird
@@ -17,7 +17,7 @@ tinybird/datafile/exceptions.py,sha256=8rw2umdZjtby85QbuRKFO5ETz_eRHwUY5l7eHsy1w
17
17
  tinybird/datafile/parse_connection.py,sha256=tRyn2Rpr1TeWet5BXmMoQgaotbGdYep1qiTak_OqC5E,1825
18
18
  tinybird/datafile/parse_datasource.py,sha256=ssW8QeFSgglVFi3sDZj_HgkJiTJ2069v2JgqnH3CkDE,1825
19
19
  tinybird/datafile/parse_pipe.py,sha256=xf4m0Tw44QWJzHzAm7Z7FwUoUUtr7noMYjU1NiWnX0k,3880
20
- tinybird/tb/__cli__.py,sha256=F6DuvogeaLQfXF18e87QuhWLJgcSX2Sq60BJKK8XzF8,247
20
+ tinybird/tb/__cli__.py,sha256=bGmVAS-5X5ZYyTYKDq1fQ8vA4zppIypVRErGtzvDkAU,247
21
21
  tinybird/tb/check_pypi.py,sha256=Gp0HkHHDFMSDL6nxKlOY51z7z1Uv-2LRexNTZSHHGmM,552
22
22
  tinybird/tb/cli.py,sha256=FdDFEIayjmsZEVsVSSvRiVYn_FHOVg_zWQzchnzfWho,1008
23
23
  tinybird/tb/client.py,sha256=IQRaInDjOwr9Fzaz3_xXc3aUGqh94tM2lew7IZbB9eM,53733
@@ -42,7 +42,7 @@ tinybird/tb/modules/feedback_manager.py,sha256=xkZjwGOV50-oc0y9h58ei4MZ1mwOMOaN_
42
42
  tinybird/tb/modules/info.py,sha256=F5vY4kHS_kyO2uSBKac92HoOb447oDeRlzpwtAHTuKc,6872
43
43
  tinybird/tb/modules/infra.py,sha256=JE9oLIyF4bi_JBoe-BgZ5HhKp_lQgSihuSV1KIS02Qs,32709
44
44
  tinybird/tb/modules/job.py,sha256=wBsnu8UPTOha2rkLvucgmw4xYv73ubmui3eeSIF68ZM,3107
45
- tinybird/tb/modules/llm.py,sha256=CpTq2YAk88E8ENpQA94-mas3UDN1aqa--9Al8GdwQtc,1575
45
+ tinybird/tb/modules/llm.py,sha256=fPBBCmM3KlCksLlgJkg4joDn6y3H5QjDzE-Pm4YNf7E,1782
46
46
  tinybird/tb/modules/llm_utils.py,sha256=nS9r4FAElJw8yXtmdYrx-rtI2zXR8qXfi1QqUDCfxvg,3469
47
47
  tinybird/tb/modules/local.py,sha256=tpiw_F_qOIp42h3kTBwTm5GQDyuVLF0QNF1jmB0zR94,6845
48
48
  tinybird/tb/modules/local_common.py,sha256=_WODjW3oPshgsZ1jDFFx2nr0zrLi3Gxz5dlahWPobM8,17464
@@ -69,7 +69,7 @@ tinybird/tb/modules/watch.py,sha256=No0bK1M1_3CYuMaIgylxf7vYFJ72lTJe3brz6xQ-mJo,
69
69
  tinybird/tb/modules/workspace.py,sha256=Q_8HcxMsNg8QG9aBlwcWS2umrDP5IkTIHqqz3sfmGuc,11341
70
70
  tinybird/tb/modules/workspace_members.py,sha256=5JdkJgfuEwbq-t6vxkBhYwgsiTDxF790wsa6Xfif9nk,8608
71
71
  tinybird/tb/modules/agent/__init__.py,sha256=i3oe3vDIWWPaicdCM0zs7D7BJ1W0k7th93ooskHAV00,54
72
- tinybird/tb/modules/agent/agent.py,sha256=MjLpl2uNASKJiKH74U9HgvQk4h8gxii5u2KR1nJAXx4,31096
72
+ tinybird/tb/modules/agent/agent.py,sha256=kPZEudIYL4pf4FXj_d7fWZvUi1f5BqG5fd-QWQueKsA,32976
73
73
  tinybird/tb/modules/agent/animations.py,sha256=4WOC5_2BracttmMCrV0H91tXfWcUzQHBUaIJc5FA7tE,3490
74
74
  tinybird/tb/modules/agent/banner.py,sha256=l6cO5Fi7lbVKp-GsBP8jf3IkjOWxg2jpAt9NBCy0WR8,4085
75
75
  tinybird/tb/modules/agent/command_agent.py,sha256=NTzgb9qnuG-gDpk87VijKs1UUMukJPaJI5UiZtRWUoQ,2864
@@ -117,8 +117,8 @@ tinybird/tb_cli_modules/config.py,sha256=IsgdtFRnUrkY8-Zo32lmk6O7u3bHie1QCxLwgp4
117
117
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
118
118
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
119
119
  tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
120
- tinybird-0.0.1.dev275.dist-info/METADATA,sha256=94PPiZAh3Vx9P9w5zSsse5_Dr9KV22caI0t7iM0hNsE,1763
121
- tinybird-0.0.1.dev275.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
122
- tinybird-0.0.1.dev275.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
123
- tinybird-0.0.1.dev275.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
124
- tinybird-0.0.1.dev275.dist-info/RECORD,,
120
+ tinybird-0.0.1.dev276.dist-info/METADATA,sha256=EILhMFhFnfIsfN1iaV2ZG3Ex5EmbLNELsIXRrC1ODPo,1763
121
+ tinybird-0.0.1.dev276.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
122
+ tinybird-0.0.1.dev276.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
123
+ tinybird-0.0.1.dev276.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
124
+ tinybird-0.0.1.dev276.dist-info/RECORD,,