cognee 0.2.1.dev7__py3-none-any.whl → 0.2.2.dev1__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.
- cognee/api/client.py +44 -4
- cognee/api/health.py +332 -0
- cognee/api/v1/add/add.py +5 -2
- cognee/api/v1/add/routers/get_add_router.py +3 -0
- cognee/api/v1/cognify/code_graph_pipeline.py +3 -1
- cognee/api/v1/cognify/cognify.py +8 -0
- cognee/api/v1/cognify/routers/get_cognify_router.py +8 -1
- cognee/api/v1/config/config.py +3 -1
- cognee/api/v1/datasets/routers/get_datasets_router.py +2 -8
- cognee/api/v1/delete/delete.py +16 -12
- cognee/api/v1/responses/routers/get_responses_router.py +3 -1
- cognee/api/v1/search/search.py +10 -0
- cognee/api/v1/settings/routers/get_settings_router.py +0 -2
- cognee/base_config.py +1 -0
- cognee/eval_framework/evaluation/direct_llm_eval_adapter.py +5 -6
- cognee/infrastructure/databases/graph/config.py +2 -0
- cognee/infrastructure/databases/graph/get_graph_engine.py +58 -12
- cognee/infrastructure/databases/graph/graph_db_interface.py +15 -10
- cognee/infrastructure/databases/graph/kuzu/adapter.py +43 -16
- cognee/infrastructure/databases/graph/kuzu/kuzu_migrate.py +281 -0
- cognee/infrastructure/databases/graph/neo4j_driver/adapter.py +151 -77
- cognee/infrastructure/databases/graph/neptune_driver/__init__.py +15 -0
- cognee/infrastructure/databases/graph/neptune_driver/adapter.py +1427 -0
- cognee/infrastructure/databases/graph/neptune_driver/exceptions.py +115 -0
- cognee/infrastructure/databases/graph/neptune_driver/neptune_utils.py +224 -0
- cognee/infrastructure/databases/graph/networkx/adapter.py +3 -3
- cognee/infrastructure/databases/hybrid/neptune_analytics/NeptuneAnalyticsAdapter.py +449 -0
- cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +11 -3
- cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +8 -3
- cognee/infrastructure/databases/vector/create_vector_engine.py +31 -23
- cognee/infrastructure/databases/vector/embeddings/FastembedEmbeddingEngine.py +3 -1
- cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +21 -6
- cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +4 -3
- cognee/infrastructure/databases/vector/embeddings/get_embedding_engine.py +3 -1
- cognee/infrastructure/databases/vector/lancedb/LanceDBAdapter.py +22 -16
- cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +36 -34
- cognee/infrastructure/databases/vector/vector_db_interface.py +78 -7
- cognee/infrastructure/files/utils/get_data_file_path.py +39 -0
- cognee/infrastructure/files/utils/guess_file_type.py +2 -2
- cognee/infrastructure/files/utils/open_data_file.py +4 -23
- cognee/infrastructure/llm/LLMGateway.py +137 -0
- cognee/infrastructure/llm/__init__.py +14 -4
- cognee/infrastructure/llm/config.py +29 -1
- cognee/infrastructure/llm/prompts/answer_hotpot_question.txt +1 -1
- cognee/infrastructure/llm/prompts/answer_hotpot_using_cognee_search.txt +1 -1
- cognee/infrastructure/llm/prompts/answer_simple_question.txt +1 -1
- cognee/infrastructure/llm/prompts/answer_simple_question_restricted.txt +1 -1
- cognee/infrastructure/llm/prompts/categorize_categories.txt +1 -1
- cognee/infrastructure/llm/prompts/classify_content.txt +1 -1
- cognee/infrastructure/llm/prompts/context_for_question.txt +1 -1
- cognee/infrastructure/llm/prompts/graph_context_for_question.txt +1 -1
- cognee/infrastructure/llm/prompts/natural_language_retriever_system.txt +1 -1
- cognee/infrastructure/llm/prompts/patch_gen_instructions.txt +1 -1
- cognee/infrastructure/llm/prompts/search_type_selector_prompt.txt +130 -0
- cognee/infrastructure/llm/prompts/summarize_code.txt +2 -2
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/__init__.py +57 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/async_client.py +533 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/config.py +94 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/globals.py +37 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/inlinedbaml.py +21 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/parser.py +131 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/runtime.py +266 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/stream_types.py +137 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/sync_client.py +550 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/tracing.py +26 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_builder.py +962 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_map.py +52 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_client/types.py +166 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extract_categories.baml +109 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extract_content_graph.baml +343 -0
- cognee/{modules/data → infrastructure/llm/structured_output_framework/baml/baml_src}/extraction/__init__.py +1 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/extract_summary.py +89 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/knowledge_graph/extract_content_graph.py +33 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_src/generators.baml +18 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/__init__.py +3 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/extract_categories.py +12 -0
- cognee/{modules/data → infrastructure/llm/structured_output_framework/litellm_instructor}/extraction/extract_summary.py +16 -7
- cognee/{modules/data → infrastructure/llm/structured_output_framework/litellm_instructor}/extraction/knowledge_graph/extract_content_graph.py +7 -6
- cognee/infrastructure/llm/{anthropic → structured_output_framework/litellm_instructor/llm/anthropic}/adapter.py +10 -4
- cognee/infrastructure/llm/{gemini → structured_output_framework/litellm_instructor/llm/gemini}/adapter.py +6 -5
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/generic_llm_api/__init__.py +0 -0
- cognee/infrastructure/llm/{generic_llm_api → structured_output_framework/litellm_instructor/llm/generic_llm_api}/adapter.py +7 -3
- cognee/infrastructure/llm/{get_llm_client.py → structured_output_framework/litellm_instructor/llm/get_llm_client.py} +18 -6
- cognee/infrastructure/llm/{llm_interface.py → structured_output_framework/litellm_instructor/llm/llm_interface.py} +2 -2
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/ollama/__init__.py +0 -0
- cognee/infrastructure/llm/{ollama → structured_output_framework/litellm_instructor/llm/ollama}/adapter.py +4 -2
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/__init__.py +0 -0
- cognee/infrastructure/llm/{openai → structured_output_framework/litellm_instructor/llm/openai}/adapter.py +6 -4
- cognee/infrastructure/llm/{rate_limiter.py → structured_output_framework/litellm_instructor/llm/rate_limiter.py} +0 -5
- cognee/infrastructure/llm/tokenizer/Gemini/adapter.py +4 -2
- cognee/infrastructure/llm/tokenizer/TikToken/adapter.py +7 -3
- cognee/infrastructure/llm/tokenizer/__init__.py +4 -0
- cognee/infrastructure/llm/utils.py +3 -1
- cognee/infrastructure/loaders/LoaderEngine.py +156 -0
- cognee/infrastructure/loaders/LoaderInterface.py +73 -0
- cognee/infrastructure/loaders/__init__.py +18 -0
- cognee/infrastructure/loaders/core/__init__.py +7 -0
- cognee/infrastructure/loaders/core/audio_loader.py +98 -0
- cognee/infrastructure/loaders/core/image_loader.py +114 -0
- cognee/infrastructure/loaders/core/text_loader.py +90 -0
- cognee/infrastructure/loaders/create_loader_engine.py +32 -0
- cognee/infrastructure/loaders/external/__init__.py +22 -0
- cognee/infrastructure/loaders/external/pypdf_loader.py +96 -0
- cognee/infrastructure/loaders/external/unstructured_loader.py +127 -0
- cognee/infrastructure/loaders/get_loader_engine.py +18 -0
- cognee/infrastructure/loaders/supported_loaders.py +18 -0
- cognee/infrastructure/loaders/use_loader.py +21 -0
- cognee/infrastructure/loaders/utils/__init__.py +0 -0
- cognee/modules/data/methods/__init__.py +1 -0
- cognee/modules/data/methods/get_authorized_dataset.py +23 -0
- cognee/modules/data/models/Data.py +13 -3
- cognee/modules/data/processing/document_types/AudioDocument.py +2 -2
- cognee/modules/data/processing/document_types/ImageDocument.py +2 -2
- cognee/modules/data/processing/document_types/PdfDocument.py +4 -11
- cognee/modules/data/processing/document_types/UnstructuredDocument.py +2 -5
- cognee/modules/engine/utils/generate_edge_id.py +5 -0
- cognee/modules/graph/cognee_graph/CogneeGraph.py +45 -35
- cognee/modules/graph/methods/get_formatted_graph_data.py +8 -2
- cognee/modules/graph/utils/get_graph_from_model.py +93 -101
- cognee/modules/ingestion/data_types/TextData.py +8 -2
- cognee/modules/ingestion/save_data_to_file.py +1 -1
- cognee/modules/pipelines/exceptions/__init__.py +1 -0
- cognee/modules/pipelines/exceptions/exceptions.py +12 -0
- cognee/modules/pipelines/models/DataItemStatus.py +5 -0
- cognee/modules/pipelines/models/PipelineRunInfo.py +6 -0
- cognee/modules/pipelines/models/__init__.py +1 -0
- cognee/modules/pipelines/operations/pipeline.py +10 -2
- cognee/modules/pipelines/operations/run_tasks.py +252 -20
- cognee/modules/pipelines/operations/run_tasks_distributed.py +1 -1
- cognee/modules/retrieval/chunks_retriever.py +23 -1
- cognee/modules/retrieval/code_retriever.py +66 -9
- cognee/modules/retrieval/completion_retriever.py +11 -9
- cognee/modules/retrieval/context_providers/TripletSearchContextProvider.py +0 -2
- cognee/modules/retrieval/graph_completion_context_extension_retriever.py +0 -2
- cognee/modules/retrieval/graph_completion_cot_retriever.py +8 -9
- cognee/modules/retrieval/graph_completion_retriever.py +1 -1
- cognee/modules/retrieval/insights_retriever.py +4 -0
- cognee/modules/retrieval/natural_language_retriever.py +9 -15
- cognee/modules/retrieval/summaries_retriever.py +23 -1
- cognee/modules/retrieval/utils/brute_force_triplet_search.py +23 -4
- cognee/modules/retrieval/utils/completion.py +6 -9
- cognee/modules/retrieval/utils/description_to_codepart_search.py +2 -3
- cognee/modules/search/methods/search.py +5 -1
- cognee/modules/search/operations/__init__.py +1 -0
- cognee/modules/search/operations/select_search_type.py +42 -0
- cognee/modules/search/types/SearchType.py +1 -0
- cognee/modules/settings/get_settings.py +0 -8
- cognee/modules/settings/save_vector_db_config.py +1 -1
- cognee/shared/data_models.py +3 -1
- cognee/shared/logging_utils.py +0 -5
- cognee/tasks/chunk_naive_llm_classifier/chunk_naive_llm_classifier.py +2 -2
- cognee/tasks/documents/extract_chunks_from_documents.py +10 -12
- cognee/tasks/entity_completion/entity_extractors/llm_entity_extractor.py +4 -6
- cognee/tasks/graph/cascade_extract/utils/extract_content_nodes_and_relationship_names.py +4 -6
- cognee/tasks/graph/cascade_extract/utils/extract_edge_triplets.py +6 -7
- cognee/tasks/graph/cascade_extract/utils/extract_nodes.py +4 -7
- cognee/tasks/graph/extract_graph_from_code.py +3 -2
- cognee/tasks/graph/extract_graph_from_data.py +4 -3
- cognee/tasks/graph/infer_data_ontology.py +5 -6
- cognee/tasks/ingestion/data_item_to_text_file.py +79 -0
- cognee/tasks/ingestion/ingest_data.py +91 -61
- cognee/tasks/ingestion/resolve_data_directories.py +3 -0
- cognee/tasks/repo_processor/get_repo_file_dependencies.py +3 -0
- cognee/tasks/storage/index_data_points.py +1 -1
- cognee/tasks/storage/index_graph_edges.py +4 -1
- cognee/tasks/summarization/summarize_code.py +2 -3
- cognee/tasks/summarization/summarize_text.py +3 -2
- cognee/tests/test_cognee_server_start.py +12 -7
- cognee/tests/test_deduplication.py +2 -2
- cognee/tests/test_deletion.py +58 -17
- cognee/tests/test_graph_visualization_permissions.py +161 -0
- cognee/tests/test_neptune_analytics_graph.py +309 -0
- cognee/tests/test_neptune_analytics_hybrid.py +176 -0
- cognee/tests/{test_weaviate.py → test_neptune_analytics_vector.py} +86 -11
- cognee/tests/test_pgvector.py +5 -5
- cognee/tests/test_s3.py +1 -6
- cognee/tests/unit/infrastructure/databases/test_rate_limiter.py +11 -10
- cognee/tests/unit/infrastructure/databases/vector/__init__.py +0 -0
- cognee/tests/unit/infrastructure/mock_embedding_engine.py +1 -1
- cognee/tests/unit/infrastructure/test_embedding_rate_limiting_realistic.py +5 -5
- cognee/tests/unit/infrastructure/test_rate_limiting_realistic.py +6 -4
- cognee/tests/unit/infrastructure/test_rate_limiting_retry.py +1 -1
- cognee/tests/unit/interfaces/graph/get_graph_from_model_unit_test.py +61 -3
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +84 -9
- cognee/tests/unit/modules/search/search_methods_test.py +55 -0
- {cognee-0.2.1.dev7.dist-info → cognee-0.2.2.dev1.dist-info}/METADATA +13 -9
- {cognee-0.2.1.dev7.dist-info → cognee-0.2.2.dev1.dist-info}/RECORD +203 -164
- cognee/infrastructure/databases/vector/pinecone/adapter.py +0 -8
- cognee/infrastructure/databases/vector/qdrant/QDrantAdapter.py +0 -514
- cognee/infrastructure/databases/vector/qdrant/__init__.py +0 -2
- cognee/infrastructure/databases/vector/weaviate_db/WeaviateAdapter.py +0 -527
- cognee/infrastructure/databases/vector/weaviate_db/__init__.py +0 -1
- cognee/modules/data/extraction/extract_categories.py +0 -14
- cognee/tests/test_qdrant.py +0 -99
- distributed/Dockerfile +0 -34
- distributed/app.py +0 -4
- distributed/entrypoint.py +0 -71
- distributed/entrypoint.sh +0 -5
- distributed/modal_image.py +0 -11
- distributed/queues.py +0 -5
- distributed/tasks/queued_add_data_points.py +0 -13
- distributed/tasks/queued_add_edges.py +0 -13
- distributed/tasks/queued_add_nodes.py +0 -13
- distributed/test.py +0 -28
- distributed/utils.py +0 -19
- distributed/workers/data_point_saving_worker.py +0 -93
- distributed/workers/graph_saving_worker.py +0 -104
- /cognee/infrastructure/databases/{graph/memgraph → hybrid/neptune_analytics}/__init__.py +0 -0
- /cognee/infrastructure/{llm → databases/vector/embeddings}/embedding_rate_limiter.py +0 -0
- /cognee/infrastructure/{databases/vector/pinecone → llm/structured_output_framework}/__init__.py +0 -0
- /cognee/infrastructure/llm/{anthropic → structured_output_framework/baml/baml_src}/__init__.py +0 -0
- /cognee/infrastructure/llm/{gemini/__init__.py → structured_output_framework/baml/baml_src/extraction/extract_categories.py} +0 -0
- /cognee/infrastructure/llm/{generic_llm_api → structured_output_framework/baml/baml_src/extraction/knowledge_graph}/__init__.py +0 -0
- /cognee/infrastructure/llm/{ollama → structured_output_framework/litellm_instructor}/__init__.py +0 -0
- /cognee/{modules/data → infrastructure/llm/structured_output_framework/litellm_instructor}/extraction/knowledge_graph/__init__.py +0 -0
- /cognee/{modules/data → infrastructure/llm/structured_output_framework/litellm_instructor}/extraction/texts.json +0 -0
- /cognee/infrastructure/llm/{openai → structured_output_framework/litellm_instructor/llm}/__init__.py +0 -0
- {distributed → cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic}/__init__.py +0 -0
- {distributed/tasks → cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini}/__init__.py +0 -0
- /cognee/modules/data/{extraction/knowledge_graph → methods}/add_model_class_to_graph.py +0 -0
- {cognee-0.2.1.dev7.dist-info → cognee-0.2.2.dev1.dist-info}/WHEEL +0 -0
- {cognee-0.2.1.dev7.dist-info → cognee-0.2.2.dev1.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.2.1.dev7.dist-info → cognee-0.2.2.dev1.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# ----------------------------------------------------------------------------
|
|
2
|
+
#
|
|
3
|
+
# Welcome to Baml! To use this generated code, please run the following:
|
|
4
|
+
#
|
|
5
|
+
# $ pip install baml
|
|
6
|
+
#
|
|
7
|
+
# ----------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
# This file was generated by BAML: please do not edit it. Instead, edit the
|
|
10
|
+
# BAML files and re-generate this code using: baml-cli generate
|
|
11
|
+
# baml-cli is available with the baml package.
|
|
12
|
+
|
|
13
|
+
_file_map = {
|
|
14
|
+
"extract_categories.baml": '// Content classification data models - matching shared/data_models.py\nclass TextContent {\n type string\n subclass string[]\n}\n\nclass AudioContent {\n type string\n subclass string[]\n}\n\nclass ImageContent {\n type string\n subclass string[]\n}\n\nclass VideoContent {\n type string\n subclass string[]\n}\n\nclass MultimediaContent {\n type string\n subclass string[]\n}\n\nclass Model3DContent {\n type string\n subclass string[]\n}\n\nclass ProceduralContent {\n type string\n subclass string[]\n}\n\nclass ContentLabel {\n content_type "text" | "audio" | "image" | "video" | "multimedia" | "3d_model" | "procedural"\n type string\n subclass string[]\n}\n\nclass DefaultContentPrediction {\n label ContentLabel\n}\n\n// Content classification prompt template\ntemplate_string ClassifyContentPrompt() #"\n You are a classification engine and should classify content. Make sure to use one of the existing classification options and not invent your own.\n\n Classify the content into one of these main categories and their relevant subclasses:\n\n **TEXT CONTENT** (content_type: "text"):\n - type: "TEXTUAL_DOCUMENTS_USED_FOR_GENERAL_PURPOSES"\n - subclass options: ["Articles, essays, and reports", "Books and manuscripts", "News stories and blog posts", "Research papers and academic publications", "Social media posts and comments", "Website content and product descriptions", "Personal narratives and stories", "Spreadsheets and tables", "Forms and surveys", "Databases and CSV files", "Source code in various programming languages", "Shell commands and scripts", "Markup languages (HTML, XML)", "Stylesheets (CSS) and configuration files (YAML, JSON, INI)", "Chat transcripts and messaging history", "Customer service logs and interactions", "Conversational AI training data", "Textbook content and lecture notes", "Exam questions and academic exercises", "E-learning course materials", "Poetry and prose", "Scripts for plays, movies, and television", "Song lyrics", "Manuals and user guides", "Technical specifications and API documentation", "Helpdesk articles and FAQs", "Contracts and agreements", "Laws, regulations, and legal case documents", "Policy documents and compliance materials", "Clinical trial reports", "Patient records and case notes", "Scientific journal articles", "Financial reports and statements", "Business plans and proposals", "Market research and analysis reports", "Ad copies and marketing slogans", "Product catalogs and brochures", "Press releases and promotional content", "Professional and formal correspondence", "Personal emails and letters", "Image and video captions", "Annotations and metadata for various media", "Vocabulary lists and grammar rules", "Language exercises and quizzes", "Other types of text data"]\n\n **AUDIO CONTENT** (content_type: "audio"):\n - type: "AUDIO_DOCUMENTS_USED_FOR_GENERAL_PURPOSES"\n - subclass options: ["Music tracks and albums", "Podcasts and radio broadcasts", "Audiobooks and audio guides", "Recorded interviews and speeches", "Sound effects and ambient sounds", "Other types of audio recordings"]\n\n **IMAGE CONTENT** (content_type: "image"):\n - type: "IMAGE_DOCUMENTS_USED_FOR_GENERAL_PURPOSES"\n - subclass options: ["Photographs and digital images", "Illustrations, diagrams, and charts", "Infographics and visual data representations", "Artwork and paintings", "Screenshots and graphical user interfaces", "Other types of images"]\n\n **VIDEO CONTENT** (content_type: "video"):\n - type: "VIDEO_DOCUMENTS_USED_FOR_GENERAL_PURPOSES"\n - subclass options: ["Movies and short films", "Documentaries and educational videos", "Video tutorials and how-to guides", "Animated features and cartoons", "Live event recordings and sports broadcasts", "Other types of video content"]\n\n **MULTIMEDIA CONTENT** (content_type: "multimedia"):\n - type: "MULTIMEDIA_DOCUMENTS_USED_FOR_GENERAL_PURPOSES"\n - subclass options: ["Interactive web content and games", "Virtual reality (VR) and augmented reality (AR) experiences", "Mixed media presentations and slide decks", "E-learning modules with integrated multimedia", "Digital exhibitions and virtual tours", "Other types of multimedia content"]\n\n **3D MODEL CONTENT** (content_type: "3d_model"):\n - type: "3D_MODEL_DOCUMENTS_USED_FOR_GENERAL_PURPOSES"\n - subclass options: ["Architectural renderings and building plans", "Product design models and prototypes", "3D animations and character models", "Scientific simulations and visualizations", "Virtual objects for AR/VR applications", "Other types of 3D models"]\n\n **PROCEDURAL CONTENT** (content_type: "procedural"):\n - type: "PROCEDURAL_DOCUMENTS_USED_FOR_GENERAL_PURPOSES"\n - subclass options: ["Tutorials and step-by-step guides", "Workflow and process descriptions", "Simulation and training exercises", "Recipes and crafting instructions", "Other types of procedural content"]\n\n Select the most appropriate content_type, type, and relevant subclasses.\n"#\n\n// OpenAI client defined once for all BAML files\n\n// Classification function\nfunction ExtractCategories(content: string) -> DefaultContentPrediction {\n client OpenAI\n\n prompt #"\n {{ ClassifyContentPrompt() }}\n\n {{ ctx.output_format(prefix="Answer in this schema:\\n") }}\n\n {{ _.role(\'user\') }}\n {{ content }}\n "#\n}\n\n// Test case for classification\ntest ExtractCategoriesExample {\n functions [ExtractCategories]\n args {\n content #"\n Natural language processing (NLP) is an interdisciplinary subfield of computer science and information retrieval.\n It deals with the interaction between computers and human language, in particular how to program computers to process and analyze large amounts of natural language data.\n "#\n }\n}\n',
|
|
15
|
+
"extract_content_graph.baml": 'class Node {\n id string\n name string\n type string\n description string\n @@dynamic\n}\n\n/// doc string for edge\nclass Edge {\n /// doc string for source_node_id\n source_node_id string\n target_node_id string\n relationship_name string\n}\n\nclass KnowledgeGraph {\n nodes (Node @stream.done)[]\n edges Edge[]\n}\n\n// Summarization classes\nclass SummarizedContent {\n summary string\n description string\n}\n\nclass SummarizedFunction {\n name string\n description string\n inputs string[]?\n outputs string[]?\n decorators string[]?\n}\n\nclass SummarizedClass {\n name string\n description string\n methods SummarizedFunction[]?\n decorators string[]?\n}\n\nclass SummarizedCode {\n high_level_summary string\n key_features string[]\n imports string[]\n constants string[]\n classes SummarizedClass[]\n functions SummarizedFunction[]\n workflow_description string?\n}\n\nclass DynamicKnowledgeGraph {\n @@dynamic\n}\n\n\n// Simple template for basic extraction (fast, good quality)\ntemplate_string ExtractContentGraphPrompt() #"\n You are an advanced algorithm that extracts structured data into a knowledge graph.\n\n - **Nodes**: Entities/concepts (like Wikipedia articles).\n - **Edges**: Relationships (like Wikipedia links). Use snake_case (e.g., `acted_in`).\n\n **Rules:**\n\n 1. **Node Labeling & IDs**\n - Use basic types only (e.g., "Person", "Date", "Organization").\n - Avoid overly specific or generic terms (e.g., no "Mathematician" or "Entity").\n - Node IDs must be human-readable names from the text (no numbers).\n\n 2. **Dates & Numbers**\n - Label dates as **"Date"** in "YYYY-MM-DD" format (use available parts if incomplete).\n - Properties are key-value pairs; do not use escaped quotes.\n\n 3. **Coreference Resolution**\n - Use a single, complete identifier for each entity (e.g., always "John Doe" not "Joe" or "he").\n\n 4. **Relationship Labels**:\n - Use descriptive, lowercase, snake_case names for edges.\n - *Example*: born_in, married_to, invented_by.\n - Avoid vague or generic labels like isA, relatesTo, has.\n - Avoid duplicated relationships like produces, produced by.\n\n 5. **Strict Compliance**\n - Follow these rules exactly. Non-compliance results in termination.\n"#\n\n// Summarization prompt template\ntemplate_string SummarizeContentPrompt() #"\n You are a top-tier summarization engine. Your task is to summarize text and make it versatile.\n Be brief and concise, but keep the important information and the subject.\n Use synonym words where possible in order to change the wording but keep the meaning.\n"#\n\n// Code summarization prompt template\ntemplate_string SummarizeCodePrompt() #"\n You are an expert code analyst. Analyze the provided source code and extract key information:\n\n 1. Provide a high-level summary of what the code does\n 2. List key features and functionality\n 3. Identify imports and dependencies\n 4. List constants and global variables\n 5. Summarize classes with their methods\n 6. Summarize standalone functions\n 7. Describe the overall workflow if applicable\n\n Be precise and technical while remaining clear and concise.\n"#\n\n// Detailed template for complex extraction (slower, higher quality)\ntemplate_string DetailedExtractContentGraphPrompt() #"\n You are a top-tier algorithm designed for extracting information in structured formats to build a knowledge graph.\n **Nodes** represent entities and concepts. They\'re akin to Wikipedia nodes.\n **Edges** represent relationships between concepts. They\'re akin to Wikipedia links.\n\n The aim is to achieve simplicity and clarity in the knowledge graph.\n\n # 1. Labeling Nodes\n **Consistency**: Ensure you use basic or elementary types for node labels.\n - For example, when you identify an entity representing a person, always label it as **"Person"**.\n - Avoid using more specific terms like "Mathematician" or "Scientist", keep those as "profession" property.\n - Don\'t use too generic terms like "Entity".\n **Node IDs**: Never utilize integers as node IDs.\n - Node IDs should be names or human-readable identifiers found in the text.\n\n # 2. Handling Numerical Data and Dates\n - For example, when you identify an entity representing a date, make sure it has type **"Date"**.\n - Extract the date in the format "YYYY-MM-DD"\n - If not possible to extract the whole date, extract month or year, or both if available.\n - **Property Format**: Properties must be in a key-value format.\n - **Quotation Marks**: Never use escaped single or double quotes within property values.\n - **Naming Convention**: Use snake_case for relationship names, e.g., `acted_in`.\n\n # 3. Coreference Resolution\n - **Maintain Entity Consistency**: When extracting entities, it\'s vital to ensure consistency.\n If an entity, such as "John Doe", is mentioned multiple times in the text but is referred to by different names or pronouns (e.g., "Joe", "he"),\n always use the most complete identifier for that entity throughout the knowledge graph. In this example, use "John Doe" as the Person\'s ID.\n Remember, the knowledge graph should be coherent and easily understandable, so maintaining consistency in entity references is crucial.\n\n # 4. Strict Compliance\n Adhere to the rules strictly. Non-compliance will result in termination.\n"#\n\n// Guided template with step-by-step instructions\ntemplate_string GuidedExtractContentGraphPrompt() #"\n You are an advanced algorithm designed to extract structured information to build a clean, consistent, and human-readable knowledge graph.\n\n **Objective**:\n - Nodes represent entities and concepts, similar to Wikipedia articles.\n - Edges represent typed relationships between nodes, similar to Wikipedia hyperlinks.\n - The graph must be clear, minimal, consistent, and semantically precise.\n\n **Node Guidelines**:\n\n 1. **Label Consistency**:\n - Use consistent, basic types for all node labels.\n - Do not switch between granular or vague labels for the same kind of entity.\n - Pick one label for each category and apply it uniformly.\n - Each entity type should be in a singular form and in a case of multiple words separated by whitespaces\n\n 2. **Node Identifiers**:\n - Node IDs must be human-readable and derived directly from the text.\n - Prefer full names and canonical terms.\n - Never use integers or autogenerated IDs.\n - *Example*: Use "Marie Curie", "Theory of Evolution", "Google".\n\n 3. **Coreference Resolution**:\n - Maintain one consistent node ID for each real-world entity.\n - Resolve aliases, acronyms, and pronouns to the most complete form.\n - *Example*: Always use "John Doe" even if later referred to as "Doe" or "he".\n\n **Edge Guidelines**:\n\n 4. **Relationship Labels**:\n - Use descriptive, lowercase, snake_case names for edges.\n - *Example*: born_in, married_to, invented_by.\n - Avoid vague or generic labels like isA, relatesTo, has.\n\n 5. **Relationship Direction**:\n - Edges must be directional and logically consistent.\n - *Example*:\n - "Marie Curie" —[born_in]→ "Warsaw"\n - "Radioactivity" —[discovered_by]→ "Marie Curie"\n\n **Compliance**:\n Strict adherence to these guidelines is required. Any deviation will result in immediate termination of the task.\n"#\n\n// Strict template with zero-tolerance rules\ntemplate_string StrictExtractContentGraphPrompt() #"\n You are a top-tier algorithm for **extracting structured information** from unstructured text to build a **knowledge graph**.\n\n Your primary goal is to extract:\n - **Nodes**: Representing **entities** and **concepts** (like Wikipedia nodes).\n - **Edges**: Representing **relationships** between those concepts (like Wikipedia links).\n\n The resulting knowledge graph must be **simple, consistent, and human-readable**.\n\n ## 1. Node Labeling and Identification\n\n ### Node Types\n Use **basic atomic types** for node labels. Always prefer general types over specific roles or professions:\n - "Person" for any human.\n - "Organization" for companies, institutions, etc.\n - "Location" for geographic or place entities.\n - "Date" for any temporal expression.\n - "Event" for historical or scheduled occurrences.\n - "Work" for books, films, artworks, or research papers.\n - "Concept" for abstract notions or ideas.\n\n ### Node IDs\n - Always assign **human-readable and unambiguous identifiers**.\n - Never use numeric or autogenerated IDs.\n - Prioritize **most complete form** of entity names for consistency.\n\n ## 2. Relationship Handling\n - Use **snake_case** for all relationship (edge) types.\n - Keep relationship types semantically clear and consistent.\n - Avoid vague relation names like "related_to" unless no better alternative exists.\n\n ## 3. Strict Compliance\n Follow all rules exactly. Any deviation may lead to rejection or incorrect graph construction.\n"#\n\n// OpenAI client with environment model selection\nclient<llm> OpenAI {\n provider openai\n options {\n model client_registry.model\n api_key client_registry.api_key\n }\n}\n\n\n\n// Function that returns raw structured output (for custom objects - to be handled in Python)\nfunction ExtractContentGraphGeneric(\n content: string,\n mode: "simple" | "base" | "guided" | "strict" | "custom"?,\n custom_prompt_content: string?\n) -> KnowledgeGraph {\n client OpenAI\n\n prompt #"\n {% if mode == "base" %}\n {{ DetailedExtractContentGraphPrompt() }}\n {% elif mode == "guided" %}\n {{ GuidedExtractContentGraphPrompt() }}\n {% elif mode == "strict" %}\n {{ StrictExtractContentGraphPrompt() }}\n {% elif mode == "custom" and custom_prompt_content %}\n {{ custom_prompt_content }}\n {% else %}\n {{ ExtractContentGraphPrompt() }}\n {% endif %}\n\n {{ ctx.output_format(prefix="Answer in this schema:\\n") }}\n\n Before answering, briefly describe what you\'ll extract from the text, then provide the structured output.\n\n Example format:\n I\'ll extract the main entities and their relationships from this text...\n\n { ... }\n\n {{ _.role(\'user\') }}\n {{ content }}\n "#\n}\n\n// Backward-compatible function specifically for KnowledgeGraph\nfunction ExtractDynamicContentGraph(\n content: string,\n mode: "simple" | "base" | "guided" | "strict" | "custom"?,\n custom_prompt_content: string?\n) -> DynamicKnowledgeGraph {\n client OpenAI\n\n prompt #"\n {% if mode == "base" %}\n {{ DetailedExtractContentGraphPrompt() }}\n {% elif mode == "guided" %}\n {{ GuidedExtractContentGraphPrompt() }}\n {% elif mode == "strict" %}\n {{ StrictExtractContentGraphPrompt() }}\n {% elif mode == "custom" and custom_prompt_content %}\n {{ custom_prompt_content }}\n {% else %}\n {{ ExtractContentGraphPrompt() }}\n {% endif %}\n\n {{ ctx.output_format(prefix="Answer in this schema:\\n") }}\n\n Before answering, briefly describe what you\'ll extract from the text, then provide the structured output.\n\n Example format:\n I\'ll extract the main entities and their relationships from this text...\n\n { ... }\n\n {{ _.role(\'user\') }}\n {{ content }}\n "#\n}\n\n\n// Summarization functions\nfunction SummarizeContent(content: string) -> SummarizedContent {\n client OpenAI\n\n prompt #"\n {{ SummarizeContentPrompt() }}\n\n {{ ctx.output_format(prefix="Answer in this schema:\\n") }}\n\n {{ _.role(\'user\') }}\n {{ content }}\n "#\n}\n\nfunction SummarizeCode(content: string) -> SummarizedCode {\n client OpenAI\n\n prompt #"\n {{ SummarizeCodePrompt() }}\n\n {{ ctx.output_format(prefix="Answer in this schema:\\n") }}\n\n {{ _.role(\'user\') }}\n {{ content }}\n "#\n}\n\ntest ExtractStrictExample {\n functions [ExtractContentGraphGeneric]\n args {\n content #"\n The Python programming language was created by Guido van Rossum in 1991.\n "#\n mode "strict"\n }\n}',
|
|
16
|
+
"generators.baml": '// This helps use auto generate libraries you can use in the language of\n// your choice. You can have multiple generators if you use multiple languages.\n// Just ensure that the output_dir is different for each generator.\ngenerator target {\n // Valid values: "python/pydantic", "typescript", "ruby/sorbet", "rest/openapi"\n output_type "python/pydantic"\n\n // Where the generated code will be saved (relative to baml_src/)\n output_dir "../baml/"\n\n // The version of the BAML package you have installed (e.g. same version as your baml-py or @boundaryml/baml).\n // The BAML VSCode extension version should also match this version.\n version "0.201.0"\n\n // Valid values: "sync", "async"\n // This controls what `b.FunctionName()` will be (sync or async).\n default_client_mode sync\n}\n',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_baml_files():
|
|
21
|
+
return _file_map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# ----------------------------------------------------------------------------
|
|
2
|
+
#
|
|
3
|
+
# Welcome to Baml! To use this generated code, please run the following:
|
|
4
|
+
#
|
|
5
|
+
# $ pip install baml
|
|
6
|
+
#
|
|
7
|
+
# ----------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
# This file was generated by BAML: please do not edit it. Instead, edit the
|
|
10
|
+
# BAML files and re-generate this code using: baml-cli generate
|
|
11
|
+
# baml-cli is available with the baml package.
|
|
12
|
+
|
|
13
|
+
import typing
|
|
14
|
+
import typing_extensions
|
|
15
|
+
|
|
16
|
+
from . import stream_types, types
|
|
17
|
+
from .runtime import DoNotUseDirectlyCallManager, BamlCallOptions
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class LlmResponseParser:
|
|
21
|
+
__options: DoNotUseDirectlyCallManager
|
|
22
|
+
|
|
23
|
+
def __init__(self, options: DoNotUseDirectlyCallManager):
|
|
24
|
+
self.__options = options
|
|
25
|
+
|
|
26
|
+
def ExtractCategories(
|
|
27
|
+
self,
|
|
28
|
+
llm_response: str,
|
|
29
|
+
baml_options: BamlCallOptions = {},
|
|
30
|
+
) -> types.DefaultContentPrediction:
|
|
31
|
+
result = self.__options.merge_options(baml_options).parse_response(
|
|
32
|
+
function_name="ExtractCategories", llm_response=llm_response, mode="request"
|
|
33
|
+
)
|
|
34
|
+
return typing.cast(types.DefaultContentPrediction, result)
|
|
35
|
+
|
|
36
|
+
def ExtractContentGraphGeneric(
|
|
37
|
+
self,
|
|
38
|
+
llm_response: str,
|
|
39
|
+
baml_options: BamlCallOptions = {},
|
|
40
|
+
) -> types.KnowledgeGraph:
|
|
41
|
+
result = self.__options.merge_options(baml_options).parse_response(
|
|
42
|
+
function_name="ExtractContentGraphGeneric", llm_response=llm_response, mode="request"
|
|
43
|
+
)
|
|
44
|
+
return typing.cast(types.KnowledgeGraph, result)
|
|
45
|
+
|
|
46
|
+
def ExtractDynamicContentGraph(
|
|
47
|
+
self,
|
|
48
|
+
llm_response: str,
|
|
49
|
+
baml_options: BamlCallOptions = {},
|
|
50
|
+
) -> types.DynamicKnowledgeGraph:
|
|
51
|
+
result = self.__options.merge_options(baml_options).parse_response(
|
|
52
|
+
function_name="ExtractDynamicContentGraph", llm_response=llm_response, mode="request"
|
|
53
|
+
)
|
|
54
|
+
return typing.cast(types.DynamicKnowledgeGraph, result)
|
|
55
|
+
|
|
56
|
+
def SummarizeCode(
|
|
57
|
+
self,
|
|
58
|
+
llm_response: str,
|
|
59
|
+
baml_options: BamlCallOptions = {},
|
|
60
|
+
) -> types.SummarizedCode:
|
|
61
|
+
result = self.__options.merge_options(baml_options).parse_response(
|
|
62
|
+
function_name="SummarizeCode", llm_response=llm_response, mode="request"
|
|
63
|
+
)
|
|
64
|
+
return typing.cast(types.SummarizedCode, result)
|
|
65
|
+
|
|
66
|
+
def SummarizeContent(
|
|
67
|
+
self,
|
|
68
|
+
llm_response: str,
|
|
69
|
+
baml_options: BamlCallOptions = {},
|
|
70
|
+
) -> types.SummarizedContent:
|
|
71
|
+
result = self.__options.merge_options(baml_options).parse_response(
|
|
72
|
+
function_name="SummarizeContent", llm_response=llm_response, mode="request"
|
|
73
|
+
)
|
|
74
|
+
return typing.cast(types.SummarizedContent, result)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class LlmStreamParser:
|
|
78
|
+
__options: DoNotUseDirectlyCallManager
|
|
79
|
+
|
|
80
|
+
def __init__(self, options: DoNotUseDirectlyCallManager):
|
|
81
|
+
self.__options = options
|
|
82
|
+
|
|
83
|
+
def ExtractCategories(
|
|
84
|
+
self,
|
|
85
|
+
llm_response: str,
|
|
86
|
+
baml_options: BamlCallOptions = {},
|
|
87
|
+
) -> stream_types.DefaultContentPrediction:
|
|
88
|
+
result = self.__options.merge_options(baml_options).parse_response(
|
|
89
|
+
function_name="ExtractCategories", llm_response=llm_response, mode="stream"
|
|
90
|
+
)
|
|
91
|
+
return typing.cast(stream_types.DefaultContentPrediction, result)
|
|
92
|
+
|
|
93
|
+
def ExtractContentGraphGeneric(
|
|
94
|
+
self,
|
|
95
|
+
llm_response: str,
|
|
96
|
+
baml_options: BamlCallOptions = {},
|
|
97
|
+
) -> stream_types.KnowledgeGraph:
|
|
98
|
+
result = self.__options.merge_options(baml_options).parse_response(
|
|
99
|
+
function_name="ExtractContentGraphGeneric", llm_response=llm_response, mode="stream"
|
|
100
|
+
)
|
|
101
|
+
return typing.cast(stream_types.KnowledgeGraph, result)
|
|
102
|
+
|
|
103
|
+
def ExtractDynamicContentGraph(
|
|
104
|
+
self,
|
|
105
|
+
llm_response: str,
|
|
106
|
+
baml_options: BamlCallOptions = {},
|
|
107
|
+
) -> stream_types.DynamicKnowledgeGraph:
|
|
108
|
+
result = self.__options.merge_options(baml_options).parse_response(
|
|
109
|
+
function_name="ExtractDynamicContentGraph", llm_response=llm_response, mode="stream"
|
|
110
|
+
)
|
|
111
|
+
return typing.cast(stream_types.DynamicKnowledgeGraph, result)
|
|
112
|
+
|
|
113
|
+
def SummarizeCode(
|
|
114
|
+
self,
|
|
115
|
+
llm_response: str,
|
|
116
|
+
baml_options: BamlCallOptions = {},
|
|
117
|
+
) -> stream_types.SummarizedCode:
|
|
118
|
+
result = self.__options.merge_options(baml_options).parse_response(
|
|
119
|
+
function_name="SummarizeCode", llm_response=llm_response, mode="stream"
|
|
120
|
+
)
|
|
121
|
+
return typing.cast(stream_types.SummarizedCode, result)
|
|
122
|
+
|
|
123
|
+
def SummarizeContent(
|
|
124
|
+
self,
|
|
125
|
+
llm_response: str,
|
|
126
|
+
baml_options: BamlCallOptions = {},
|
|
127
|
+
) -> stream_types.SummarizedContent:
|
|
128
|
+
result = self.__options.merge_options(baml_options).parse_response(
|
|
129
|
+
function_name="SummarizeContent", llm_response=llm_response, mode="stream"
|
|
130
|
+
)
|
|
131
|
+
return typing.cast(stream_types.SummarizedContent, result)
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# ----------------------------------------------------------------------------
|
|
2
|
+
#
|
|
3
|
+
# Welcome to Baml! To use this generated code, please run the following:
|
|
4
|
+
#
|
|
5
|
+
# $ pip install baml
|
|
6
|
+
#
|
|
7
|
+
# ----------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
# This file was generated by BAML: please do not edit it. Instead, edit the
|
|
10
|
+
# BAML files and re-generate this code using: baml-cli generate
|
|
11
|
+
# baml-cli is available with the baml package.
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import typing
|
|
15
|
+
import typing_extensions
|
|
16
|
+
|
|
17
|
+
import baml_py
|
|
18
|
+
|
|
19
|
+
from . import types, stream_types, type_builder
|
|
20
|
+
from .globals import (
|
|
21
|
+
DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME as __runtime__,
|
|
22
|
+
DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX as __ctx__manager__,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class BamlCallOptions(typing.TypedDict, total=False):
|
|
27
|
+
tb: typing_extensions.NotRequired[type_builder.TypeBuilder]
|
|
28
|
+
client_registry: typing_extensions.NotRequired[baml_py.baml_py.ClientRegistry]
|
|
29
|
+
env: typing_extensions.NotRequired[typing.Dict[str, typing.Optional[str]]]
|
|
30
|
+
collector: typing_extensions.NotRequired[
|
|
31
|
+
typing.Union[baml_py.baml_py.Collector, typing.List[baml_py.baml_py.Collector]]
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class _ResolvedBamlOptions:
|
|
36
|
+
tb: typing.Optional[baml_py.baml_py.TypeBuilder]
|
|
37
|
+
client_registry: typing.Optional[baml_py.baml_py.ClientRegistry]
|
|
38
|
+
collectors: typing.List[baml_py.baml_py.Collector]
|
|
39
|
+
env_vars: typing.Dict[str, str]
|
|
40
|
+
|
|
41
|
+
def __init__(
|
|
42
|
+
self,
|
|
43
|
+
tb: typing.Optional[baml_py.baml_py.TypeBuilder],
|
|
44
|
+
client_registry: typing.Optional[baml_py.baml_py.ClientRegistry],
|
|
45
|
+
collectors: typing.List[baml_py.baml_py.Collector],
|
|
46
|
+
env_vars: typing.Dict[str, str],
|
|
47
|
+
):
|
|
48
|
+
self.tb = tb
|
|
49
|
+
self.client_registry = client_registry
|
|
50
|
+
self.collectors = collectors
|
|
51
|
+
self.env_vars = env_vars
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class DoNotUseDirectlyCallManager:
|
|
55
|
+
def __init__(self, baml_options: BamlCallOptions):
|
|
56
|
+
self.__baml_options = baml_options
|
|
57
|
+
|
|
58
|
+
def __getstate__(self):
|
|
59
|
+
# Return state needed for pickling
|
|
60
|
+
return {"baml_options": self.__baml_options}
|
|
61
|
+
|
|
62
|
+
def __setstate__(self, state):
|
|
63
|
+
# Restore state from pickling
|
|
64
|
+
self.__baml_options = state["baml_options"]
|
|
65
|
+
|
|
66
|
+
def __resolve(self) -> _ResolvedBamlOptions:
|
|
67
|
+
tb = self.__baml_options.get("tb")
|
|
68
|
+
if tb is not None:
|
|
69
|
+
baml_tb = tb._tb # type: ignore (we know how to use this private attribute)
|
|
70
|
+
else:
|
|
71
|
+
baml_tb = None
|
|
72
|
+
client_registry = self.__baml_options.get("client_registry")
|
|
73
|
+
collector = self.__baml_options.get("collector")
|
|
74
|
+
collectors_as_list = (
|
|
75
|
+
collector
|
|
76
|
+
if isinstance(collector, list)
|
|
77
|
+
else [collector]
|
|
78
|
+
if collector is not None
|
|
79
|
+
else []
|
|
80
|
+
)
|
|
81
|
+
env_vars = os.environ.copy()
|
|
82
|
+
for k, v in self.__baml_options.get("env", {}).items():
|
|
83
|
+
if v is not None:
|
|
84
|
+
env_vars[k] = v
|
|
85
|
+
else:
|
|
86
|
+
env_vars.pop(k, None)
|
|
87
|
+
|
|
88
|
+
return _ResolvedBamlOptions(
|
|
89
|
+
baml_tb,
|
|
90
|
+
client_registry,
|
|
91
|
+
collectors_as_list,
|
|
92
|
+
env_vars,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
def merge_options(self, options: BamlCallOptions) -> "DoNotUseDirectlyCallManager":
|
|
96
|
+
return DoNotUseDirectlyCallManager({**self.__baml_options, **options})
|
|
97
|
+
|
|
98
|
+
async def call_function_async(
|
|
99
|
+
self, *, function_name: str, args: typing.Dict[str, typing.Any]
|
|
100
|
+
) -> baml_py.baml_py.FunctionResult:
|
|
101
|
+
resolved_options = self.__resolve()
|
|
102
|
+
return await __runtime__.call_function(
|
|
103
|
+
function_name,
|
|
104
|
+
args,
|
|
105
|
+
# ctx
|
|
106
|
+
__ctx__manager__.clone_context(),
|
|
107
|
+
# tb
|
|
108
|
+
resolved_options.tb,
|
|
109
|
+
# cr
|
|
110
|
+
resolved_options.client_registry,
|
|
111
|
+
# collectors
|
|
112
|
+
resolved_options.collectors,
|
|
113
|
+
# env_vars
|
|
114
|
+
resolved_options.env_vars,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def call_function_sync(
|
|
118
|
+
self, *, function_name: str, args: typing.Dict[str, typing.Any]
|
|
119
|
+
) -> baml_py.baml_py.FunctionResult:
|
|
120
|
+
resolved_options = self.__resolve()
|
|
121
|
+
ctx = __ctx__manager__.get()
|
|
122
|
+
return __runtime__.call_function_sync(
|
|
123
|
+
function_name,
|
|
124
|
+
args,
|
|
125
|
+
# ctx
|
|
126
|
+
ctx,
|
|
127
|
+
# tb
|
|
128
|
+
resolved_options.tb,
|
|
129
|
+
# cr
|
|
130
|
+
resolved_options.client_registry,
|
|
131
|
+
# collectors
|
|
132
|
+
resolved_options.collectors,
|
|
133
|
+
# env_vars
|
|
134
|
+
resolved_options.env_vars,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
def create_async_stream(
|
|
138
|
+
self,
|
|
139
|
+
*,
|
|
140
|
+
function_name: str,
|
|
141
|
+
args: typing.Dict[str, typing.Any],
|
|
142
|
+
) -> typing.Tuple[baml_py.baml_py.RuntimeContextManager, baml_py.baml_py.FunctionResultStream]:
|
|
143
|
+
resolved_options = self.__resolve()
|
|
144
|
+
ctx = __ctx__manager__.clone_context()
|
|
145
|
+
result = __runtime__.stream_function(
|
|
146
|
+
function_name,
|
|
147
|
+
args,
|
|
148
|
+
# this is always None, we set this later!
|
|
149
|
+
# on_event
|
|
150
|
+
None,
|
|
151
|
+
# ctx
|
|
152
|
+
ctx,
|
|
153
|
+
# tb
|
|
154
|
+
resolved_options.tb,
|
|
155
|
+
# cr
|
|
156
|
+
resolved_options.client_registry,
|
|
157
|
+
# collectors
|
|
158
|
+
resolved_options.collectors,
|
|
159
|
+
# env_vars
|
|
160
|
+
resolved_options.env_vars,
|
|
161
|
+
)
|
|
162
|
+
return ctx, result
|
|
163
|
+
|
|
164
|
+
def create_sync_stream(
|
|
165
|
+
self,
|
|
166
|
+
*,
|
|
167
|
+
function_name: str,
|
|
168
|
+
args: typing.Dict[str, typing.Any],
|
|
169
|
+
) -> typing.Tuple[
|
|
170
|
+
baml_py.baml_py.RuntimeContextManager, baml_py.baml_py.SyncFunctionResultStream
|
|
171
|
+
]:
|
|
172
|
+
resolved_options = self.__resolve()
|
|
173
|
+
ctx = __ctx__manager__.get()
|
|
174
|
+
result = __runtime__.stream_function_sync(
|
|
175
|
+
function_name,
|
|
176
|
+
args,
|
|
177
|
+
# this is always None, we set this later!
|
|
178
|
+
# on_event
|
|
179
|
+
None,
|
|
180
|
+
# ctx
|
|
181
|
+
ctx,
|
|
182
|
+
# tb
|
|
183
|
+
resolved_options.tb,
|
|
184
|
+
# cr
|
|
185
|
+
resolved_options.client_registry,
|
|
186
|
+
# collectors
|
|
187
|
+
resolved_options.collectors,
|
|
188
|
+
# env_vars
|
|
189
|
+
resolved_options.env_vars,
|
|
190
|
+
)
|
|
191
|
+
return ctx, result
|
|
192
|
+
|
|
193
|
+
async def create_http_request_async(
|
|
194
|
+
self,
|
|
195
|
+
*,
|
|
196
|
+
function_name: str,
|
|
197
|
+
args: typing.Dict[str, typing.Any],
|
|
198
|
+
mode: typing_extensions.Literal["stream", "request"],
|
|
199
|
+
) -> baml_py.baml_py.HTTPRequest:
|
|
200
|
+
resolved_options = self.__resolve()
|
|
201
|
+
return await __runtime__.build_request(
|
|
202
|
+
function_name,
|
|
203
|
+
args,
|
|
204
|
+
# ctx
|
|
205
|
+
__ctx__manager__.clone_context(),
|
|
206
|
+
# tb
|
|
207
|
+
resolved_options.tb,
|
|
208
|
+
# cr
|
|
209
|
+
resolved_options.client_registry,
|
|
210
|
+
# env_vars
|
|
211
|
+
resolved_options.env_vars,
|
|
212
|
+
# is_stream
|
|
213
|
+
mode == "stream",
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
def create_http_request_sync(
|
|
217
|
+
self,
|
|
218
|
+
*,
|
|
219
|
+
function_name: str,
|
|
220
|
+
args: typing.Dict[str, typing.Any],
|
|
221
|
+
mode: typing_extensions.Literal["stream", "request"],
|
|
222
|
+
) -> baml_py.baml_py.HTTPRequest:
|
|
223
|
+
resolved_options = self.__resolve()
|
|
224
|
+
return __runtime__.build_request_sync(
|
|
225
|
+
function_name,
|
|
226
|
+
args,
|
|
227
|
+
# ctx
|
|
228
|
+
__ctx__manager__.get(),
|
|
229
|
+
# tb
|
|
230
|
+
resolved_options.tb,
|
|
231
|
+
# cr
|
|
232
|
+
resolved_options.client_registry,
|
|
233
|
+
# env_vars
|
|
234
|
+
resolved_options.env_vars,
|
|
235
|
+
# is_stream
|
|
236
|
+
mode == "stream",
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
def parse_response(
|
|
240
|
+
self,
|
|
241
|
+
*,
|
|
242
|
+
function_name: str,
|
|
243
|
+
llm_response: str,
|
|
244
|
+
mode: typing_extensions.Literal["stream", "request"],
|
|
245
|
+
) -> typing.Any:
|
|
246
|
+
resolved_options = self.__resolve()
|
|
247
|
+
return __runtime__.parse_llm_response(
|
|
248
|
+
function_name,
|
|
249
|
+
llm_response,
|
|
250
|
+
# enum_module
|
|
251
|
+
types,
|
|
252
|
+
# cls_module
|
|
253
|
+
types,
|
|
254
|
+
# partial_cls_module
|
|
255
|
+
stream_types,
|
|
256
|
+
# allow_partials
|
|
257
|
+
mode == "stream",
|
|
258
|
+
# ctx
|
|
259
|
+
__ctx__manager__.get(),
|
|
260
|
+
# tb
|
|
261
|
+
resolved_options.tb,
|
|
262
|
+
# cr
|
|
263
|
+
resolved_options.client_registry,
|
|
264
|
+
# env_vars
|
|
265
|
+
resolved_options.env_vars,
|
|
266
|
+
)
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# ----------------------------------------------------------------------------
|
|
2
|
+
#
|
|
3
|
+
# Welcome to Baml! To use this generated code, please run the following:
|
|
4
|
+
#
|
|
5
|
+
# $ pip install baml
|
|
6
|
+
#
|
|
7
|
+
# ----------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
# This file was generated by BAML: please do not edit it. Instead, edit the
|
|
10
|
+
# BAML files and re-generate this code using: baml-cli generate
|
|
11
|
+
# baml-cli is available with the baml package.
|
|
12
|
+
|
|
13
|
+
import typing
|
|
14
|
+
import typing_extensions
|
|
15
|
+
from pydantic import BaseModel, ConfigDict
|
|
16
|
+
|
|
17
|
+
import baml_py
|
|
18
|
+
|
|
19
|
+
from . import types
|
|
20
|
+
|
|
21
|
+
StreamStateValueT = typing.TypeVar("StreamStateValueT")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class StreamState(BaseModel, typing.Generic[StreamStateValueT]):
|
|
25
|
+
value: StreamStateValueT
|
|
26
|
+
state: typing_extensions.Literal["Pending", "Incomplete", "Complete"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# #########################################################################
|
|
30
|
+
# Generated classes (17)
|
|
31
|
+
# #########################################################################
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class AudioContent(BaseModel):
|
|
35
|
+
type: typing.Optional[str] = None
|
|
36
|
+
subclass: typing.List[str]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ContentLabel(BaseModel):
|
|
40
|
+
content_type: typing.Optional[typing.Union[str, str, str, str, str, str, str]] = None
|
|
41
|
+
type: typing.Optional[str] = None
|
|
42
|
+
subclass: typing.List[str]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class DefaultContentPrediction(BaseModel):
|
|
46
|
+
label: typing.Optional["ContentLabel"] = None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class DynamicKnowledgeGraph(BaseModel):
|
|
50
|
+
model_config = ConfigDict(extra="allow")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class Edge(BaseModel):
|
|
54
|
+
# doc string for edge
|
|
55
|
+
# doc string for source_node_id
|
|
56
|
+
|
|
57
|
+
source_node_id: typing.Optional[str] = None
|
|
58
|
+
target_node_id: typing.Optional[str] = None
|
|
59
|
+
relationship_name: typing.Optional[str] = None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ImageContent(BaseModel):
|
|
63
|
+
type: typing.Optional[str] = None
|
|
64
|
+
subclass: typing.List[str]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class KnowledgeGraph(BaseModel):
|
|
68
|
+
nodes: typing.List["types.Node"]
|
|
69
|
+
edges: typing.List["Edge"]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class Model3DContent(BaseModel):
|
|
73
|
+
type: typing.Optional[str] = None
|
|
74
|
+
subclass: typing.List[str]
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class MultimediaContent(BaseModel):
|
|
78
|
+
type: typing.Optional[str] = None
|
|
79
|
+
subclass: typing.List[str]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class Node(BaseModel):
|
|
83
|
+
model_config = ConfigDict(extra="allow")
|
|
84
|
+
id: typing.Optional[str] = None
|
|
85
|
+
name: typing.Optional[str] = None
|
|
86
|
+
type: typing.Optional[str] = None
|
|
87
|
+
description: typing.Optional[str] = None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class ProceduralContent(BaseModel):
|
|
91
|
+
type: typing.Optional[str] = None
|
|
92
|
+
subclass: typing.List[str]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class SummarizedClass(BaseModel):
|
|
96
|
+
name: typing.Optional[str] = None
|
|
97
|
+
description: typing.Optional[str] = None
|
|
98
|
+
methods: typing.Optional[typing.List["SummarizedFunction"]] = None
|
|
99
|
+
decorators: typing.Optional[typing.List[str]] = None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class SummarizedCode(BaseModel):
|
|
103
|
+
high_level_summary: typing.Optional[str] = None
|
|
104
|
+
key_features: typing.List[str]
|
|
105
|
+
imports: typing.List[str]
|
|
106
|
+
constants: typing.List[str]
|
|
107
|
+
classes: typing.List["SummarizedClass"]
|
|
108
|
+
functions: typing.List["SummarizedFunction"]
|
|
109
|
+
workflow_description: typing.Optional[str] = None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class SummarizedContent(BaseModel):
|
|
113
|
+
summary: typing.Optional[str] = None
|
|
114
|
+
description: typing.Optional[str] = None
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class SummarizedFunction(BaseModel):
|
|
118
|
+
name: typing.Optional[str] = None
|
|
119
|
+
description: typing.Optional[str] = None
|
|
120
|
+
inputs: typing.Optional[typing.List[str]] = None
|
|
121
|
+
outputs: typing.Optional[typing.List[str]] = None
|
|
122
|
+
decorators: typing.Optional[typing.List[str]] = None
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class TextContent(BaseModel):
|
|
126
|
+
type: typing.Optional[str] = None
|
|
127
|
+
subclass: typing.List[str]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class VideoContent(BaseModel):
|
|
131
|
+
type: typing.Optional[str] = None
|
|
132
|
+
subclass: typing.List[str]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
# #########################################################################
|
|
136
|
+
# Generated type aliases (0)
|
|
137
|
+
# #########################################################################
|