clarifai 11.6.4rc2__py3-none-any.whl → 11.6.6__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.
Files changed (200) hide show
  1. clarifai/__init__.py +1 -1
  2. clarifai/cli/README.md +39 -0
  3. clarifai/cli/base.py +119 -118
  4. clarifai/cli/model.py +116 -86
  5. clarifai/client/app.py +1 -1
  6. clarifai/client/auth/helper.py +7 -2
  7. clarifai/client/base.py +35 -8
  8. clarifai/client/compute_cluster.py +1 -1
  9. clarifai/client/model.py +3 -1
  10. clarifai/client/model_client.py +20 -1
  11. clarifai/client/nodepool.py +4 -2
  12. clarifai/client/user.py +4 -2
  13. clarifai/runners/models/model_runner.py +55 -0
  14. clarifai/runners/server.py +23 -1
  15. clarifai/runners/utils/model_utils.py +4 -4
  16. clarifai/runners/utils/url_fetcher.py +51 -12
  17. clarifai/utils/cli.py +148 -13
  18. clarifai/utils/constants.py +5 -0
  19. clarifai/utils/misc.py +47 -0
  20. {clarifai-11.6.4rc2.dist-info → clarifai-11.6.6.dist-info}/METADATA +2 -2
  21. clarifai-11.6.6.dist-info/RECORD +127 -0
  22. {clarifai-11.6.4rc2.dist-info → clarifai-11.6.6.dist-info}/WHEEL +1 -1
  23. clarifai/__pycache__/__init__.cpython-311.pyc +0 -0
  24. clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
  25. clarifai/__pycache__/errors.cpython-311.pyc +0 -0
  26. clarifai/__pycache__/errors.cpython-39.pyc +0 -0
  27. clarifai/__pycache__/versions.cpython-311.pyc +0 -0
  28. clarifai/__pycache__/versions.cpython-39.pyc +0 -0
  29. clarifai/cli/__pycache__/__init__.cpython-39.pyc +0 -0
  30. clarifai/cli/__pycache__/base.cpython-39.pyc +0 -0
  31. clarifai/cli/__pycache__/compute_cluster.cpython-39.pyc +0 -0
  32. clarifai/cli/__pycache__/deployment.cpython-39.pyc +0 -0
  33. clarifai/cli/__pycache__/model.cpython-39.pyc +0 -0
  34. clarifai/cli/__pycache__/nodepool.cpython-39.pyc +0 -0
  35. clarifai/cli/model_templates.py +0 -243
  36. clarifai/cli/pipeline_step_templates.py +0 -64
  37. clarifai/client/__pycache__/__init__.cpython-311.pyc +0 -0
  38. clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
  39. clarifai/client/__pycache__/app.cpython-311.pyc +0 -0
  40. clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
  41. clarifai/client/__pycache__/base.cpython-311.pyc +0 -0
  42. clarifai/client/__pycache__/base.cpython-39.pyc +0 -0
  43. clarifai/client/__pycache__/compute_cluster.cpython-311.pyc +0 -0
  44. clarifai/client/__pycache__/dataset.cpython-311.pyc +0 -0
  45. clarifai/client/__pycache__/dataset.cpython-39.pyc +0 -0
  46. clarifai/client/__pycache__/deployment.cpython-311.pyc +0 -0
  47. clarifai/client/__pycache__/deployment.cpython-39.pyc +0 -0
  48. clarifai/client/__pycache__/input.cpython-311.pyc +0 -0
  49. clarifai/client/__pycache__/input.cpython-39.pyc +0 -0
  50. clarifai/client/__pycache__/lister.cpython-311.pyc +0 -0
  51. clarifai/client/__pycache__/lister.cpython-39.pyc +0 -0
  52. clarifai/client/__pycache__/model.cpython-311.pyc +0 -0
  53. clarifai/client/__pycache__/model.cpython-39.pyc +0 -0
  54. clarifai/client/__pycache__/model_client.cpython-311.pyc +0 -0
  55. clarifai/client/__pycache__/model_client.cpython-39.pyc +0 -0
  56. clarifai/client/__pycache__/module.cpython-311.pyc +0 -0
  57. clarifai/client/__pycache__/nodepool.cpython-311.pyc +0 -0
  58. clarifai/client/__pycache__/runner.cpython-311.pyc +0 -0
  59. clarifai/client/__pycache__/search.cpython-311.pyc +0 -0
  60. clarifai/client/__pycache__/user.cpython-311.pyc +0 -0
  61. clarifai/client/__pycache__/workflow.cpython-311.pyc +0 -0
  62. clarifai/client/auth/__pycache__/__init__.cpython-311.pyc +0 -0
  63. clarifai/client/auth/__pycache__/__init__.cpython-39.pyc +0 -0
  64. clarifai/client/auth/__pycache__/helper.cpython-311.pyc +0 -0
  65. clarifai/client/auth/__pycache__/helper.cpython-39.pyc +0 -0
  66. clarifai/client/auth/__pycache__/register.cpython-311.pyc +0 -0
  67. clarifai/client/auth/__pycache__/register.cpython-39.pyc +0 -0
  68. clarifai/client/auth/__pycache__/stub.cpython-311.pyc +0 -0
  69. clarifai/client/auth/__pycache__/stub.cpython-39.pyc +0 -0
  70. clarifai/constants/__pycache__/base.cpython-311.pyc +0 -0
  71. clarifai/constants/__pycache__/base.cpython-39.pyc +0 -0
  72. clarifai/constants/__pycache__/dataset.cpython-311.pyc +0 -0
  73. clarifai/constants/__pycache__/dataset.cpython-39.pyc +0 -0
  74. clarifai/constants/__pycache__/input.cpython-311.pyc +0 -0
  75. clarifai/constants/__pycache__/input.cpython-39.pyc +0 -0
  76. clarifai/constants/__pycache__/model.cpython-311.pyc +0 -0
  77. clarifai/constants/__pycache__/model.cpython-39.pyc +0 -0
  78. clarifai/constants/__pycache__/search.cpython-311.pyc +0 -0
  79. clarifai/constants/__pycache__/workflow.cpython-311.pyc +0 -0
  80. clarifai/datasets/__pycache__/__init__.cpython-311.pyc +0 -0
  81. clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
  82. clarifai/datasets/export/__pycache__/__init__.cpython-311.pyc +0 -0
  83. clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
  84. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-311.pyc +0 -0
  85. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-39.pyc +0 -0
  86. clarifai/datasets/upload/__pycache__/__init__.cpython-311.pyc +0 -0
  87. clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
  88. clarifai/datasets/upload/__pycache__/base.cpython-311.pyc +0 -0
  89. clarifai/datasets/upload/__pycache__/base.cpython-39.pyc +0 -0
  90. clarifai/datasets/upload/__pycache__/features.cpython-311.pyc +0 -0
  91. clarifai/datasets/upload/__pycache__/features.cpython-39.pyc +0 -0
  92. clarifai/datasets/upload/__pycache__/image.cpython-311.pyc +0 -0
  93. clarifai/datasets/upload/__pycache__/image.cpython-39.pyc +0 -0
  94. clarifai/datasets/upload/__pycache__/multimodal.cpython-311.pyc +0 -0
  95. clarifai/datasets/upload/__pycache__/multimodal.cpython-39.pyc +0 -0
  96. clarifai/datasets/upload/__pycache__/text.cpython-311.pyc +0 -0
  97. clarifai/datasets/upload/__pycache__/text.cpython-39.pyc +0 -0
  98. clarifai/datasets/upload/__pycache__/utils.cpython-311.pyc +0 -0
  99. clarifai/datasets/upload/__pycache__/utils.cpython-39.pyc +0 -0
  100. clarifai/models/model_serving/README.md +0 -158
  101. clarifai/models/model_serving/__init__.py +0 -14
  102. clarifai/models/model_serving/cli/__init__.py +0 -12
  103. clarifai/models/model_serving/cli/_utils.py +0 -53
  104. clarifai/models/model_serving/cli/base.py +0 -14
  105. clarifai/models/model_serving/cli/build.py +0 -79
  106. clarifai/models/model_serving/cli/clarifai_clis.py +0 -33
  107. clarifai/models/model_serving/cli/create.py +0 -171
  108. clarifai/models/model_serving/cli/example_cli.py +0 -34
  109. clarifai/models/model_serving/cli/login.py +0 -26
  110. clarifai/models/model_serving/cli/upload.py +0 -179
  111. clarifai/models/model_serving/constants.py +0 -21
  112. clarifai/models/model_serving/docs/cli.md +0 -161
  113. clarifai/models/model_serving/docs/concepts.md +0 -229
  114. clarifai/models/model_serving/docs/dependencies.md +0 -11
  115. clarifai/models/model_serving/docs/inference_parameters.md +0 -139
  116. clarifai/models/model_serving/docs/model_types.md +0 -19
  117. clarifai/models/model_serving/model_config/__init__.py +0 -16
  118. clarifai/models/model_serving/model_config/base.py +0 -369
  119. clarifai/models/model_serving/model_config/config.py +0 -312
  120. clarifai/models/model_serving/model_config/inference_parameter.py +0 -129
  121. clarifai/models/model_serving/model_config/model_types_config/multimodal-embedder.yaml +0 -25
  122. clarifai/models/model_serving/model_config/model_types_config/text-classifier.yaml +0 -19
  123. clarifai/models/model_serving/model_config/model_types_config/text-embedder.yaml +0 -20
  124. clarifai/models/model_serving/model_config/model_types_config/text-to-image.yaml +0 -19
  125. clarifai/models/model_serving/model_config/model_types_config/text-to-text.yaml +0 -19
  126. clarifai/models/model_serving/model_config/model_types_config/visual-classifier.yaml +0 -22
  127. clarifai/models/model_serving/model_config/model_types_config/visual-detector.yaml +0 -32
  128. clarifai/models/model_serving/model_config/model_types_config/visual-embedder.yaml +0 -19
  129. clarifai/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +0 -19
  130. clarifai/models/model_serving/model_config/output.py +0 -133
  131. clarifai/models/model_serving/model_config/triton/__init__.py +0 -14
  132. clarifai/models/model_serving/model_config/triton/serializer.py +0 -136
  133. clarifai/models/model_serving/model_config/triton/triton_config.py +0 -182
  134. clarifai/models/model_serving/model_config/triton/wrappers.py +0 -281
  135. clarifai/models/model_serving/repo_build/__init__.py +0 -14
  136. clarifai/models/model_serving/repo_build/build.py +0 -198
  137. clarifai/models/model_serving/repo_build/static_files/_requirements.txt +0 -2
  138. clarifai/models/model_serving/repo_build/static_files/base_test.py +0 -169
  139. clarifai/models/model_serving/repo_build/static_files/inference.py +0 -26
  140. clarifai/models/model_serving/repo_build/static_files/sample_clarifai_config.yaml +0 -25
  141. clarifai/models/model_serving/repo_build/static_files/test.py +0 -40
  142. clarifai/models/model_serving/repo_build/static_files/triton/model.py +0 -75
  143. clarifai/models/model_serving/utils.py +0 -23
  144. clarifai/runners/__pycache__/__init__.cpython-311.pyc +0 -0
  145. clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
  146. clarifai/runners/models/__pycache__/__init__.cpython-311.pyc +0 -0
  147. clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
  148. clarifai/runners/models/__pycache__/mcp_class.cpython-311.pyc +0 -0
  149. clarifai/runners/models/__pycache__/model_builder.cpython-311.pyc +0 -0
  150. clarifai/runners/models/__pycache__/model_builder.cpython-39.pyc +0 -0
  151. clarifai/runners/models/__pycache__/model_class.cpython-311.pyc +0 -0
  152. clarifai/runners/models/__pycache__/model_runner.cpython-311.pyc +0 -0
  153. clarifai/runners/models/__pycache__/openai_class.cpython-311.pyc +0 -0
  154. clarifai/runners/models/base_typed_model.py +0 -238
  155. clarifai/runners/models/model_upload.py +0 -607
  156. clarifai/runners/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  157. clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  158. clarifai/runners/utils/__pycache__/code_script.cpython-311.pyc +0 -0
  159. clarifai/runners/utils/__pycache__/code_script.cpython-39.pyc +0 -0
  160. clarifai/runners/utils/__pycache__/const.cpython-311.pyc +0 -0
  161. clarifai/runners/utils/__pycache__/data_utils.cpython-311.pyc +0 -0
  162. clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
  163. clarifai/runners/utils/__pycache__/loader.cpython-311.pyc +0 -0
  164. clarifai/runners/utils/__pycache__/method_signatures.cpython-311.pyc +0 -0
  165. clarifai/runners/utils/__pycache__/model_utils.cpython-311.pyc +0 -0
  166. clarifai/runners/utils/__pycache__/openai_convertor.cpython-311.pyc +0 -0
  167. clarifai/runners/utils/__pycache__/serializers.cpython-311.pyc +0 -0
  168. clarifai/runners/utils/__pycache__/url_fetcher.cpython-311.pyc +0 -0
  169. clarifai/runners/utils/data_handler.py +0 -231
  170. clarifai/runners/utils/data_types/__pycache__/__init__.cpython-311.pyc +0 -0
  171. clarifai/runners/utils/data_types/__pycache__/__init__.cpython-39.pyc +0 -0
  172. clarifai/runners/utils/data_types/__pycache__/data_types.cpython-311.pyc +0 -0
  173. clarifai/runners/utils/data_types/__pycache__/data_types.cpython-39.pyc +0 -0
  174. clarifai/runners/utils/data_types.py +0 -471
  175. clarifai/runners/utils/temp.py +0 -59
  176. clarifai/schema/__pycache__/search.cpython-311.pyc +0 -0
  177. clarifai/urls/__pycache__/helper.cpython-311.pyc +0 -0
  178. clarifai/urls/__pycache__/helper.cpython-39.pyc +0 -0
  179. clarifai/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  180. clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  181. clarifai/utils/__pycache__/cli.cpython-39.pyc +0 -0
  182. clarifai/utils/__pycache__/config.cpython-311.pyc +0 -0
  183. clarifai/utils/__pycache__/config.cpython-39.pyc +0 -0
  184. clarifai/utils/__pycache__/constants.cpython-311.pyc +0 -0
  185. clarifai/utils/__pycache__/constants.cpython-39.pyc +0 -0
  186. clarifai/utils/__pycache__/logging.cpython-311.pyc +0 -0
  187. clarifai/utils/__pycache__/logging.cpython-39.pyc +0 -0
  188. clarifai/utils/__pycache__/misc.cpython-311.pyc +0 -0
  189. clarifai/utils/__pycache__/misc.cpython-39.pyc +0 -0
  190. clarifai/utils/__pycache__/model_train.cpython-311.pyc +0 -0
  191. clarifai/utils/__pycache__/protobuf.cpython-311.pyc +0 -0
  192. clarifai/utils/__pycache__/protobuf.cpython-39.pyc +0 -0
  193. clarifai/workflows/__pycache__/__init__.cpython-311.pyc +0 -0
  194. clarifai/workflows/__pycache__/export.cpython-311.pyc +0 -0
  195. clarifai/workflows/__pycache__/utils.cpython-311.pyc +0 -0
  196. clarifai/workflows/__pycache__/validate.cpython-311.pyc +0 -0
  197. clarifai-11.6.4rc2.dist-info/RECORD +0 -301
  198. {clarifai-11.6.4rc2.dist-info → clarifai-11.6.6.dist-info}/entry_points.txt +0 -0
  199. {clarifai-11.6.4rc2.dist-info → clarifai-11.6.6.dist-info}/licenses/LICENSE +0 -0
  200. {clarifai-11.6.4rc2.dist-info → clarifai-11.6.6.dist-info}/top_level.txt +0 -0
clarifai/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "11.6.4rc2"
1
+ __version__ = "11.6.6"
clarifai/cli/README.md CHANGED
@@ -8,6 +8,45 @@ Clarifai offers a user-friendly interface for deploying your local model into pr
8
8
  * Easy implementation and testing in Python
9
9
  * No need for MLops expertise.
10
10
 
11
+ ## Context Management
12
+
13
+ Manage CLI contexts for authentication and environment configuration:
14
+ ### List all contexts
15
+ ```bash
16
+ clarifai config get-contexts
17
+ ```
18
+
19
+ ### Switch context
20
+ ```bash
21
+ clarifai config use-context production
22
+ ```
23
+ ### Show current context
24
+ ```bash
25
+ clarifai config current-context
26
+ ```
27
+
28
+ ### Create new context
29
+ ```bash
30
+ clarifai config create-context staging --user-id myuser --pat 678***
31
+ ```
32
+ ### View entire configuration
33
+ ```bash
34
+ clarifai config view
35
+ ```
36
+ ### Delete a context
37
+ ```bash
38
+ clarifai config delete-context old-context
39
+ ```
40
+ ### Edit configuration file
41
+ ```bash
42
+ clarifai config edit
43
+ ```
44
+
45
+ ### Print environment variables for the active context
46
+ ```bash
47
+ clarifai context env
48
+ ```
49
+
11
50
  ## Compute Orchestration
12
51
 
13
52
  Quick example for deploying a `visual-classifier` model
clarifai/cli/base.py CHANGED
@@ -1,6 +1,6 @@
1
+ import getpass
1
2
  import json
2
3
  import os
3
- import shutil
4
4
  import sys
5
5
 
6
6
  import click
@@ -13,7 +13,6 @@ from clarifai.utils.constants import DEFAULT_BASE, DEFAULT_CONFIG, DEFAULT_UI
13
13
  from clarifai.utils.logging import logger
14
14
 
15
15
 
16
- # @click.group(cls=CustomMultiGroup)
17
16
  @click.group(cls=AliasedGroup)
18
17
  @click.version_option(version=__version__)
19
18
  @click.option('--config', default=DEFAULT_CONFIG)
@@ -54,42 +53,82 @@ def shell_completion(shell):
54
53
  os.system(f"_CLARIFAI_COMPLETE={shell}_source clarifai")
55
54
 
56
55
 
57
- @cli.group(
58
- ['cfg'],
59
- cls=AliasedGroup,
60
- context_settings={'max_content_width': shutil.get_terminal_size().columns - 10},
61
- )
56
+ @cli.group(cls=AliasedGroup)
62
57
  def config():
63
- """Manage CLI configuration"""
58
+ """
59
+ Manage multiple configuration profiles (contexts).
64
60
 
61
+ Authentication Precedence:\n
62
+ 1. Environment variables (e.g., `CLARIFAI_PAT`) are used first if set.
63
+ 2. The settings from the active context are used if no environment variables are provided.\n
64
+ """
65
65
 
66
- @config.command(['e'])
66
+
67
+ @cli.command()
68
+ @click.argument('api_url', default=DEFAULT_BASE)
69
+ @click.option('--user_id', required=False, help='User ID')
67
70
  @click.pass_context
68
- def edit(ctx):
69
- """Edit the configuration file"""
70
- os.system(f'{os.environ.get("EDITOR", "vi")} {ctx.obj.filename}')
71
+ def login(ctx, api_url, user_id):
72
+ """Login command to set PAT and other configurations."""
73
+ from clarifai.utils.cli import validate_context_auth
71
74
 
75
+ click.echo('> To authenticate, you\'ll need a Personal Access Token (PAT).')
76
+ click.echo(
77
+ '> You can create one from your account settings: https://clarifai.com/settings/security\n'
78
+ )
72
79
 
73
- @config.command(['current'])
74
- @click.option('-o', '--output-format', default='name', type=click.Choice(['name', 'json', 'yaml']))
75
- @click.pass_context
76
- def current_context(ctx, output_format):
77
- """Get the current context"""
78
- if output_format == 'name':
79
- print(ctx.obj.current_context)
80
- elif output_format == 'json':
81
- print(json.dumps(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
82
- else:
83
- print(yaml.safe_dump(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
80
+ # Securely input PAT
81
+ pat = getpass.getpass('Enter your Personal Access Token: ')
82
+
83
+ # Input user_id if not supplied
84
+ if not user_id:
85
+ user_id = click.prompt('Enter your Clarifai user ID', type=str)
86
+
87
+ # Progress indicator
88
+ click.echo('\n> Verifying token...')
89
+ validate_context_auth(pat, user_id, api_url)
90
+
91
+ # Context naming
92
+ default_context_name = 'default'
93
+ click.echo('\n> Let\'s save these credentials to a new context.')
94
+ click.echo('> You can have multiple contexts to easily switch between accounts or projects.\n')
95
+ context_name = click.prompt("Enter a name for this context", default=default_context_name)
96
+
97
+ # Save context
98
+ context = Context(
99
+ context_name,
100
+ CLARIFAI_API_BASE=api_url,
101
+ CLARIFAI_USER_ID=user_id,
102
+ CLARIFAI_PAT=pat,
103
+ )
104
+
105
+ ctx.obj.contexts[context_name] = context
106
+ ctx.obj.current_context = context_name
107
+ ctx.obj.to_yaml()
108
+ click.secho('✅ Success! You are now logged in.', fg='green')
109
+ click.echo(f'Credentials saved to the \'{context_name}\' context.\n')
110
+ click.echo('💡 To switch contexts later, use `clarifai config use-context <name>`.')
111
+
112
+ logger.info(f"Login successful for user '{user_id}' in context '{context_name}'")
113
+
114
+
115
+ def pat_display(pat):
116
+ return pat[:5] + "****"
117
+
118
+
119
+ def input_or_default(prompt, default):
120
+ value = input(prompt)
121
+ return value if value else default
84
122
 
85
123
 
86
- @config.command(['list', 'ls'])
124
+ # Context management commands under config group
125
+ @config.command(aliases=['get-contexts', 'list-contexts'])
87
126
  @click.option(
88
127
  '-o', '--output-format', default='wide', type=click.Choice(['wide', 'name', 'json', 'yaml'])
89
128
  )
90
129
  @click.pass_context
91
130
  def get_contexts(ctx, output_format):
92
- """Get all contexts"""
131
+ """List all available contexts."""
93
132
  if output_format == 'wide':
94
133
  columns = {
95
134
  '': lambda c: '*' if c.name == ctx.obj.current_context else '',
@@ -106,7 +145,6 @@ def get_contexts(ctx, output_format):
106
145
  additional_columns.add(key)
107
146
  for key in sorted(additional_columns):
108
147
  columns[key] = lambda c, k=key: getattr(c, k) if hasattr(c, k) else ""
109
-
110
148
  formatter = TableFormatter(
111
149
  custom_columns=columns,
112
150
  )
@@ -123,101 +161,45 @@ def get_contexts(ctx, output_format):
123
161
  print(yaml.safe_dump(dicts))
124
162
 
125
163
 
126
- @config.command(['use'])
127
- @click.argument('context-name', type=str)
164
+ @config.command(aliases=['use-context'])
165
+ @click.argument('name', type=str)
128
166
  @click.pass_context
129
- def use_context(ctx, context_name):
130
- """Set the current context"""
131
- if context_name not in ctx.obj.contexts:
167
+ def use_context(ctx, name):
168
+ """Set the current context."""
169
+ if name not in ctx.obj.contexts:
132
170
  raise click.UsageError('Context not found')
133
- ctx.obj.current_context = context_name
171
+ ctx.obj.current_context = name
134
172
  ctx.obj.to_yaml()
135
- print(f'Set {context_name} as the current context')
136
-
137
-
138
- @config.command(['cat'])
139
- @click.option('-o', '--output-format', default='yaml', type=click.Choice(['yaml', 'json']))
140
- @click.pass_obj
141
- def dump(ctx_obj, output_format):
142
- """Dump the configuration to stdout"""
143
- if output_format == 'yaml':
144
- yaml.safe_dump(ctx_obj.to_dict(), sys.stdout)
145
- else:
146
- json.dump(ctx_obj.to_dict(), sys.stdout, indent=2)
147
-
148
-
149
- @config.command(['cat'])
150
- @click.pass_obj
151
- def env(ctx_obj):
152
- """Print env vars. Use: eval "$(clarifai config env)" """
153
- ctx_obj.current.print_env_vars()
173
+ print(f'Set {name} as the current context')
154
174
 
155
175
 
156
- @cli.command()
157
- @click.argument('api_url', default=DEFAULT_BASE)
158
- @click.option('--user_id', required=False, help='User ID')
176
+ @config.command(aliases=['current-context'])
177
+ @click.option('-o', '--output-format', default='name', type=click.Choice(['name', 'json', 'yaml']))
159
178
  @click.pass_context
160
- def login(ctx, api_url, user_id):
161
- """Login command to set PAT and other configurations."""
162
- from clarifai.utils.cli import validate_context_auth
163
-
164
- name = input('context name (default: "default"): ')
165
- user_id = user_id if user_id is not None else input('user id: ')
166
- pat = input_or_default(
167
- 'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
168
- 'ENVVAR',
169
- )
170
-
171
- # Validate the Context Credentials
172
- validate_context_auth(pat, user_id, api_url)
173
-
174
- context = Context(
175
- name,
176
- CLARIFAI_API_BASE=api_url,
177
- CLARIFAI_USER_ID=user_id,
178
- CLARIFAI_PAT=pat,
179
- )
180
-
181
- if context.name == '':
182
- context.name = 'default'
183
-
184
- ctx.obj.contexts[context.name] = context
185
- ctx.obj.current_context = context.name
186
-
187
- ctx.obj.to_yaml()
188
- logger.info(
189
- f"Login successful and Configuration saved successfully for context '{context.name}'"
190
- )
191
-
192
-
193
- @cli.group(cls=AliasedGroup)
194
- def context():
195
- """Manage contexts"""
196
-
197
-
198
- def pat_display(pat):
199
- return pat[:5] + "****"
200
-
201
-
202
- def input_or_default(prompt, default):
203
- value = input(prompt)
204
- return value if value else default
179
+ def current_context(ctx, output_format):
180
+ """Show the current context's details."""
181
+ if output_format == 'name':
182
+ print(ctx.obj.current_context)
183
+ elif output_format == 'json':
184
+ print(json.dumps(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
185
+ else:
186
+ print(yaml.safe_dump(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
205
187
 
206
188
 
207
- @context.command()
189
+ @config.command(aliases=['create-context', 'set-context'])
208
190
  @click.argument('name')
209
191
  @click.option('--user-id', required=False, help='User ID')
210
192
  @click.option('--base-url', required=False, help='Base URL')
211
193
  @click.option('--pat', required=False, help='Personal access token')
212
194
  @click.pass_context
213
- def create(
195
+ def create_context(
214
196
  ctx,
215
197
  name,
216
198
  user_id=None,
217
199
  base_url=None,
218
200
  pat=None,
219
201
  ):
220
- """Create a new context"""
202
+ """Create a new context."""
221
203
  from clarifai.utils.cli import validate_context_auth
222
204
 
223
205
  if name in ctx.obj.contexts:
@@ -234,22 +216,28 @@ def create(
234
216
  'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
235
217
  'ENVVAR',
236
218
  )
237
-
238
- # Validate the Context Credentials
239
219
  validate_context_auth(pat, user_id, base_url)
240
-
241
220
  context = Context(name, CLARIFAI_USER_ID=user_id, CLARIFAI_API_BASE=base_url, CLARIFAI_PAT=pat)
242
221
  ctx.obj.contexts[context.name] = context
243
222
  ctx.obj.to_yaml()
244
223
  logger.info(f"Context '{name}' created successfully")
245
224
 
246
225
 
247
- # write a click command to delete a context
248
- @context.command(['rm'])
226
+ @config.command(aliases=['e'])
227
+ @click.pass_context
228
+ def edit(
229
+ ctx,
230
+ ):
231
+ """Open the configuration file for editing."""
232
+ # For now, just open the config file (not per-context)
233
+ os.system(f'{os.environ.get("EDITOR", "vi")} {ctx.obj.filename}')
234
+
235
+
236
+ @config.command(aliases=['delete-context'])
249
237
  @click.argument('name')
250
238
  @click.pass_context
251
- def delete(ctx, name):
252
- """Delete a context"""
239
+ def delete_context(ctx, name):
240
+ """Delete a context."""
253
241
  if name not in ctx.obj.contexts:
254
242
  print(f'{name} is not a valid context')
255
243
  sys.exit(1)
@@ -258,16 +246,29 @@ def delete(ctx, name):
258
246
  print(f'{name} deleted')
259
247
 
260
248
 
261
- @context.command()
262
- @click.argument('name', type=str)
249
+ @config.command(aliases=['get-env'])
263
250
  @click.pass_context
264
- def use(ctx, name):
265
- """Set the current context"""
266
- if name not in ctx.obj.contexts:
267
- raise click.UsageError('Context not found')
268
- ctx.obj.current_context = name
269
- ctx.obj.to_yaml()
270
- print(f'Set {name} as the current context')
251
+ def env(ctx):
252
+ """Print env vars for the active context."""
253
+ ctx.obj.current.print_env_vars()
254
+
255
+
256
+ @config.command(aliases=['show'])
257
+ @click.option('-o', '--output-format', default='yaml', type=click.Choice(['json', 'yaml']))
258
+ @click.pass_context
259
+ def view(ctx, output_format):
260
+ """Display the current configuration."""
261
+ config_dict = {
262
+ 'current-context': ctx.obj.current_context,
263
+ 'contexts': {
264
+ name: context.to_serializable_dict() for name, context in ctx.obj.contexts.items()
265
+ },
266
+ }
267
+
268
+ if output_format == 'json':
269
+ print(json.dumps(config_dict, indent=2))
270
+ else:
271
+ print(yaml.safe_dump(config_dict, default_flow_style=False))
271
272
 
272
273
 
273
274
  @cli.command()