shaped 2.0.1__py3-none-any.whl → 2.0.4__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.
- shaped/__init__.py +59 -4
- shaped/autogen/__init__.py +527 -66
- shaped/autogen/api/__init__.py +4 -3
- shaped/autogen/api/engine_api.py +1467 -0
- shaped/autogen/api/{dataset_api.py → query_api.py} +159 -194
- shaped/autogen/api/table_api.py +1494 -0
- shaped/autogen/api/{model_management_api.py → view_api.py} +179 -181
- shaped/autogen/api_client.py +18 -11
- shaped/autogen/configuration.py +22 -9
- shaped/autogen/exceptions.py +25 -5
- shaped/autogen/models/__init__.py +247 -52
- shaped/autogen/models/ai_enrichment_view_config.py +123 -0
- shaped/autogen/models/{path.py → algorithm.py} +19 -19
- shaped/autogen/models/amplitude_table_config.py +106 -0
- shaped/autogen/models/ascending.py +148 -0
- shaped/autogen/models/attn_dropout_prob.py +136 -0
- shaped/autogen/models/attribute_journey.py +124 -0
- shaped/autogen/models/attribute_value.py +178 -0
- shaped/autogen/models/autoscaling_config.py +95 -0
- shaped/autogen/models/aws_pinpoint_table_config.py +108 -0
- shaped/autogen/models/batch_size.py +136 -0
- shaped/autogen/models/batch_size1.py +136 -0
- shaped/autogen/models/batch_size2.py +136 -0
- shaped/autogen/models/big_query_table_config.py +147 -0
- shaped/autogen/models/bm25.py +136 -0
- shaped/autogen/models/boosted_reorder_step.py +125 -0
- shaped/autogen/models/canary_rollout.py +99 -0
- shaped/autogen/models/candidate_attributes_retrieve_step.py +113 -0
- shaped/autogen/models/candidate_ids_retrieve_step.py +113 -0
- shaped/autogen/models/candidate_retrieval_strategy.py +41 -0
- shaped/autogen/models/clickhouse_table_config.py +146 -0
- shaped/autogen/models/column_order_retrieve_step.py +123 -0
- shaped/autogen/models/column_ordering.py +91 -0
- shaped/autogen/models/create_table_response.py +87 -0
- shaped/autogen/models/create_view_response.py +87 -0
- shaped/autogen/models/custom_table_config.py +135 -0
- shaped/autogen/models/data_compute_config.py +89 -0
- shaped/autogen/models/data_config.py +145 -0
- shaped/autogen/models/data_config_interaction_table.py +146 -0
- shaped/autogen/models/data_split_config.py +88 -0
- shaped/autogen/models/data_split_strategy.py +37 -0
- shaped/autogen/models/data_tier.py +37 -0
- shaped/autogen/models/default.py +246 -0
- shaped/autogen/models/delete_engine_response.py +87 -0
- shaped/autogen/models/delete_table_response.py +87 -0
- shaped/autogen/models/delete_view_response.py +87 -0
- shaped/autogen/models/deployment_config.py +117 -0
- shaped/autogen/models/distance_function.py +38 -0
- shaped/autogen/models/diversity_reorder_step.py +137 -0
- shaped/autogen/models/dropout_rate.py +136 -0
- shaped/autogen/models/dynamo_db_table_config.py +160 -0
- shaped/autogen/models/dynamo_db_table_config_scan_kwargs_value.py +138 -0
- shaped/autogen/models/embedder_batch_size.py +136 -0
- shaped/autogen/models/embedding_config.py +93 -0
- shaped/autogen/models/embedding_dim.py +136 -0
- shaped/autogen/models/embedding_dims.py +136 -0
- shaped/autogen/models/embedding_size.py +136 -0
- shaped/autogen/models/encoder.py +140 -0
- shaped/autogen/models/encoding_pooling_strategy.py +38 -0
- shaped/autogen/models/engine.py +109 -0
- shaped/autogen/models/engine_config_v2.py +152 -0
- shaped/autogen/models/engine_details_response.py +120 -0
- shaped/autogen/models/engine_schema.py +113 -0
- shaped/autogen/models/engine_schema_user_inner.py +146 -0
- shaped/autogen/models/entity_config.py +109 -0
- shaped/autogen/models/entity_journey.py +161 -0
- shaped/autogen/models/entity_type.py +38 -0
- shaped/autogen/models/evaluation_config.py +92 -0
- shaped/autogen/models/exploration_reorder_step.py +125 -0
- shaped/autogen/models/expression_filter_step.py +106 -0
- shaped/autogen/models/factors.py +136 -0
- shaped/autogen/models/factors1.py +136 -0
- shaped/autogen/models/feature.py +90 -0
- shaped/autogen/models/feature_type.py +60 -0
- shaped/autogen/models/file_table_config.py +112 -0
- shaped/autogen/models/filter_config.py +99 -0
- shaped/autogen/models/filter_dataset.py +164 -0
- shaped/autogen/models/filter_index_type.py +36 -0
- shaped/autogen/models/filter_retrieve_step.py +113 -0
- shaped/autogen/models/filter_step_explanation.py +165 -0
- shaped/autogen/models/filter_table.py +140 -0
- shaped/autogen/models/filter_type.py +134 -0
- shaped/autogen/models/global_filter.py +102 -0
- shaped/autogen/models/hidden_dropout_prob.py +136 -0
- shaped/autogen/models/hidden_size.py +136 -0
- shaped/autogen/models/hidden_size1.py +136 -0
- shaped/autogen/models/http_problem_response.py +115 -0
- shaped/autogen/models/http_validation_error.py +2 -2
- shaped/autogen/models/hugging_face_encoder.py +115 -0
- shaped/autogen/models/iceberg_table_config.py +154 -0
- shaped/autogen/models/index_config.py +101 -0
- shaped/autogen/models/inner_entity_id.py +144 -0
- shaped/autogen/models/inner_size.py +136 -0
- shaped/autogen/models/inner_size1.py +136 -0
- shaped/autogen/models/inner_uid.py +144 -0
- shaped/autogen/models/interaction_config.py +122 -0
- shaped/autogen/models/interaction_pooling_encoder.py +104 -0
- shaped/autogen/models/interaction_round_robin_encoder.py +104 -0
- shaped/autogen/models/item_attribute_pooling_encoder.py +111 -0
- shaped/autogen/models/journey.py +140 -0
- shaped/autogen/models/kafka_table_config.py +129 -0
- shaped/autogen/models/kinesis_table_config.py +140 -0
- shaped/autogen/models/kinesis_table_config_column_schema_value.py +136 -0
- shaped/autogen/models/label.py +90 -0
- shaped/autogen/models/label_type.py +36 -0
- shaped/autogen/models/laplace_smoothing.py +136 -0
- shaped/autogen/models/latency_scaling_policy.py +112 -0
- shaped/autogen/models/learning_rate.py +136 -0
- shaped/autogen/models/learning_rate1.py +136 -0
- shaped/autogen/models/learning_rate2.py +136 -0
- shaped/autogen/models/learning_rate3.py +136 -0
- shaped/autogen/models/lexical_search_mode.py +99 -0
- shaped/autogen/models/list_engines_response.py +95 -0
- shaped/autogen/models/list_tables_response.py +95 -0
- shaped/autogen/models/list_views_response.py +95 -0
- shaped/autogen/models/location_inner.py +138 -0
- shaped/autogen/models/loss_types.py +37 -0
- shaped/autogen/models/lr.py +136 -0
- shaped/autogen/models/lr1.py +136 -0
- shaped/autogen/models/lr2.py +136 -0
- shaped/autogen/models/max_depth.py +136 -0
- shaped/autogen/models/max_leaves.py +136 -0
- shaped/autogen/models/max_seq_length.py +136 -0
- shaped/autogen/models/max_seq_length1.py +136 -0
- shaped/autogen/models/max_seq_length2.py +136 -0
- shaped/autogen/models/mode.py +134 -0
- shaped/autogen/models/mode1.py +136 -0
- shaped/autogen/models/mode2.py +150 -0
- shaped/autogen/models/models_inner.py +308 -0
- shaped/autogen/models/mongo_db_table_config.py +147 -0
- shaped/autogen/models/mssql_table_config.py +155 -0
- shaped/autogen/models/{my_sql_dataset_config.py → my_sql_table_config.py} +45 -28
- shaped/autogen/models/n_epochs.py +136 -0
- shaped/autogen/models/n_epochs1.py +136 -0
- shaped/autogen/models/n_epochs2.py +136 -0
- shaped/autogen/models/n_estimators.py +136 -0
- shaped/autogen/models/n_heads.py +136 -0
- shaped/autogen/models/n_layers.py +136 -0
- shaped/autogen/models/neg_per_positive.py +136 -0
- shaped/autogen/models/negative_samples_count.py +136 -0
- shaped/autogen/models/ngram_tokenizer.py +103 -0
- shaped/autogen/models/no_op_config.py +117 -0
- shaped/autogen/models/num_blocks.py +136 -0
- shaped/autogen/models/num_heads.py +136 -0
- shaped/autogen/models/num_leaves.py +136 -0
- shaped/autogen/models/objective.py +40 -0
- shaped/autogen/models/objective1.py +134 -0
- shaped/autogen/models/online_store_config.py +89 -0
- shaped/autogen/models/pagination_config.py +87 -0
- shaped/autogen/models/parameter_definition.py +96 -0
- shaped/autogen/models/parameters_value.py +240 -0
- shaped/autogen/models/passthrough_score.py +104 -0
- shaped/autogen/models/personal_filter.py +104 -0
- shaped/autogen/models/pipeline_stage_explanation.py +118 -0
- shaped/autogen/models/policy.py +134 -0
- shaped/autogen/models/pool_fn.py +152 -0
- shaped/autogen/models/pooling_function.py +37 -0
- shaped/autogen/models/{postgres_dataset_config.py → postgres_table_config.py} +66 -28
- shaped/autogen/models/posthog_table_config.py +133 -0
- shaped/autogen/models/prebuilt_filter_step.py +113 -0
- shaped/autogen/models/precomputed_item_embedding.py +99 -0
- shaped/autogen/models/precomputed_user_embedding.py +99 -0
- shaped/autogen/models/query.py +136 -0
- shaped/autogen/models/query1.py +136 -0
- shaped/autogen/models/query_any_of.py +172 -0
- shaped/autogen/models/query_config.py +140 -0
- shaped/autogen/models/query_definition.py +106 -0
- shaped/autogen/models/query_encoder.py +194 -0
- shaped/autogen/models/query_explanation.py +201 -0
- shaped/autogen/models/query_request.py +121 -0
- shaped/autogen/models/query_result.py +113 -0
- shaped/autogen/models/query_table_config.py +99 -0
- shaped/autogen/models/rank_item_attribute_values_query_config.py +122 -0
- shaped/autogen/models/rank_query_config.py +167 -0
- shaped/autogen/models/rank_query_config_filter_inner.py +149 -0
- shaped/autogen/models/rank_query_config_reorder_inner.py +186 -0
- shaped/autogen/models/rank_query_config_retrieve_inner.py +265 -0
- shaped/autogen/models/recreate_rollout.py +97 -0
- shaped/autogen/models/{redshift_dataset_config.py → redshift_table_config.py} +48 -25
- shaped/autogen/models/reference_table_config.py +113 -0
- shaped/autogen/models/regularization.py +136 -0
- shaped/autogen/models/reorder_inner.py +149 -0
- shaped/autogen/models/reorder_step_explanation.py +207 -0
- shaped/autogen/models/request.py +378 -0
- shaped/autogen/models/request1.py +140 -0
- shaped/autogen/models/requests_per_second_scaling_policy.py +112 -0
- shaped/autogen/models/resource_config.py +100 -0
- shaped/autogen/models/response_get_view_details_views_view_name_get.py +134 -0
- shaped/autogen/models/result.py +132 -0
- shaped/autogen/models/result_embeddings_value.py +127 -0
- shaped/autogen/models/retrieval_scores_value.py +127 -0
- shaped/autogen/models/retrieve_inner.py +196 -0
- shaped/autogen/models/retrieve_step_explanation.py +172 -0
- shaped/autogen/models/retriever.py +196 -0
- shaped/autogen/models/retriever1.py +196 -0
- shaped/autogen/models/rollout_config.py +91 -0
- shaped/autogen/models/rudderstack_table_config.py +106 -0
- shaped/autogen/models/sampling_strategy.py +36 -0
- shaped/autogen/models/saved_query_info_response.py +103 -0
- shaped/autogen/models/saved_query_list_response.py +87 -0
- shaped/autogen/models/saved_query_request.py +115 -0
- shaped/autogen/models/schema_config.py +117 -0
- shaped/autogen/models/score.py +134 -0
- shaped/autogen/models/score_ensemble.py +127 -0
- shaped/autogen/models/score_ensemble_policy_config.py +165 -0
- shaped/autogen/models/score_ensemble_policy_config_policies_inner.py +755 -0
- shaped/autogen/models/score_step_explanation.py +224 -0
- shaped/autogen/models/search_config.py +105 -0
- shaped/autogen/models/segment_table_config.py +106 -0
- shaped/autogen/models/sequence_length.py +136 -0
- shaped/autogen/models/server_config.py +100 -0
- shaped/autogen/models/setup_engine_response.py +87 -0
- shaped/autogen/models/shaped_internal_recsys_policies_als_model_policy_als_model_policy_config.py +154 -0
- shaped/autogen/models/shaped_internal_recsys_policies_beeformer_model_policy_beeformer_model_policy_beeformer_model_policy_config.py +160 -0
- shaped/autogen/models/shaped_internal_recsys_policies_bert_model_policy_bert_model_policy_bert_model_policy_config.py +215 -0
- shaped/autogen/models/shaped_internal_recsys_policies_chronological_model_policy_chronological_model_policy_config.py +156 -0
- shaped/autogen/models/shaped_internal_recsys_policies_elsa_model_policy_elsa_model_policy_elsa_model_policy_config.py +141 -0
- shaped/autogen/models/shaped_internal_recsys_policies_gsasrec_model_policy_gsasrec_model_policy_gsas_rec_model_policy_config.py +211 -0
- shaped/autogen/models/shaped_internal_recsys_policies_item2vec_model_policy_item2_vec_model_policy_config.py +140 -0
- shaped/autogen/models/shaped_internal_recsys_policies_item_content_similarity_model_policy_item_content_similarity_model_policy_config.py +195 -0
- shaped/autogen/models/shaped_internal_recsys_policies_lightgbm_model_policy_lightgbm_model_policy_light_gbm_model_policy_config.py +245 -0
- shaped/autogen/models/shaped_internal_recsys_policies_ngram_model_policy_ngram_model_policy_config.py +119 -0
- shaped/autogen/models/shaped_internal_recsys_policies_popular_model_policy_popular_model_policy_config.py +161 -0
- shaped/autogen/models/shaped_internal_recsys_policies_random_model_policy_random_model_policy_config.py +108 -0
- shaped/autogen/models/shaped_internal_recsys_policies_recently_popular_policy_recently_popular_policy_config.py +143 -0
- shaped/autogen/models/shaped_internal_recsys_policies_rising_popular_policy_rising_popular_policy_config.py +123 -0
- shaped/autogen/models/shaped_internal_recsys_policies_sasrec_model_policy_sasrec_model_policy_sas_rec_model_policy_config.py +230 -0
- shaped/autogen/models/shaped_internal_recsys_policies_svd_model_policy_svd_model_policy_config.py +119 -0
- shaped/autogen/models/shaped_internal_recsys_policies_two_tower_model_policy_two_tower_model_policy_two_tower_model_policy_config.py +165 -0
- shaped/autogen/models/shaped_internal_recsys_policies_user_item_content_similarity_model_policy_user_item_content_similarity_model_policy_config.py +153 -0
- shaped/autogen/models/shaped_internal_recsys_policies_widedeep_model_policy_wide_deep_model_policy_config.py +137 -0
- shaped/autogen/models/shaped_internal_recsys_policies_xgboost_model_policy_xg_boost_model_policy_config.py +155 -0
- shaped/autogen/models/shopify_table_config.py +156 -0
- shaped/autogen/models/similarity_retrieve_step.py +123 -0
- shaped/autogen/models/{snowflake_dataset_config.py → snowflake_table_config.py} +47 -18
- shaped/autogen/models/sql_transform_type.py +37 -0
- shaped/autogen/models/sql_view_config.py +111 -0
- shaped/autogen/models/stemmer_tokenizer.py +105 -0
- shaped/autogen/models/step_explanation.py +137 -0
- shaped/autogen/models/steps_inner.py +179 -0
- shaped/autogen/models/strategy.py +134 -0
- shaped/autogen/models/table.py +102 -0
- shaped/autogen/models/table_deployment_type.py +38 -0
- shaped/autogen/models/table_insert_arguments.py +87 -0
- shaped/autogen/models/table_insert_response.py +87 -0
- shaped/autogen/models/text_encoding.py +148 -0
- shaped/autogen/models/text_search_retrieve_step.py +121 -0
- shaped/autogen/models/time_frequency.py +136 -0
- shaped/autogen/models/time_window.py +136 -0
- shaped/autogen/models/time_window_in_days.py +154 -0
- shaped/autogen/models/tokenizer.py +149 -0
- shaped/autogen/models/trained_model_encoder.py +99 -0
- shaped/autogen/models/training_compute_config.py +99 -0
- shaped/autogen/models/training_config.py +121 -0
- shaped/autogen/models/training_config_models_inner.py +540 -0
- shaped/autogen/models/training_strategy.py +37 -0
- shaped/autogen/models/transform_status.py +41 -0
- shaped/autogen/models/trending_mode.py +37 -0
- shaped/autogen/models/truncate_filter_step.py +106 -0
- shaped/autogen/models/tunable_bool.py +97 -0
- shaped/autogen/models/tunable_float.py +118 -0
- shaped/autogen/models/tunable_int.py +118 -0
- shaped/autogen/models/tunable_int_categorical.py +99 -0
- shaped/autogen/models/tunable_string.py +99 -0
- shaped/autogen/models/tuning_config.py +89 -0
- shaped/autogen/models/type.py +150 -0
- shaped/autogen/models/update_table_response.py +87 -0
- shaped/autogen/models/update_view_response.py +87 -0
- shaped/autogen/models/user_attribute_pooling_encoder.py +124 -0
- shaped/autogen/models/user_inner.py +134 -0
- shaped/autogen/models/val_split.py +136 -0
- shaped/autogen/models/validation_error.py +13 -3
- shaped/autogen/models/validation_error_loc_inner.py +150 -0
- shaped/autogen/models/value_type.py +7 -5
- shaped/autogen/models/vector_search_mode.py +101 -0
- shaped/autogen/models/view.py +104 -0
- shaped/autogen/models/view_details_ai.py +140 -0
- shaped/autogen/models/view_details_ai_schema_value.py +153 -0
- shaped/autogen/models/view_details_sql.py +140 -0
- shaped/autogen/models/view_status.py +41 -0
- shaped/autogen/models/weight_decay.py +136 -0
- shaped/autogen/models/whitespace_tokenizer.py +97 -0
- shaped/autogen/models/window_size.py +136 -0
- shaped/autogen/rest.py +10 -4
- shaped/cli/shaped_cli.py +163 -35
- shaped/client.py +591 -171
- shaped/config_builders.py +705 -0
- shaped/query_builder.py +781 -0
- {shaped-2.0.1.dist-info → shaped-2.0.4.dist-info}/METADATA +141 -6
- shaped-2.0.4.dist-info/RECORD +296 -0
- {shaped-2.0.1.dist-info → shaped-2.0.4.dist-info}/WHEEL +1 -1
- shaped-2.0.4.dist-info/entry_points.txt +2 -0
- shaped/autogen/api/model_inference_api.py +0 -2825
- shaped/autogen/models/amplitude_dataset_config.py +0 -96
- shaped/autogen/models/aws_pinpoint_dataset_config.py +0 -96
- shaped/autogen/models/big_query_dataset_config.py +0 -114
- shaped/autogen/models/complement_items_request.py +0 -99
- shaped/autogen/models/complement_items_response.py +0 -89
- shaped/autogen/models/connectors_inner.py +0 -134
- shaped/autogen/models/create_dataset_arguments.py +0 -263
- shaped/autogen/models/create_embedding_response.py +0 -87
- shaped/autogen/models/create_item_embedding_request.py +0 -89
- shaped/autogen/models/create_model_arguments.py +0 -107
- shaped/autogen/models/create_model_response.py +0 -87
- shaped/autogen/models/create_user_embedding_request.py +0 -89
- shaped/autogen/models/custom_dataset_config.py +0 -115
- shaped/autogen/models/dataset_config.py +0 -101
- shaped/autogen/models/dataset_schema_type.py +0 -47
- shaped/autogen/models/datasets_inner.py +0 -91
- shaped/autogen/models/delete_model_response.py +0 -87
- shaped/autogen/models/fetch_config.py +0 -95
- shaped/autogen/models/file_config.py +0 -105
- shaped/autogen/models/file_source_config.py +0 -89
- shaped/autogen/models/inference_config.py +0 -101
- shaped/autogen/models/insert_model_response.py +0 -87
- shaped/autogen/models/interaction.py +0 -87
- shaped/autogen/models/list_datasets_response.py +0 -95
- shaped/autogen/models/list_models_response.py +0 -95
- shaped/autogen/models/model_config.py +0 -99
- shaped/autogen/models/model_response.py +0 -95
- shaped/autogen/models/mongo_db_dataset_config.py +0 -119
- shaped/autogen/models/post_rank_request.py +0 -117
- shaped/autogen/models/rank_attribute_response.py +0 -89
- shaped/autogen/models/rank_grid_attribute_request.py +0 -91
- shaped/autogen/models/rank_grid_attribute_request1.py +0 -93
- shaped/autogen/models/rank_grid_attribute_response.py +0 -91
- shaped/autogen/models/rank_response.py +0 -91
- shaped/autogen/models/retrieve_request.py +0 -101
- shaped/autogen/models/retrieve_response.py +0 -91
- shaped/autogen/models/retriever_top_k_override.py +0 -97
- shaped/autogen/models/rudder_stack_dataset_config.py +0 -96
- shaped/autogen/models/segment_dataset_config.py +0 -96
- shaped/autogen/models/similar_item_request.py +0 -101
- shaped/autogen/models/similar_response.py +0 -89
- shaped/autogen/models/similar_users_request.py +0 -99
- shaped/autogen/models/successful_response.py +0 -87
- shaped/autogen/models/view_model_response.py +0 -99
- shaped-2.0.1.dist-info/RECORD +0 -73
- shaped-2.0.1.dist-info/entry_points.txt +0 -2
- {shaped-2.0.1.dist-info → shaped-2.0.4.dist-info}/top_level.txt +0 -0
- {shaped-2.0.1.dist-info → shaped-2.0.4.dist-info}/zip-safe +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Shaped API
|
|
5
|
+
|
|
6
|
+
Welcome to Shaped's API reference docs. These provide a detailed view of the endpoints and CLI commands that Shaped provides and brief explanations of how they should be used. The Shaped API has four main endpoints: **Tables** - Provision and manage batch and real-time data connectors. **Views** - Configure SQL transformations and AI enrichment on your input data. Use SQL to combine multiple data sources or use an LLM to add new categories, extract specific attributes from descriptions, etc. **Engines** - Deploy and manage your relevance engines. The Engine API exposes configuration for indexing logic, input datasets, externam embeddings, and more. **Query** - Execute queries against your engines, to return data based on an input query or rerank an existing list. The Query API exposes the retrieve, filter, score, and ranking steps of the 4-stage ranking architecture. The base URL for each endpoint is: `https://api.shaped.ai/v2`
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 2.0.4
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
import pprint
|
|
17
|
+
import re # noqa: F401
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
|
|
21
|
+
from typing import Any, ClassVar, Dict, List, Optional
|
|
22
|
+
from typing import Optional, Set
|
|
23
|
+
from typing_extensions import Self
|
|
24
|
+
|
|
25
|
+
class WhitespaceTokenizer(BaseModel):
|
|
26
|
+
"""
|
|
27
|
+
A simple tokenizer that splits on whitespace.
|
|
28
|
+
""" # noqa: E501
|
|
29
|
+
type: Optional[StrictStr] = Field(default='whitespace', description="Tokenizer type discriminator.")
|
|
30
|
+
__properties: ClassVar[List[str]] = ["type"]
|
|
31
|
+
|
|
32
|
+
@field_validator('type')
|
|
33
|
+
def type_validate_enum(cls, value):
|
|
34
|
+
"""Validates the enum"""
|
|
35
|
+
if value is None:
|
|
36
|
+
return value
|
|
37
|
+
|
|
38
|
+
if value not in set(['whitespace']):
|
|
39
|
+
raise ValueError("must be one of enum values ('whitespace')")
|
|
40
|
+
return value
|
|
41
|
+
|
|
42
|
+
model_config = ConfigDict(
|
|
43
|
+
populate_by_name=True,
|
|
44
|
+
validate_assignment=True,
|
|
45
|
+
protected_namespaces=(),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def to_str(self) -> str:
|
|
50
|
+
"""Returns the string representation of the model using alias"""
|
|
51
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
52
|
+
|
|
53
|
+
def to_json(self) -> str:
|
|
54
|
+
"""Returns the JSON representation of the model using alias"""
|
|
55
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
56
|
+
return json.dumps(self.to_dict())
|
|
57
|
+
|
|
58
|
+
@classmethod
|
|
59
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
60
|
+
"""Create an instance of WhitespaceTokenizer from a JSON string"""
|
|
61
|
+
return cls.from_dict(json.loads(json_str))
|
|
62
|
+
|
|
63
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
64
|
+
"""Return the dictionary representation of the model using alias.
|
|
65
|
+
|
|
66
|
+
This has the following differences from calling pydantic's
|
|
67
|
+
`self.model_dump(by_alias=True)`:
|
|
68
|
+
|
|
69
|
+
* `None` is only added to the output dict for nullable fields that
|
|
70
|
+
were set at model initialization. Other fields with value `None`
|
|
71
|
+
are ignored.
|
|
72
|
+
"""
|
|
73
|
+
excluded_fields: Set[str] = set([
|
|
74
|
+
])
|
|
75
|
+
|
|
76
|
+
_dict = self.model_dump(
|
|
77
|
+
by_alias=True,
|
|
78
|
+
exclude=excluded_fields,
|
|
79
|
+
exclude_none=True,
|
|
80
|
+
)
|
|
81
|
+
return _dict
|
|
82
|
+
|
|
83
|
+
@classmethod
|
|
84
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
85
|
+
"""Create an instance of WhitespaceTokenizer from a dict"""
|
|
86
|
+
if obj is None:
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
if not isinstance(obj, dict):
|
|
90
|
+
return cls.model_validate(obj)
|
|
91
|
+
|
|
92
|
+
_obj = cls.model_validate({
|
|
93
|
+
"type": obj.get("type") if obj.get("type") is not None else 'whitespace'
|
|
94
|
+
})
|
|
95
|
+
return _obj
|
|
96
|
+
|
|
97
|
+
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Shaped API
|
|
5
|
+
|
|
6
|
+
Welcome to Shaped's API reference docs. These provide a detailed view of the endpoints and CLI commands that Shaped provides and brief explanations of how they should be used. The Shaped API has four main endpoints: **Tables** - Provision and manage batch and real-time data connectors. **Views** - Configure SQL transformations and AI enrichment on your input data. Use SQL to combine multiple data sources or use an LLM to add new categories, extract specific attributes from descriptions, etc. **Engines** - Deploy and manage your relevance engines. The Engine API exposes configuration for indexing logic, input datasets, externam embeddings, and more. **Query** - Execute queries against your engines, to return data based on an input query or rerank an existing list. The Query API exposes the retrieve, filter, score, and ranking steps of the 4-stage ranking architecture. The base URL for each endpoint is: `https://api.shaped.ai/v2`
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 2.0.4
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
from inspect import getfullargspec
|
|
17
|
+
import json
|
|
18
|
+
import pprint
|
|
19
|
+
import re # noqa: F401
|
|
20
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, ValidationError, field_validator
|
|
21
|
+
from typing import Optional
|
|
22
|
+
from shaped.autogen.models.tunable_int import TunableInt
|
|
23
|
+
from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict
|
|
24
|
+
from typing_extensions import Literal, Self
|
|
25
|
+
from pydantic import Field
|
|
26
|
+
|
|
27
|
+
WINDOWSIZE_ANY_OF_SCHEMAS = ["TunableInt", "int"]
|
|
28
|
+
|
|
29
|
+
class WindowSize(BaseModel):
|
|
30
|
+
"""
|
|
31
|
+
Context window size for predicting items in sequences.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
# data type: int
|
|
35
|
+
anyof_schema_1_validator: Optional[StrictInt] = None
|
|
36
|
+
# data type: TunableInt
|
|
37
|
+
anyof_schema_2_validator: Optional[TunableInt] = None
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
actual_instance: Optional[Union[TunableInt, int]] = None
|
|
40
|
+
else:
|
|
41
|
+
actual_instance: Any = None
|
|
42
|
+
any_of_schemas: Set[str] = { "TunableInt", "int" }
|
|
43
|
+
|
|
44
|
+
model_config = {
|
|
45
|
+
"validate_assignment": True,
|
|
46
|
+
"protected_namespaces": (),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
50
|
+
if args:
|
|
51
|
+
if len(args) > 1:
|
|
52
|
+
raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
|
|
53
|
+
if kwargs:
|
|
54
|
+
raise ValueError("If a position argument is used, keyword arguments cannot be used.")
|
|
55
|
+
super().__init__(actual_instance=args[0])
|
|
56
|
+
else:
|
|
57
|
+
super().__init__(**kwargs)
|
|
58
|
+
|
|
59
|
+
@field_validator('actual_instance')
|
|
60
|
+
def actual_instance_must_validate_anyof(cls, v):
|
|
61
|
+
instance = WindowSize.model_construct()
|
|
62
|
+
error_messages = []
|
|
63
|
+
# validate data type: int
|
|
64
|
+
try:
|
|
65
|
+
instance.anyof_schema_1_validator = v
|
|
66
|
+
return v
|
|
67
|
+
except (ValidationError, ValueError) as e:
|
|
68
|
+
error_messages.append(str(e))
|
|
69
|
+
# validate data type: TunableInt
|
|
70
|
+
if not isinstance(v, TunableInt):
|
|
71
|
+
error_messages.append(f"Error! Input type `{type(v)}` is not `TunableInt`")
|
|
72
|
+
else:
|
|
73
|
+
return v
|
|
74
|
+
|
|
75
|
+
if error_messages:
|
|
76
|
+
# no match
|
|
77
|
+
raise ValueError("No match found when setting the actual_instance in WindowSize with anyOf schemas: TunableInt, int. Details: " + ", ".join(error_messages))
|
|
78
|
+
else:
|
|
79
|
+
return v
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def from_dict(cls, obj: Dict[str, Any]) -> Self:
|
|
83
|
+
return cls.from_json(json.dumps(obj))
|
|
84
|
+
|
|
85
|
+
@classmethod
|
|
86
|
+
def from_json(cls, json_str: str) -> Self:
|
|
87
|
+
"""Returns the object represented by the json string"""
|
|
88
|
+
instance = cls.model_construct()
|
|
89
|
+
error_messages = []
|
|
90
|
+
# deserialize data into int
|
|
91
|
+
try:
|
|
92
|
+
# validation
|
|
93
|
+
instance.anyof_schema_1_validator = json.loads(json_str)
|
|
94
|
+
# assign value to actual_instance
|
|
95
|
+
instance.actual_instance = instance.anyof_schema_1_validator
|
|
96
|
+
return instance
|
|
97
|
+
except (ValidationError, ValueError) as e:
|
|
98
|
+
error_messages.append(str(e))
|
|
99
|
+
# anyof_schema_2_validator: Optional[TunableInt] = None
|
|
100
|
+
try:
|
|
101
|
+
instance.actual_instance = TunableInt.from_json(json_str)
|
|
102
|
+
return instance
|
|
103
|
+
except (ValidationError, ValueError) as e:
|
|
104
|
+
error_messages.append(str(e))
|
|
105
|
+
|
|
106
|
+
if error_messages:
|
|
107
|
+
# no match
|
|
108
|
+
raise ValueError("No match found when deserializing the JSON string into WindowSize with anyOf schemas: TunableInt, int. Details: " + ", ".join(error_messages))
|
|
109
|
+
else:
|
|
110
|
+
return instance
|
|
111
|
+
|
|
112
|
+
def to_json(self) -> str:
|
|
113
|
+
"""Returns the JSON representation of the actual instance"""
|
|
114
|
+
if self.actual_instance is None:
|
|
115
|
+
return "null"
|
|
116
|
+
|
|
117
|
+
if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json):
|
|
118
|
+
return self.actual_instance.to_json()
|
|
119
|
+
else:
|
|
120
|
+
return json.dumps(self.actual_instance)
|
|
121
|
+
|
|
122
|
+
def to_dict(self) -> Optional[Union[Dict[str, Any], TunableInt, int]]:
|
|
123
|
+
"""Returns the dict representation of the actual instance"""
|
|
124
|
+
if self.actual_instance is None:
|
|
125
|
+
return None
|
|
126
|
+
|
|
127
|
+
if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict):
|
|
128
|
+
return self.actual_instance.to_dict()
|
|
129
|
+
else:
|
|
130
|
+
return self.actual_instance
|
|
131
|
+
|
|
132
|
+
def to_str(self) -> str:
|
|
133
|
+
"""Returns the string representation of the actual instance"""
|
|
134
|
+
return pprint.pformat(self.model_dump())
|
|
135
|
+
|
|
136
|
+
|
shaped/autogen/rest.py
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"""
|
|
4
4
|
Shaped API
|
|
5
5
|
|
|
6
|
-
Welcome to Shaped's API reference docs. These provide a
|
|
6
|
+
Welcome to Shaped's API reference docs. These provide a detailed view of the endpoints and CLI commands that Shaped provides and brief explanations of how they should be used. The Shaped API has four main endpoints: **Tables** - Provision and manage batch and real-time data connectors. **Views** - Configure SQL transformations and AI enrichment on your input data. Use SQL to combine multiple data sources or use an LLM to add new categories, extract specific attributes from descriptions, etc. **Engines** - Deploy and manage your relevance engines. The Engine API exposes configuration for indexing logic, input datasets, externam embeddings, and more. **Query** - Execute queries against your engines, to return data based on an input query or rerank an existing list. The Query API exposes the retrieve, filter, score, and ranking steps of the 4-stage ranking architecture. The base URL for each endpoint is: `https://api.shaped.ai/v2`
|
|
7
7
|
|
|
8
|
-
The version of the OpenAPI document:
|
|
8
|
+
The version of the OpenAPI document: 2.0.4
|
|
9
9
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
10
|
|
|
11
11
|
Do not edit the class manually.
|
|
@@ -48,12 +48,17 @@ class RESTResponse(io.IOBase):
|
|
|
48
48
|
self.data = self.response.data
|
|
49
49
|
return self.data
|
|
50
50
|
|
|
51
|
+
@property
|
|
52
|
+
def headers(self):
|
|
53
|
+
"""Returns a dictionary of response headers."""
|
|
54
|
+
return self.response.headers
|
|
55
|
+
|
|
51
56
|
def getheaders(self):
|
|
52
|
-
"""Returns a dictionary of the response headers."""
|
|
57
|
+
"""Returns a dictionary of the response headers; use ``headers`` instead."""
|
|
53
58
|
return self.response.headers
|
|
54
59
|
|
|
55
60
|
def getheader(self, name, default=None):
|
|
56
|
-
"""Returns a given response header."""
|
|
61
|
+
"""Returns a given response header; use ``headers.get()`` instead."""
|
|
57
62
|
return self.response.headers.get(name, default)
|
|
58
63
|
|
|
59
64
|
|
|
@@ -76,6 +81,7 @@ class RESTClientObject:
|
|
|
76
81
|
"ca_certs": configuration.ssl_ca_cert,
|
|
77
82
|
"cert_file": configuration.cert_file,
|
|
78
83
|
"key_file": configuration.key_file,
|
|
84
|
+
"ca_cert_data": configuration.ca_cert_data,
|
|
79
85
|
}
|
|
80
86
|
if configuration.assert_hostname is not None:
|
|
81
87
|
pool_args['assert_hostname'] = (
|
shaped/cli/shaped_cli.py
CHANGED
|
@@ -12,7 +12,7 @@ from tqdm import tqdm
|
|
|
12
12
|
|
|
13
13
|
APP_NAME = "SHAPED_CLI"
|
|
14
14
|
|
|
15
|
-
app = typer.Typer()
|
|
15
|
+
app = typer.Typer(name="shaped")
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class Config(BaseModel):
|
|
@@ -25,14 +25,14 @@ def _write_config(config: Config):
|
|
|
25
25
|
app_dir_path.mkdir(parents=True, exist_ok=True)
|
|
26
26
|
config_path = app_dir_path / "config.json"
|
|
27
27
|
with open(config_path, "w") as f:
|
|
28
|
-
f.write(config.
|
|
28
|
+
f.write(config.model_dump_json())
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
def _read_config() -> Config:
|
|
32
32
|
app_dir_path = Path(typer.get_app_dir(APP_NAME))
|
|
33
33
|
config_path = app_dir_path / "config.json"
|
|
34
34
|
with open(config_path, "r") as f:
|
|
35
|
-
config = Config.
|
|
35
|
+
config = Config.model_validate_json(f.read())
|
|
36
36
|
|
|
37
37
|
return config
|
|
38
38
|
|
|
@@ -61,26 +61,92 @@ def _parse_response_as_yaml(content: str) -> str:
|
|
|
61
61
|
return yaml.dump(json.loads(content), sort_keys=False)
|
|
62
62
|
|
|
63
63
|
|
|
64
|
+
def _normalize_query_to_request(query_input: str) -> str:
|
|
65
|
+
"""
|
|
66
|
+
Normalize query input to a QueryRequest JSON string.
|
|
67
|
+
|
|
68
|
+
The input can be:
|
|
69
|
+
- A SQL string (e.g., "SELECT * FROM table")
|
|
70
|
+
- A QueryConfig JSON object (e.g., {"type": "rank", ...})
|
|
71
|
+
- A full QueryRequest JSON object (e.g., {"query": "...", "return_metadata": true})
|
|
72
|
+
- Legacy format (e.g., {"sql": "SELECT * FROM table"})
|
|
73
|
+
|
|
74
|
+
Returns a JSON string representing a QueryRequest.
|
|
75
|
+
|
|
76
|
+
Raises:
|
|
77
|
+
ValueError: If the input is invalid or cannot be normalized.
|
|
78
|
+
"""
|
|
79
|
+
if not query_input or not query_input.strip():
|
|
80
|
+
raise ValueError(
|
|
81
|
+
"Query input cannot be empty. Provide a SQL query string or "
|
|
82
|
+
"JSON query configuration."
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Try to parse as JSON first.
|
|
86
|
+
try:
|
|
87
|
+
parsed = json.loads(query_input)
|
|
88
|
+
|
|
89
|
+
# If it's already a QueryRequest (has 'query' field), use as-is.
|
|
90
|
+
if isinstance(parsed, dict) and "query" in parsed:
|
|
91
|
+
return json.dumps(parsed)
|
|
92
|
+
|
|
93
|
+
# Handle legacy {"sql": "..."} format.
|
|
94
|
+
if isinstance(parsed, dict) and "sql" in parsed:
|
|
95
|
+
sql_string = parsed["sql"]
|
|
96
|
+
if not isinstance(sql_string, str) or not sql_string.strip():
|
|
97
|
+
raise ValueError(
|
|
98
|
+
"Invalid 'sql' field in query. Expected a non-empty SQL string."
|
|
99
|
+
)
|
|
100
|
+
# Merge any other fields (like return_metadata) if present.
|
|
101
|
+
request = {"query": sql_string, "return_metadata": True}
|
|
102
|
+
if "return_metadata" in parsed:
|
|
103
|
+
request["return_metadata"] = parsed["return_metadata"]
|
|
104
|
+
if "parameters" in parsed:
|
|
105
|
+
request["parameters"] = parsed["parameters"]
|
|
106
|
+
return json.dumps(request)
|
|
107
|
+
|
|
108
|
+
# If it's a dict but not a QueryRequest, wrap it as the query field.
|
|
109
|
+
if isinstance(parsed, dict):
|
|
110
|
+
return json.dumps({"query": parsed, "return_metadata": True})
|
|
111
|
+
|
|
112
|
+
# If it's a string in JSON (unlikely but possible), treat as SQL.
|
|
113
|
+
if isinstance(parsed, str):
|
|
114
|
+
return json.dumps({"query": parsed, "return_metadata": True})
|
|
115
|
+
|
|
116
|
+
# Other types, wrap as query.
|
|
117
|
+
return json.dumps({"query": parsed, "return_metadata": True})
|
|
118
|
+
except json.JSONDecodeError:
|
|
119
|
+
# Not valid JSON, treat as SQL string.
|
|
120
|
+
# This is expected for plain SQL queries, so we don't raise an error.
|
|
121
|
+
return json.dumps({"query": query_input, "return_metadata": True})
|
|
122
|
+
except ValueError as e:
|
|
123
|
+
# Re-raise ValueError with context.
|
|
124
|
+
raise ValueError(f"Invalid query input: {e}") from e
|
|
125
|
+
|
|
126
|
+
|
|
64
127
|
@app.command()
|
|
65
128
|
def init(
|
|
66
|
-
api_key: str = typer.Option(..., help="Your Shaped API key."),
|
|
67
|
-
env: str = typer.Option(
|
|
129
|
+
api_key: str = typer.Option(..., "--api-key", help="Your Shaped API key."),
|
|
130
|
+
env: str = typer.Option(
|
|
131
|
+
"prod", "--env", help="Environment to use (e.g., prod, dev, staging)."
|
|
132
|
+
),
|
|
68
133
|
):
|
|
69
134
|
"""
|
|
70
135
|
Initialize the Shaped CLI with your API key and environment.
|
|
71
|
-
|
|
136
|
+
|
|
72
137
|
This command saves your configuration locally so you don't need to
|
|
73
138
|
provide your API key for every command.
|
|
74
139
|
"""
|
|
75
140
|
config = Config(api_key=api_key, env=env)
|
|
76
141
|
_write_config(config)
|
|
77
|
-
typer.echo(f"Initializing with config: {config.
|
|
142
|
+
typer.echo(f"Initializing with config: {config.model_dump()}")
|
|
78
143
|
|
|
79
144
|
|
|
80
145
|
##############
|
|
81
146
|
# ENGINE API #
|
|
82
147
|
##############
|
|
83
148
|
|
|
149
|
+
|
|
84
150
|
@app.command()
|
|
85
151
|
def create_engine(
|
|
86
152
|
file: typer.FileText = typer.Option(
|
|
@@ -89,7 +155,7 @@ def create_engine(
|
|
|
89
155
|
):
|
|
90
156
|
"""
|
|
91
157
|
Create a new engine.
|
|
92
|
-
|
|
158
|
+
|
|
93
159
|
The engine configuration can be provided via:
|
|
94
160
|
- --file: Path to a JSON/YAML file
|
|
95
161
|
- stdin: Pipe JSON/YAML content
|
|
@@ -125,7 +191,7 @@ def update_engine(
|
|
|
125
191
|
):
|
|
126
192
|
"""
|
|
127
193
|
Update an existing engine.
|
|
128
|
-
|
|
194
|
+
|
|
129
195
|
The engine configuration can be provided via:
|
|
130
196
|
- --file: Path to a JSON/YAML file
|
|
131
197
|
- stdin: Pipe JSON/YAML content
|
|
@@ -218,7 +284,7 @@ def create_table_from_uri(
|
|
|
218
284
|
):
|
|
219
285
|
"""
|
|
220
286
|
Create a table from a data file and automatically insert the data.
|
|
221
|
-
|
|
287
|
+
|
|
222
288
|
The table schema is inferred from the first chunk of data.
|
|
223
289
|
"""
|
|
224
290
|
chunks = _read_chunks(path, type, chunk_size=1)
|
|
@@ -249,7 +315,7 @@ def create_table(
|
|
|
249
315
|
):
|
|
250
316
|
"""
|
|
251
317
|
Create a new table.
|
|
252
|
-
|
|
318
|
+
|
|
253
319
|
The table configuration can be provided via:
|
|
254
320
|
- --file: Path to a JSON/YAML file
|
|
255
321
|
- stdin: Pipe JSON/YAML content
|
|
@@ -321,7 +387,7 @@ def update_table(
|
|
|
321
387
|
):
|
|
322
388
|
"""
|
|
323
389
|
Update an existing table.
|
|
324
|
-
|
|
390
|
+
|
|
325
391
|
The table configuration can be provided via:
|
|
326
392
|
- --file: Path to a JSON/YAML file
|
|
327
393
|
- stdin: Pipe JSON/YAML content
|
|
@@ -359,7 +425,7 @@ def table_insert(
|
|
|
359
425
|
):
|
|
360
426
|
"""
|
|
361
427
|
Insert data into a table from a file.
|
|
362
|
-
|
|
428
|
+
|
|
363
429
|
Data is read in chunks and uploaded progressively with a progress bar.
|
|
364
430
|
"""
|
|
365
431
|
config = _read_config()
|
|
@@ -383,7 +449,7 @@ def table_insert(
|
|
|
383
449
|
# Chunk read and upload.
|
|
384
450
|
for chunk in _read_chunks(file, type, chunk_size=1000):
|
|
385
451
|
_write_chunk(chunk)
|
|
386
|
-
|
|
452
|
+
|
|
387
453
|
bar.close()
|
|
388
454
|
|
|
389
455
|
|
|
@@ -440,7 +506,7 @@ def create_view(
|
|
|
440
506
|
):
|
|
441
507
|
"""
|
|
442
508
|
Create a new view.
|
|
443
|
-
|
|
509
|
+
|
|
444
510
|
The view configuration can be provided via:
|
|
445
511
|
- --file: Path to a JSON/YAML file
|
|
446
512
|
- stdin: Pipe JSON/YAML content
|
|
@@ -513,7 +579,7 @@ def update_view(
|
|
|
513
579
|
):
|
|
514
580
|
"""
|
|
515
581
|
Update an existing view.
|
|
516
|
-
|
|
582
|
+
|
|
517
583
|
The view configuration can be provided via:
|
|
518
584
|
- --file: Path to a JSON/YAML file
|
|
519
585
|
- stdin: Pipe JSON/YAML content
|
|
@@ -566,20 +632,22 @@ def delete_view(
|
|
|
566
632
|
|
|
567
633
|
@app.command()
|
|
568
634
|
def query(
|
|
569
|
-
engine_name: str = typer.Option(
|
|
635
|
+
engine_name: str = typer.Option(
|
|
636
|
+
..., help="Name of the engine to execute the query against."
|
|
637
|
+
),
|
|
570
638
|
query_file: typer.FileText = typer.Option(
|
|
571
639
|
None, help="Path to a JSON or YAML file containing the query."
|
|
572
640
|
),
|
|
573
641
|
query: str = typer.Option(
|
|
574
|
-
None, help="
|
|
642
|
+
None, help="Query string (SQL or JSON). Can be used instead of --query-file."
|
|
575
643
|
),
|
|
576
644
|
):
|
|
577
645
|
"""
|
|
578
646
|
Execute an ad-hoc query against an engine.
|
|
579
|
-
|
|
647
|
+
|
|
580
648
|
The query can be provided via:
|
|
581
649
|
- --query-file: Path to a JSON/YAML file
|
|
582
|
-
- --query: JSON string
|
|
650
|
+
- --query: SQL query string or JSON string containing the query
|
|
583
651
|
- stdin: Pipe JSON/YAML content
|
|
584
652
|
"""
|
|
585
653
|
config = _read_config()
|
|
@@ -590,28 +658,79 @@ def query(
|
|
|
590
658
|
"x-api-key": config.api_key,
|
|
591
659
|
}
|
|
592
660
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
661
|
+
try:
|
|
662
|
+
# Check stdin only if no other input options are provided.
|
|
663
|
+
# If stdin is not a TTY, peek to see if there's content.
|
|
664
|
+
stdin_has_content = False
|
|
665
|
+
stdin_content = ""
|
|
666
|
+
if not sys.stdin.isatty() and query_file is None and query is None:
|
|
667
|
+
# Only read from stdin if no other options provided.
|
|
668
|
+
stdin_content = sys.stdin.read()
|
|
669
|
+
stdin_has_content = bool(stdin_content.strip())
|
|
670
|
+
if not stdin_has_content:
|
|
671
|
+
raise ValueError(
|
|
672
|
+
"No input provided via stdin. Provide a SQL query string or "
|
|
673
|
+
"JSON query configuration."
|
|
674
|
+
)
|
|
675
|
+
|
|
676
|
+
if stdin_has_content:
|
|
677
|
+
# Read from stdin and normalize to QueryRequest.
|
|
678
|
+
payload = _normalize_query_to_request(stdin_content)
|
|
679
|
+
elif query_file is not None:
|
|
680
|
+
# Read file content and normalize to QueryRequest.
|
|
681
|
+
# Files can contain SQL strings or JSON/YAML.
|
|
682
|
+
try:
|
|
683
|
+
# Try to parse as JSON/YAML first.
|
|
684
|
+
query_file.seek(0)
|
|
685
|
+
file_content = _parse_file_as_json(query_file)
|
|
686
|
+
except (ValueError, json.JSONDecodeError, yaml.YAMLError) as e:
|
|
687
|
+
# If parsing fails, read as raw content (e.g., SQL string).
|
|
688
|
+
query_file.seek(0)
|
|
689
|
+
file_content = query_file.read()
|
|
690
|
+
if not file_content.strip():
|
|
691
|
+
raise ValueError(
|
|
692
|
+
f"File '{query_file.name}' is empty or could not be parsed. "
|
|
693
|
+
"Provide a SQL query string or valid JSON/YAML configuration."
|
|
694
|
+
) from e
|
|
695
|
+
payload = _normalize_query_to_request(file_content)
|
|
696
|
+
elif query is not None:
|
|
697
|
+
# Normalize CLI string input to QueryRequest.
|
|
698
|
+
payload = _normalize_query_to_request(query)
|
|
699
|
+
else:
|
|
700
|
+
raise ValueError(
|
|
701
|
+
"Must provide query input via one of:\n"
|
|
702
|
+
" - --query-file: Path to a file containing SQL or JSON/YAML\n"
|
|
703
|
+
" - --query: SQL query string or JSON string\n"
|
|
704
|
+
" - stdin: Pipe SQL or JSON/YAML content"
|
|
705
|
+
)
|
|
706
|
+
except ValueError as e:
|
|
707
|
+
typer.echo(f"Error: {e}", err=True)
|
|
708
|
+
raise typer.Exit(1)
|
|
709
|
+
except Exception as e:
|
|
710
|
+
typer.echo(f"Error: Unexpected error processing query input: {e}", err=True)
|
|
711
|
+
raise typer.Exit(1)
|
|
603
712
|
|
|
604
713
|
typer.echo(payload)
|
|
605
714
|
response = requests.post(url, headers=headers, data=payload)
|
|
606
715
|
if response.status_code != 200:
|
|
607
|
-
|
|
716
|
+
# Try to parse error response for better error message.
|
|
717
|
+
try:
|
|
718
|
+
error_data = response.json()
|
|
719
|
+
error_msg = error_data.get(
|
|
720
|
+
"message", error_data.get("detail", response.text)
|
|
721
|
+
)
|
|
722
|
+
typer.echo(f"Error {response.status_code}: {error_msg}", err=True)
|
|
723
|
+
except (json.JSONDecodeError, ValueError):
|
|
724
|
+
typer.echo(f"Error {response.status_code}: {response.text}", err=True)
|
|
608
725
|
raise typer.Exit(1)
|
|
609
726
|
typer.echo(_parse_response_as_yaml(response.text))
|
|
610
727
|
|
|
611
728
|
|
|
612
729
|
@app.command()
|
|
613
730
|
def execute_saved_query(
|
|
614
|
-
engine_name: str = typer.Option(
|
|
731
|
+
engine_name: str = typer.Option(
|
|
732
|
+
..., help="Name of the engine containing the saved query."
|
|
733
|
+
),
|
|
615
734
|
query_name: str = typer.Option(..., help="Name of the saved query to execute."),
|
|
616
735
|
):
|
|
617
736
|
"""
|
|
@@ -633,7 +752,9 @@ def execute_saved_query(
|
|
|
633
752
|
|
|
634
753
|
@app.command()
|
|
635
754
|
def view_saved_query(
|
|
636
|
-
engine_name: str = typer.Option(
|
|
755
|
+
engine_name: str = typer.Option(
|
|
756
|
+
..., help="Name of the engine containing the saved query."
|
|
757
|
+
),
|
|
637
758
|
query_name: str = typer.Option(..., help="Name of the saved query to view."),
|
|
638
759
|
):
|
|
639
760
|
"""
|
|
@@ -651,7 +772,9 @@ def view_saved_query(
|
|
|
651
772
|
|
|
652
773
|
@app.command()
|
|
653
774
|
def list_saved_queries(
|
|
654
|
-
engine_name: str = typer.Option(
|
|
775
|
+
engine_name: str = typer.Option(
|
|
776
|
+
..., help="Name of the engine to list saved queries for."
|
|
777
|
+
),
|
|
655
778
|
):
|
|
656
779
|
"""
|
|
657
780
|
List all saved queries for an engine.
|
|
@@ -666,5 +789,10 @@ def list_saved_queries(
|
|
|
666
789
|
typer.echo(_parse_response_as_yaml(response.text))
|
|
667
790
|
|
|
668
791
|
|
|
669
|
-
|
|
792
|
+
def main():
|
|
793
|
+
"""Entry point for the shaped CLI command."""
|
|
670
794
|
app(prog_name="shaped")
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
if __name__ == "__main__":
|
|
798
|
+
main()
|