clarifai 11.6.4rc1__py3-none-any.whl → 11.6.4rc2__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.
clarifai/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "11.6.4rc1"
1
+ __version__ = "11.6.4rc2"
clarifai/cli/model.py CHANGED
@@ -139,7 +139,7 @@ def init(
139
139
  MODEL_PATH: Path where to create the model directory structure. If not specified, the current directory is used by default.
140
140
  model_type_id: Type of model to initialize. Options are 'mcp' for MCPModelClass or 'openai' for OpenAIModelClass.
141
141
  github_pat: GitHub Personal Access Token for cloning private repositories.
142
- github_url: GitHub repository URL or "user/repo" format to clone a repository from. If provided, the entire repository contents will be copied to the target directory instead of using default templates.
142
+ github_url: GitHub repository URL or "user/repo" format or the github folder URL to clone a model files from. If provided, the entire contents of repo/folder will be copied to the target directory instead of using default templates.
143
143
  toolkit: Toolkit to use for model initialization. Currently supports 'ollama'.
144
144
  model_name: Model name to configure when using --toolkit. For ollama toolkit, this sets the Ollama model to use (e.g., 'llama3.1', 'mistral', etc.).
145
145
  port: Port to run the Ollama server on. Defaults to 23333.
@@ -133,6 +133,7 @@ def serve(
133
133
  pat=pat,
134
134
  num_parallel_polls=num_threads,
135
135
  )
136
+ logger.info("Runner started successfully and is waiting for work from the API...")
136
137
  runner.start() # start the runner to fetch work from the API.
137
138
 
138
139
 
@@ -44,62 +44,66 @@ def generate_client_script(
44
44
  model_id,
45
45
  )
46
46
 
47
- _CLIENT_TEMPLATE = """
47
+ _CLIENT_TEMPLATE = f"""
48
48
  import asyncio
49
49
  import os
50
+
50
51
  from fastmcp import Client
51
52
  from fastmcp.client.transports import StreamableHttpTransport
52
53
 
53
- transport = StreamableHttpTransport(url="%s",
54
- headers={"Authorization": "Bearer " + os.environ["CLARIFAI_PAT"]})
54
+ transport = StreamableHttpTransport(
55
+ url="{mcp_url}",
56
+ headers={{"Authorization": "Bearer " + os.environ["CLARIFAI_PAT"]}},
57
+ )
55
58
 
56
59
  async def main():
57
- async with Client(transport) as client:
58
- tools = await client.list_tools()
59
- print(f"Available tools: {tools}")
60
- # TODO: update the dictionary of arguments passed to call_tool to make sense for your MCP.
61
- result = await client.call_tool(tools[0].name, {"a": 5, "b": 3})
62
- print(f"Result: {result[0].text}")
60
+ async with Client(transport) as client:
61
+ tools = await client.list_tools()
62
+ print(f"Available tools: {{tools}}")
63
+ # TODO: update the dictionary of arguments passed to call_tool to make sense for your MCP.
64
+ result = await client.call_tool(tools[0].name, {{"a": 5, "b": 3}})
65
+ print(f"Result: {{result[0].text}}")
63
66
 
64
67
  if __name__ == "__main__":
65
- asyncio.run(main())
68
+ asyncio.run(main())
66
69
  """
67
- return _CLIENT_TEMPLATE % mcp_url
70
+ return _CLIENT_TEMPLATE
68
71
 
69
72
  if has_signature_method(OPENAI_TRANSPORT_NAME, method_signatures):
70
73
  openai_api_base = url_helper.openai_api_url()
71
74
  model_ui_url = url_helper.clarifai_url(user_id, app_id, "models", model_id)
72
- _CLIENT_TEMPLATE = """
75
+ _CLIENT_TEMPLATE = f"""
73
76
  import os
77
+
74
78
  from openai import OpenAI
75
79
 
76
80
  client = OpenAI(
77
- base_url="%s",
81
+ base_url="{openai_api_base}",
78
82
  api_key=os.environ['CLARIFAI_PAT'],
79
83
  )
84
+
80
85
  response = client.chat.completions.create(
81
- model="%s",
86
+ model="{model_ui_url}",
82
87
  messages=[
83
- {"role": "system", "content": "Talk like a pirate."},
84
- {
88
+ {{"role": "system", "content": "Talk like a pirate."}},
89
+ {{
85
90
  "role": "user",
86
91
  "content": "How do I check if a Python object is an instance of a class?",
87
- },
92
+ }},
88
93
  ],
89
94
  temperature=0.7,
90
- stream=False, # stream=True also works, just iterator over the response
95
+ stream=False, # stream=True also works, just iterator over the response
91
96
  )
92
97
  print(response)
93
98
  """
94
- return _CLIENT_TEMPLATE % (openai_api_base, model_ui_url)
95
-
96
- _CLIENT_TEMPLATE = """\
97
- import os
98
-
99
- from clarifai.client import Model
100
- from clarifai.runners.utils import data_types
101
- {model_section}
102
- """
99
+ return _CLIENT_TEMPLATE
100
+ # Generate client template
101
+ _CLIENT_TEMPLATE = (
102
+ "import os\n\n"
103
+ "from clarifai.client import Model\n"
104
+ "from clarifai.runners.utils import data_types\n\n"
105
+ "{model_section}\n"
106
+ )
103
107
  if deployment_id and (compute_cluster_id or nodepool_id):
104
108
  raise ValueError(
105
109
  "You can only specify one of deployment_id or compute_cluster_id and nodepool_id."
@@ -108,26 +112,26 @@ from clarifai.runners.utils import data_types
108
112
  deployment_id = None
109
113
  else:
110
114
  deployment_id = (
111
- "os.environ['CLARIFAI_DEPLOYMENT_ID']" if not deployment_id else repr(deployment_id)
115
+ 'os.environ["CLARIFAI_DEPLOYMENT_ID"]' if not deployment_id else repr(deployment_id)
112
116
  )
113
117
 
114
118
  deployment_line = (
115
- f'deployment_id = {deployment_id}, # Only needed for dedicated deployed models'
119
+ f'deployment_id={deployment_id}, # Only needed for dedicated deployed models'
116
120
  if deployment_id
117
121
  else ""
118
122
  )
119
123
  compute_cluster_line = (
120
- f'compute_cluster_id = "{compute_cluster_id}",' if compute_cluster_id else ""
124
+ f'compute_cluster_id="{compute_cluster_id}",' if compute_cluster_id else ""
121
125
  )
122
126
  nodepool_line = (
123
- f'nodepool_id = "{nodepool_id}", # Only needed for dedicated nodepool'
127
+ f'nodepool_id="{nodepool_id}", # Only needed for dedicated nodepool'
124
128
  if nodepool_id
125
129
  else ""
126
130
  )
127
131
 
128
132
  base_url_str = ""
129
133
  if base_url is not None:
130
- base_url_str = f"base_url='{base_url}',"
134
+ base_url_str = f'base_url="{base_url}",'
131
135
 
132
136
  # Join all non-empty lines
133
137
  optional_lines = "\n ".join(
@@ -138,19 +142,17 @@ from clarifai.runners.utils import data_types
138
142
 
139
143
  if use_ctx:
140
144
  model_section = """
141
- model = Model.from_current_context()"""
145
+ model = Model.from_current_context()
146
+ """
142
147
  else:
143
148
  model_ui_url = url_helper.clarifai_url(user_id, app_id, "models", model_id)
144
- model_section = f"""
145
- model = Model("{model_ui_url}",
146
- {optional_lines}
147
- )
148
- """
149
+ if optional_lines:
150
+ model_args = f'"{model_ui_url}",\n {optional_lines}'
151
+ else:
152
+ model_args = f'"{model_ui_url}"'
153
+ model_section = f"model = Model(\n {model_args}\n)"
149
154
 
150
- # Generate client template
151
- client_template = _CLIENT_TEMPLATE.format(
152
- model_section=model_section,
153
- )
155
+ client_template = _CLIENT_TEMPLATE.format(model_section=model_section.strip("\n"))
154
156
 
155
157
  # Generate method signatures
156
158
  method_signatures_str = []
@@ -158,8 +160,9 @@ model = Model("{model_ui_url}",
158
160
  if method_signature is None:
159
161
  continue
160
162
  method_name = method_signature.name
161
- client_script_str = f'response = model.{method_name}('
163
+ client_script_str = f"response = model.{method_name}("
162
164
  annotations = _get_annotations_source(method_signature)
165
+ param_lines = []
163
166
  for idx, (param_name, (param_type, default_value, required)) in enumerate(
164
167
  annotations.items()
165
168
  ):
@@ -172,8 +175,11 @@ model = Model("{model_ui_url}",
172
175
  if param_type == "str" and default_value is not None:
173
176
  default_value = json.dumps(default_value)
174
177
  if default_value is not None:
175
- client_script_str += f"{param_name}={default_value}, "
176
- client_script_str = client_script_str.rstrip(", ") + ")"
178
+ param_lines.append(f" {param_name}={default_value},")
179
+ if param_lines:
180
+ client_script_str += "\n" + "\n".join(param_lines) + "\n)"
181
+ else:
182
+ client_script_str += ")"
177
183
  if method_signature.method_type == resources_pb2.RunnerMethodType.UNARY_UNARY:
178
184
  client_script_str += "\nprint(response)"
179
185
  elif method_signature.method_type == resources_pb2.RunnerMethodType.UNARY_STREAMING:
@@ -191,7 +197,7 @@ model = Model("{model_ui_url}",
191
197
  )
192
198
  script_lines.append("# Example usage:")
193
199
  script_lines.append(client_template)
194
- script_lines.append("# Example model prediction from different model methods: \n")
200
+ script_lines.append("# Example model prediction from different model methods:\n")
195
201
  script_lines.append(method_signatures_str)
196
202
  script_lines.append("")
197
203
  script = "\n".join(script_lines)
clarifai/utils/misc.py CHANGED
@@ -242,7 +242,8 @@ class GitHubDownloader:
242
242
  return owner, repo, branch, folder_path
243
243
 
244
244
  except Exception as e:
245
- raise ValueError(f"Failed to parse GitHub URL: {e}")
245
+ logger.error(f"Failed to parse GitHub URL: {e}")
246
+ sys.exit(1)
246
247
 
247
248
  def get_folder_contents(self, owner: str, repo: str, path: str, branch: str = 'main') -> list:
248
249
  api_url = f"https://api.github.com/repos/{owner}/{repo}/contents/{path}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clarifai
3
- Version: 11.6.4rc1
3
+ Version: 11.6.4rc2
4
4
  Home-page: https://github.com/Clarifai/clarifai-python
5
5
  Author: Clarifai
6
6
  Author-email: support@clarifai.com
@@ -1,4 +1,4 @@
1
- clarifai/__init__.py,sha256=IhAUqR6EdKamjSDzcP15aKGyFnqcPJqpjn88f3ub6UM,26
1
+ clarifai/__init__.py,sha256=ar7JD6Boa57AqjHY4xavUrsMXIAHf60c96qtzrGWFPg,26
2
2
  clarifai/cli.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  clarifai/errors.py,sha256=GXa6D4v_L404J83jnRNFPH7s-1V9lk7w6Ws99f1g-AY,2772
4
4
  clarifai/versions.py,sha256=ecSuEB_nOL2XSoYHDw2n23XUbm_KPOGjudMXmQrGdS8,224
@@ -14,7 +14,7 @@ clarifai/cli/__main__.py,sha256=7nPbLW7Jr2shkgMPvnxpn4xYGMvIcnqluJ69t9w4H_k,74
14
14
  clarifai/cli/base.py,sha256=yFfC7POW9BMcUoBn134n9RC0BWkhP_BMDYsVwWeA9SE,8801
15
15
  clarifai/cli/compute_cluster.py,sha256=8Xss0Obrp6l1XuxJe0luOqU_pf8vXGDRi6jyIe8qR6k,2282
16
16
  clarifai/cli/deployment.py,sha256=9C4I6_kyMxRkWl6h681wc79-3mAtDHtTUaxRv05OZMs,4262
17
- clarifai/cli/model.py,sha256=nyGxg8DvnfOpmN-mvH13KT8dgmxL_F_ChV761sHRaV8,42155
17
+ clarifai/cli/model.py,sha256=qg7UtVSJcNS20QqF9rFaDNwPvMWLFSO0TPlXyN322mI,42185
18
18
  clarifai/cli/model_templates.py,sha256=_ZonIBnY9KKSJY31KZbUys_uN_k_Txu7Dip12KWfmSU,9633
19
19
  clarifai/cli/nodepool.py,sha256=H6OIdUW_EiyDUwZogzEDoYmVwEjLMsgoDlPyE7gjIuU,4245
20
20
  clarifai/cli/pipeline.py,sha256=smWPCK9kLCqnjTCb3w8BAeiAcowY20Bdxfk-OCzCi0I,10601
@@ -192,7 +192,7 @@ clarifai/rag/__init__.py,sha256=wu3PzAzo7uqgrEzuaC9lY_3gj1HFiR3GU3elZIKTT5g,40
192
192
  clarifai/rag/rag.py,sha256=EG3GoFrHFCmA70Tz49_0Jo1-3WIaHSgWGHecPeErcdc,14170
193
193
  clarifai/rag/utils.py,sha256=_gVZdABuMnraCKViLruV75x0F3IpgFXN6amYSGE5_xc,4462
194
194
  clarifai/runners/__init__.py,sha256=wXLaSljH7qLeJCrZdKEnlQh2tNqTQAIZKWOu2rZ6wGs,279
195
- clarifai/runners/server.py,sha256=ic1qI-ZhlePCpJDP94hWIf8X-_D1fiEp2CdtaMvFFMk,4780
195
+ clarifai/runners/server.py,sha256=6leCkPkbxtfQyrSNUK_MlwArBcR3K1q1gYqFFsl9bkQ,4871
196
196
  clarifai/runners/__pycache__/__init__.cpython-311.pyc,sha256=Z5FOMAOomAbAQ_OUT-YYc4PVkn89DF5aLAOCWMtm2CU,533
197
197
  clarifai/runners/__pycache__/__init__.cpython-39.pyc,sha256=ar7ZlbFKLRjwEDdldGPsPF4AH8o_vGUQCXfFgq7WvtY,443
198
198
  clarifai/runners/dockerfile_template/Dockerfile.template,sha256=nEnIMqzhAXDbd0Ht7QQm0U7AVPIHWQD6kYnFZ0TKJUM,2428
@@ -222,7 +222,7 @@ clarifai/runners/pipeline_steps/pipeline_step_builder.py,sha256=X2xWg4QM4kX3cr8J
222
222
  clarifai/runners/pipelines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
223
223
  clarifai/runners/pipelines/pipeline_builder.py,sha256=z_bCwjwQPFa_1AYkorhh5r6t6r5hC5K2D8Z1LTEzIpg,12801
224
224
  clarifai/runners/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
225
- clarifai/runners/utils/code_script.py,sha256=toHoQQ2UGGmAxhFrbHo8217eJpUbAa-8RyPzTzfqXvk,14031
225
+ clarifai/runners/utils/code_script.py,sha256=dzvHKgD-3B25KtQVCnCLz9rGzvgrxi4w7DoVkd6AxaI,14312
226
226
  clarifai/runners/utils/const.py,sha256=MK7lTzzJKbOiyiUtG_jlJXfz_xNKMn5LjkQ9vjbttXE,1538
227
227
  clarifai/runners/utils/data_handler.py,sha256=sxy9zlAgI6ETuxCQhUgEXAn2GCsaW1GxpK6GTaMne0g,6966
228
228
  clarifai/runners/utils/data_types.py,sha256=ag08V9CYV9Rm2W0QkKkG6VwpiqUdW7LAynm4dB1RPR4,13606
@@ -264,7 +264,7 @@ clarifai/utils/cli.py,sha256=1pMzWSFg2eqw74oitKc7O99pgr7hmyAXFHDiEFfACsQ,7332
264
264
  clarifai/utils/config.py,sha256=jMSWYxJfp_D8eoGqz-HTdsngn5bg_1ymjLidYz6rdLA,7073
265
265
  clarifai/utils/constants.py,sha256=gveZo_k_v6itX_ImnCjo8HVVNDqa4Z3m3Mk7El5brHw,2313
266
266
  clarifai/utils/logging.py,sha256=0we53uTqUvzrulC86whu-oeWNxn1JjJL0OQ98Bwf9vo,15198
267
- clarifai/utils/misc.py,sha256=v_1KX0mN3RjitNJJs1ExzDWahFQJV2L2hGZQn18eZXg,20904
267
+ clarifai/utils/misc.py,sha256=_FqRkBO1EC9rBd1C1fsNvoHCy-l6nYb9HIx0StnVf3A,20924
268
268
  clarifai/utils/model_train.py,sha256=0XSAoTkSsrwf4f-W9yw2mkXZtkal7LBLJSoi86CFCn4,9250
269
269
  clarifai/utils/protobuf.py,sha256=VMhnNsPuWQ16VarKm8BOr5zccXMe26UlrxdJxIzEZNM,6220
270
270
  clarifai/utils/__pycache__/__init__.cpython-311.pyc,sha256=flXj0n7hHiXQ36N-q7345qS1XLIpFvt3KWvYMaI_rrU,193
@@ -293,9 +293,9 @@ clarifai/workflows/__pycache__/__init__.cpython-311.pyc,sha256=ZLPuiL5wZcQj_tGzX
293
293
  clarifai/workflows/__pycache__/export.cpython-311.pyc,sha256=wllNwGH9vZV13mr8nP50RIotZMc-ihdqZrPlmIvole0,3694
294
294
  clarifai/workflows/__pycache__/utils.cpython-311.pyc,sha256=9OjCazsf84YXB-yel33SMzo2dN5SzfTJE1Qu5ehP5Vo,3357
295
295
  clarifai/workflows/__pycache__/validate.cpython-311.pyc,sha256=7jRomDKdaSjADi0uIrUyEQyxUBvbdZKPZat_UtzDkoo,3529
296
- clarifai-11.6.4rc1.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
297
- clarifai-11.6.4rc1.dist-info/METADATA,sha256=LnWEJ_OsqSw1oqMCKcVG4lz5nETQusbVbutu5nEx3dc,22740
298
- clarifai-11.6.4rc1.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
299
- clarifai-11.6.4rc1.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
300
- clarifai-11.6.4rc1.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
301
- clarifai-11.6.4rc1.dist-info/RECORD,,
296
+ clarifai-11.6.4rc2.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
297
+ clarifai-11.6.4rc2.dist-info/METADATA,sha256=-X9GLWKAYI8mlP2SDCkcdvp8K5C0-Fn7c_vHhBHqoZw,22740
298
+ clarifai-11.6.4rc2.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
299
+ clarifai-11.6.4rc2.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
300
+ clarifai-11.6.4rc2.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
301
+ clarifai-11.6.4rc2.dist-info/RECORD,,