truefoundry 0.5.3rc3__py3-none-any.whl → 0.5.3rc4__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 truefoundry might be problematic. Click here for more details.

@@ -63,3 +63,4 @@ API_SERVER_RELATIVE_PATH = "api/svc"
63
63
  MLFOUNDRY_SERVER_RELATIVE_PATH = "api/ml"
64
64
  VERSION_PREFIX = "v1"
65
65
  SERVICEFOUNDRY_CLIENT_MAX_RETRIES = 2
66
+ GATEWAY_SERVER_RELATIVE_PATH = "api/llm"
@@ -2,7 +2,7 @@ import click
2
2
 
3
3
  from truefoundry.cli.const import COMMAND_CLS, GROUP_CLS
4
4
  from truefoundry.cli.display_util import print_entity_list
5
- from truefoundry.gateway.lib.models import list_models
5
+ from truefoundry.gateway.lib.models import generate_code_for_model, list_models
6
6
 
7
7
 
8
8
  def get_gateway_cli():
@@ -27,4 +27,25 @@ def get_gateway_cli():
27
27
  enabled_models = list_models(model_type)
28
28
  print_entity_list("Models", enabled_models)
29
29
 
30
+ @gateway.command("generate-code", cls=COMMAND_CLS, help="Generate code for a model")
31
+ @click.argument("model_id")
32
+ @click.option(
33
+ "--inference-type",
34
+ type=click.Choice(["chat", "completion", "embedding"]),
35
+ default="chat",
36
+ help="Type of inference to generate code for",
37
+ )
38
+ @click.option(
39
+ "--client",
40
+ type=click.Choice(["openai", "rest", "langchain", "stream", "node", "curl"]),
41
+ default="curl",
42
+ help="Language/framework to generate code for",
43
+ )
44
+ def generate_code_cli(model_id: str, inference_type: str, client: str):
45
+ """Generate code for a model"""
46
+ code = generate_code_for_model(
47
+ model_id, client=client, inference_type=inference_type
48
+ )
49
+ print(code)
50
+
30
51
  return gateway
@@ -0,0 +1,51 @@
1
+ from typing import Literal, Optional
2
+
3
+ import requests
4
+
5
+ from truefoundry.common.constants import GATEWAY_SERVER_RELATIVE_PATH
6
+ from truefoundry.common.credential_provider import (
7
+ CredentialProvider,
8
+ EnvCredentialProvider,
9
+ FileCredentialProvider,
10
+ )
11
+
12
+
13
+ class GatewayServiceClient:
14
+ def __init__(
15
+ self,
16
+ credential_provider: Optional[CredentialProvider] = None,
17
+ host: Optional[str] = None,
18
+ ) -> None:
19
+ if credential_provider is None:
20
+ if EnvCredentialProvider.can_provide():
21
+ credential_provider = EnvCredentialProvider()
22
+ elif FileCredentialProvider.can_provide():
23
+ credential_provider = FileCredentialProvider()
24
+ else:
25
+ raise Exception(
26
+ "No credentials found. Please login using `tfy login` or set TFY_API_KEY environment variable"
27
+ )
28
+
29
+ self._credential_provider = credential_provider
30
+ self._host = credential_provider.base_url
31
+
32
+ def _get_header(self):
33
+ return {
34
+ "Authorization": f"Bearer {self._credential_provider.token.access_token}"
35
+ }
36
+
37
+ @property
38
+ def _base_url(self) -> str:
39
+ return f"{self._host}/{GATEWAY_SERVER_RELATIVE_PATH}"
40
+
41
+ def generate_code(
42
+ self, model_id: str, inference_type: Literal["chat", "completion", "embedding"]
43
+ ) -> str:
44
+ url = f"{self._base_url}/api/inference/openai/generate-code-snippet"
45
+ data = {
46
+ "model": model_id,
47
+ "playground_endpoint": self._base_url,
48
+ "inference_type": inference_type,
49
+ }
50
+ response = requests.post(url, headers=self._get_header(), json=data)
51
+ return response.json()
@@ -17,10 +17,15 @@ class GatewayModel(BaseModel):
17
17
  model_fqn: str
18
18
 
19
19
  def list_row_data(self) -> Dict[str, Any]:
20
+ model_display = self.model_fqn
21
+ provider_display = self.provider
22
+ if self.model_id:
23
+ provider_display = f"{self.provider} ({self.model_id})"
24
+
20
25
  return {
21
- "model_id": self.model_fqn,
22
- "provider": self.provider,
23
- "provider_model_id": self.model_id,
26
+ "model": model_display,
27
+ "provider": provider_display,
28
+ "type": self.types if isinstance(self.types, str) else ", ".join(self.types)
24
29
  }
25
30
 
26
31
 
@@ -3,6 +3,7 @@ from typing import List, Literal, Optional
3
3
  from truefoundry.deploy.lib.clients.servicefoundry_client import (
4
4
  ServiceFoundryServiceClient,
5
5
  )
6
+ from truefoundry.gateway.lib.client import GatewayServiceClient
6
7
  from truefoundry.gateway.lib.entities import GatewayModel
7
8
 
8
9
 
@@ -27,3 +28,40 @@ def list_models(
27
28
  enabled_models.append(model)
28
29
 
29
30
  return enabled_models
31
+
32
+
33
+ def generate_code_for_model(
34
+ model_id: str,
35
+ client: Literal["openai", "rest", "langchain", "stream", "node", "curl"] = "curl",
36
+ inference_type: Literal["chat", "completion", "embedding"] = "chat",
37
+ ) -> str:
38
+ """Generate code snippet for using a model in the specified language/framework
39
+
40
+ Args:
41
+ model_id (str): ID of the model to generate code for
42
+ language (Literal["openai", "rest", "langchain", "stream", "node", "curl"]): Language/framework to generate code for. Defaults to "curl"
43
+ inference_type (Literal["chat", "completion", "embedding"]): Type of inference to generate code for. Defaults to "chat"
44
+
45
+ Returns:
46
+ str: Code snippet for using the model in the specified language/framework
47
+ """
48
+ gateway_client = GatewayServiceClient()
49
+ response = gateway_client.generate_code(model_id, inference_type)
50
+
51
+ code_map = {
52
+ "openai": ("openai_code", "Python code using OpenAI SDK for direct API calls"),
53
+ "rest": ("rest_code", "Python code using requests library for REST API calls"),
54
+ "langchain": (
55
+ "langchain_code",
56
+ "Python code using LangChain framework for LLM integration",
57
+ ),
58
+ "stream": ("stream_code", "Python code with streaming response handling"),
59
+ "node": ("node_code", "Node.js code using Axios for API calls"),
60
+ "curl": ("curl_code", "cURL command for direct API access via terminal"),
61
+ }
62
+
63
+ code_key, description = code_map[client]
64
+ if code_key in response and response[code_key]:
65
+ return f"{description}\n{response[code_key]}"
66
+
67
+ return "No code snippet available for the specified language"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: truefoundry
3
- Version: 0.5.3rc3
3
+ Version: 0.5.3rc4
4
4
  Summary: Truefoundry CLI
5
5
  Author: Abhishek Choudhary
6
6
  Author-email: abhishek@truefoundry.com
@@ -33,7 +33,7 @@ truefoundry/cli/display_util.py,sha256=vypx4FQImmDwl2QAj7GpjwlpvG3VFhqoNPvCkBzGq
33
33
  truefoundry/cli/util.py,sha256=yA8sie7TBTOu-5QFf2zEFWYEKYcBCaV6o1gtctj1dtI,3390
34
34
  truefoundry/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
35
  truefoundry/common/auth_service_client.py,sha256=RRiGUqITxeVYwKZLc923zJP-61UAvFtVlMaG2HJBvXc,7940
36
- truefoundry/common/constants.py,sha256=Pxksh1MMjz9WAKV6wCcq1wu9uawzZGMe9RU9FrLOZbQ,2626
36
+ truefoundry/common/constants.py,sha256=VbwTn5nzdUnG8u50_dnq_zWwcLf5PXFinhhSogsOAys,2667
37
37
  truefoundry/common/credential_file_manager.py,sha256=1yEk1Zm2xS4G0VDFwKSZ4w0VUrcPWQ1nJnoBaz9xyKA,4251
38
38
  truefoundry/common/credential_provider.py,sha256=Aht7hFLsnyRgMR34dRbzln7dor0WYSeA8ej8ApNmnKM,4148
39
39
  truefoundry/common/entities.py,sha256=8O-EGPk4PKqnyoFMKUTxISCU19rz0KBnfRDJU695DhY,3797
@@ -105,9 +105,10 @@ truefoundry/deploy/v2/lib/models.py,sha256=pSolLMTArDuYpeNsmeeS5DWliloN_iCDfZSpR
105
105
  truefoundry/deploy/v2/lib/patched_models.py,sha256=NTU8J_CwdvEuF9zNXwFyN3suOp_196Wrm75DDy5qcXE,14184
106
106
  truefoundry/deploy/v2/lib/source.py,sha256=VHKuFREiixUP40D3Mrz-TA70spu1M0RbCzl--qwlFaY,9263
107
107
  truefoundry/gateway/__init__.py,sha256=HvAMuk60-fuZcMmdOtozHrUaH_JcbEHxpMSlS9ci4ls,41
108
- truefoundry/gateway/cli/cli.py,sha256=9raS6Nq_CNzagEPpbKICwUZ01zMoqmZINKMB9m_gJRE,908
109
- truefoundry/gateway/lib/entities.py,sha256=1P9YjrMoHbg58M57Pq-HlsT1ISHRyyX4JxK-o4of6cY,695
110
- truefoundry/gateway/lib/models.py,sha256=TXOur51tuYkq4Xil-icNVaVH-7xZbdOUyqS8N9295dg,876
108
+ truefoundry/gateway/cli/cli.py,sha256=SPEHNP210QtK7G97KOOP6t6QBxgCq2YUezgx65QZToM,1715
109
+ truefoundry/gateway/lib/client.py,sha256=6E9gTl_rOCwcrx5fJkUzbZqacJmgXtSXd1mcmDk9bCA,1717
110
+ truefoundry/gateway/lib/entities.py,sha256=DoYS9QAKjiVao-CH9j9LVUPlVFdeHqJ3xC7-pYhmAyM,918
111
+ truefoundry/gateway/lib/models.py,sha256=0JUsLt2oNf0bBea_03ndDmUkZhNqvMmixh8zgxaH2lk,2600
111
112
  truefoundry/logger.py,sha256=u-YCNjg5HBwE70uQcpjIG64Ghos-K2ulTWaxC03BSj4,714
112
113
  truefoundry/ml/__init__.py,sha256=ssUEIs8BixPWxynKoeSh-dkRl6AtLXG0PBGYnUR5Az8,2217
113
114
  truefoundry/ml/artifact/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -373,7 +374,7 @@ truefoundry/workflow/remote_filesystem/tfy_signed_url_client.py,sha256=5mBCIc-ON
373
374
  truefoundry/workflow/remote_filesystem/tfy_signed_url_fs.py,sha256=Hf6Dk6Fu6P7DqsK5ULgraf9DStjgigf-kjaRAMBW-RU,8680
374
375
  truefoundry/workflow/task.py,sha256=ToitYiKcNzFCtOVQwz1W8sRjbR97eVS7vQBdbgUQtKg,1779
375
376
  truefoundry/workflow/workflow.py,sha256=WaTqUjhwfAXDWu4E5ehuwAxrCbDJkoAf1oWmR2E9Qy0,4575
376
- truefoundry-0.5.3rc3.dist-info/METADATA,sha256=zuoxLW-MzlfmWPLCP8J2NF8eydbOKPu_LNhKouhQi_0,2887
377
- truefoundry-0.5.3rc3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
378
- truefoundry-0.5.3rc3.dist-info/entry_points.txt,sha256=TXvUxQkI6zmqJuycPsyxEIMr3oqfDjgrWj0m_9X12x4,95
379
- truefoundry-0.5.3rc3.dist-info/RECORD,,
377
+ truefoundry-0.5.3rc4.dist-info/METADATA,sha256=qPTGfmHQVmxxL_jBbf7CJI6fDI1LkOpkSfeBXSqLRpY,2887
378
+ truefoundry-0.5.3rc4.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
379
+ truefoundry-0.5.3rc4.dist-info/entry_points.txt,sha256=TXvUxQkI6zmqJuycPsyxEIMr3oqfDjgrWj0m_9X12x4,95
380
+ truefoundry-0.5.3rc4.dist-info/RECORD,,