tinybird 0.0.1.dev2__py3-none-any.whl → 0.0.1.dev3__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.
tinybird/__cli__.py CHANGED
@@ -4,5 +4,5 @@ __description__ = 'Tinybird Command Line Tool'
4
4
  __url__ = 'https://www.tinybird.co/docs/cli/introduction.html'
5
5
  __author__ = 'Tinybird'
6
6
  __author_email__ = 'support@tinybird.co'
7
- __version__ = '0.0.1.dev2'
8
- __revision__ = 'bdbc260'
7
+ __version__ = '0.0.1.dev3'
8
+ __revision__ = '50bec29'
@@ -0,0 +1,31 @@
1
+ from typing import List, Optional
2
+
3
+ from openai import OpenAI
4
+ from pydantic import BaseModel
5
+
6
+ from tinybird.tb_cli_modules.prompts import create_project_prompt
7
+
8
+
9
+ class DataFile(BaseModel):
10
+ name: str
11
+ content: str
12
+
13
+
14
+ class DataProject(BaseModel):
15
+ datasources: List[DataFile]
16
+ pipes: List[DataFile]
17
+
18
+
19
+ class LLM:
20
+ def __init__(self, model: Optional[str] = None, key: Optional[str] = None):
21
+ self.model = model
22
+ self.key = key
23
+
24
+ async def create_project(self, prompt: str) -> DataProject:
25
+ client = OpenAI(api_key=self.key)
26
+ completion = client.beta.chat.completions.parse(
27
+ model=self.model,
28
+ messages=[{"role": "system", "content": create_project_prompt}, {"role": "user", "content": prompt}],
29
+ response_format=DataProject,
30
+ )
31
+ return completion.choices[0].message.parsed or DataProject(datasources=[], pipes=[])
@@ -0,0 +1,108 @@
1
+ import time
2
+
3
+ import click
4
+ import requests
5
+
6
+ import docker
7
+ from tinybird.feedback_manager import FeedbackManager
8
+ from tinybird.tb_cli_modules.common import CLIException
9
+ from tinybird.tb_cli_modules.config import CLIConfig
10
+
11
+ # TODO: Use the official Tinybird image once it's available 'tinybirdco/tinybird-local:latest'
12
+ TB_IMAGE_NAME = "registry.gitlab.com/tinybird/analytics/tinybird-local-jammy-3.11:latest"
13
+ TB_CONTAINER_NAME = "tinybird-local"
14
+ TB_LOCAL_PORT = 80
15
+ TB_LOCAL_HOST = f"http://localhost:{TB_LOCAL_PORT}"
16
+
17
+
18
+ def start_tinybird_local(
19
+ docker_client,
20
+ ):
21
+ """Start the Tinybird container."""
22
+ containers = docker_client.containers.list(all=True, filters={"name": TB_CONTAINER_NAME})
23
+ if containers:
24
+ # Container `start` is idempotent. It's safe to call it even if the container is already running.
25
+ container = containers[0]
26
+ container.start()
27
+ else:
28
+ pull_required = False
29
+ try:
30
+ local_image = docker_client.images.get(TB_IMAGE_NAME)
31
+ local_image_id = local_image.attrs["RepoDigests"][0].split("@")[1]
32
+ remote_image = docker_client.images.get_registry_data(TB_IMAGE_NAME)
33
+ pull_required = local_image_id != remote_image.id
34
+ except Exception:
35
+ pull_required = True
36
+
37
+ if pull_required:
38
+ click.echo(
39
+ FeedbackManager.info(message="** Downloading latest version of Tinybird development environment...")
40
+ )
41
+ docker_client.images.pull(TB_IMAGE_NAME, platform="linux/amd64")
42
+
43
+ container = docker_client.containers.run(
44
+ TB_IMAGE_NAME,
45
+ name=TB_CONTAINER_NAME,
46
+ detach=True,
47
+ ports={"80/tcp": TB_LOCAL_PORT},
48
+ remove=False,
49
+ platform="linux/amd64",
50
+ )
51
+
52
+ click.echo(FeedbackManager.info(message="** Waiting for Tinybird development environment to be ready..."))
53
+ for attempt in range(10):
54
+ try:
55
+ run = container.exec_run("tb --no-version-warning sql 'SELECT 1 AS healthcheck' --format json").output
56
+ # dont parse the json as docker sometimes returns warning messages
57
+ # todo: rafa, make this rigth
58
+ if b'"healthcheck": 1' in run:
59
+ break
60
+ raise RuntimeError("Unexpected response from Tinybird")
61
+ except Exception:
62
+ if attempt == 9: # Last attempt
63
+ raise CLIException("Tinybird local environment not ready yet. Please try again in a few seconds.")
64
+ time.sleep(5) # Wait 5 seconds before retrying
65
+
66
+
67
+ def get_docker_client():
68
+ """Check if Docker is installed and running."""
69
+ try:
70
+ client = docker.from_env()
71
+ client.ping()
72
+ return client
73
+ except Exception:
74
+ raise CLIException("Docker is not running or installed. Please ensure Docker is installed and running.")
75
+
76
+
77
+ def stop_tinybird_local(docker_client):
78
+ """Stop the Tinybird container."""
79
+ try:
80
+ container = docker_client.containers.get(TB_CONTAINER_NAME)
81
+ container.stop()
82
+ except Exception:
83
+ pass
84
+
85
+
86
+ def remove_tinybird_local(docker_client):
87
+ """Remove the Tinybird container."""
88
+ try:
89
+ container = docker_client.containers.get(TB_CONTAINER_NAME)
90
+ container.remove(force=True)
91
+ except Exception:
92
+ pass
93
+
94
+
95
+ def set_up_tinybird_local(docker_client):
96
+ """Set up the Tinybird local environment."""
97
+ start_tinybird_local(docker_client)
98
+ return get_tinybird_local_client()
99
+
100
+
101
+ def get_tinybird_local_client():
102
+ """Get a Tinybird client connected to the local environment."""
103
+ config = CLIConfig.get_project_config()
104
+ tokens = requests.get(f"{TB_LOCAL_HOST}/tokens").json()
105
+ token = tokens["workspace_admin_token"]
106
+ config.set_token(token)
107
+ config.set_host(TB_LOCAL_HOST)
108
+ return config.get_client(host=TB_LOCAL_HOST, token=token)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tinybird
3
- Version: 0.0.1.dev2
3
+ Version: 0.0.1.dev3
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/cli/introduction.html
6
6
  Author: Tinybird
@@ -1,4 +1,4 @@
1
- tinybird/__cli__.py,sha256=PHs2gdn0u2epRONYAzC2TOYLhI2SR6FPDDS5NDrS0TY,250
1
+ tinybird/__cli__.py,sha256=bgGjpK7NkAkSj1v-IXZIG9nlQnRLi4faLhm9wfdnePo,250
2
2
  tinybird/check_pypi.py,sha256=_4NkharLyR_ELrAdit-ftqIWvOf7jZNPt3i76frlo9g,975
3
3
  tinybird/client.py,sha256=nd97gD2-8Ap8yDonBcVwk9eXDAL43hmIYdo-Pse43RE,50738
4
4
  tinybird/config.py,sha256=Z-BX9FrjgsLw1YwcCdF0IztLB97Zpc70VVPplO_pDSY,6089
@@ -30,6 +30,8 @@ tinybird/tb_cli_modules/datasource.py,sha256=BVYwPkKvdnEv2YMkxof7n7FOffyJm-QK7Pk
30
30
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
31
31
  tinybird/tb_cli_modules/fmt.py,sha256=_xL2AyGo3us7NpmfAXtSIhn1cGAC-A4PspdhUjm58jY,3382
32
32
  tinybird/tb_cli_modules/job.py,sha256=AG69LPb9MbobA1awwJFZJvxqarDKfRlsBjw2V1zvYqc,2964
33
+ tinybird/tb_cli_modules/llm.py,sha256=RyUBtyLJcG5DFBjkalFLgwwX-415_Uom8Hq_oKiiyBs,904
34
+ tinybird/tb_cli_modules/local.py,sha256=uamCRYoU0MhCaPUXtvCFfbzHJGwTaPMTTHRQyw0Da3k,3870
33
35
  tinybird/tb_cli_modules/pipe.py,sha256=BCLAQ3ZuWKGAih2mupnw_Y2S5B5cNS-epF317whsSEE,30989
34
36
  tinybird/tb_cli_modules/prompts.py,sha256=Esjhet-KUM1bT6RStk2voCCVjvAOUD4hDDiKpn-AYNY,7227
35
37
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
@@ -41,8 +43,8 @@ tinybird/tb_cli_modules/workspace.py,sha256=N8f1dl4BYc34ucmJ6oNZc4XZMGKd8m0Fhq7o
41
43
  tinybird/tb_cli_modules/workspace_members.py,sha256=ksXsjd233y9-sNlz4Qb-meZbX4zn1B84e_bSm2i8rhg,8731
42
44
  tinybird/tb_cli_modules/tinyunit/tinyunit.py,sha256=_ydOD4WxmKy7_h-d3fG62w_0_lD0uLl9w4EbEYtwd0U,11720
43
45
  tinybird/tb_cli_modules/tinyunit/tinyunit_lib.py,sha256=hGh1ZaXC1af7rKnX7222urkj0QJMhMWclqMy59dOqwE,1922
44
- tinybird-0.0.1.dev2.dist-info/METADATA,sha256=C0w-b-Ur4VfPVJya8uxCZvv2cBxlgaDePZnV2m2-Y9k,2404
45
- tinybird-0.0.1.dev2.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
46
- tinybird-0.0.1.dev2.dist-info/entry_points.txt,sha256=PKPKuPmA4IfJYnCFHHUiw-aAWZuBomFvwCklv1OyCjE,43
47
- tinybird-0.0.1.dev2.dist-info/top_level.txt,sha256=pgw6AzERHBcW3YTi2PW4arjxLkulk2msOz_SomfOEuc,45
48
- tinybird-0.0.1.dev2.dist-info/RECORD,,
46
+ tinybird-0.0.1.dev3.dist-info/METADATA,sha256=6J__4w3BceyDNH4mybjldWRwFGgNaDLSyvugF9Se_E4,2404
47
+ tinybird-0.0.1.dev3.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
48
+ tinybird-0.0.1.dev3.dist-info/entry_points.txt,sha256=PKPKuPmA4IfJYnCFHHUiw-aAWZuBomFvwCklv1OyCjE,43
49
+ tinybird-0.0.1.dev3.dist-info/top_level.txt,sha256=pgw6AzERHBcW3YTi2PW4arjxLkulk2msOz_SomfOEuc,45
50
+ tinybird-0.0.1.dev3.dist-info/RECORD,,