diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/__init__.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/__init__.py index c4fe2bc85..85dfab90c 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/__init__.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/__init__.py @@ -13,9 +13,9 @@ __version__ = "0.201.0" try: - from baml_py.safe_import import EnsureBamlPyImport + from baml_py.safe_import import EnsureBamlPyImport except ImportError: - raise ImportError(f"""Update to baml-py required. + raise ImportError(f"""Update to baml-py required. Version of baml_client generator (see generators.baml): {__version__} Please upgrade baml-py to version "{__version__}". @@ -31,16 +31,15 @@ https://boundaryml.com/discord with EnsureBamlPyImport(__version__) as e: - e.raise_if_incompatible_version(__version__) + e.raise_if_incompatible_version(__version__) - from . import types - from . import tracing - from . import stream_types - from . import config - from .config import reset_baml_env_vars - - from .sync_client import b - + from . import types + from . import tracing + from . import stream_types + from . import config + from .config import reset_baml_env_vars + + from .sync_client import b # FOR LEGACY COMPATIBILITY, expose "partial_types" as an alias for "stream_types" @@ -48,11 +47,11 @@ with EnsureBamlPyImport(__version__) as e: partial_types = stream_types __all__ = [ - "b", - "stream_types", - "partial_types", - "tracing", - "types", - "reset_baml_env_vars", - "config", -] \ No newline at end of file + "b", + "stream_types", + "partial_types", + "tracing", + "types", + "reset_baml_env_vars", + "config", +] diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/async_client.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/async_client.py index 18b24abdd..faf00c836 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/async_client.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/async_client.py @@ -36,10 +36,13 @@ class BamlAsyncClient: self.__llm_response_parser = LlmResponseParser(options) self.__llm_stream_parser = LlmStreamParser(options) - def with_options(self, + def with_options( + self, tb: typing.Optional[type_builder.TypeBuilder] = None, client_registry: typing.Optional[baml_py.baml_py.ClientRegistry] = None, - collector: typing.Optional[typing.Union[baml_py.baml_py.Collector, typing.List[baml_py.baml_py.Collector]]] = None, + collector: typing.Optional[ + typing.Union[baml_py.baml_py.Collector, typing.List[baml_py.baml_py.Collector]] + ] = None, env: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None, ) -> "BamlAsyncClient": options: BamlCallOptions = {} @@ -55,60 +58,124 @@ class BamlAsyncClient: @property def stream(self): - return self.__stream_client + return self.__stream_client @property def request(self): - return self.__http_request + return self.__http_request @property def stream_request(self): - return self.__http_stream_request + return self.__http_stream_request @property def parse(self): - return self.__llm_response_parser + return self.__llm_response_parser @property def parse_stream(self): - return self.__llm_stream_parser - - async def ExtractCategories(self, content: str, + return self.__llm_stream_parser + + async def ExtractCategories( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> types.DefaultContentPrediction: - result = await self.__options.merge_options(baml_options).call_function_async(function_name="ExtractCategories", args={ - "content": content, - }) - return typing.cast(types.DefaultContentPrediction, result.cast_to(types, types, stream_types, False, __runtime__)) - async def ExtractContentGraphGeneric(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + result = await self.__options.merge_options(baml_options).call_function_async( + function_name="ExtractCategories", + args={ + "content": content, + }, + ) + return typing.cast( + types.DefaultContentPrediction, + result.cast_to(types, types, stream_types, False, __runtime__), + ) + + async def ExtractContentGraphGeneric( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> types.KnowledgeGraph: - result = await self.__options.merge_options(baml_options).call_function_async(function_name="ExtractContentGraphGeneric", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }) - return typing.cast(types.KnowledgeGraph, result.cast_to(types, types, stream_types, False, __runtime__)) - async def ExtractDynamicContentGraph(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + result = await self.__options.merge_options(baml_options).call_function_async( + function_name="ExtractContentGraphGeneric", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + ) + return typing.cast( + types.KnowledgeGraph, result.cast_to(types, types, stream_types, False, __runtime__) + ) + + async def ExtractDynamicContentGraph( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> types.DynamicKnowledgeGraph: - result = await self.__options.merge_options(baml_options).call_function_async(function_name="ExtractDynamicContentGraph", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }) - return typing.cast(types.DynamicKnowledgeGraph, result.cast_to(types, types, stream_types, False, __runtime__)) - async def SummarizeCode(self, content: str, + result = await self.__options.merge_options(baml_options).call_function_async( + function_name="ExtractDynamicContentGraph", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + ) + return typing.cast( + types.DynamicKnowledgeGraph, + result.cast_to(types, types, stream_types, False, __runtime__), + ) + + async def SummarizeCode( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> types.SummarizedCode: - result = await self.__options.merge_options(baml_options).call_function_async(function_name="SummarizeCode", args={ - "content": content, - }) - return typing.cast(types.SummarizedCode, result.cast_to(types, types, stream_types, False, __runtime__)) - async def SummarizeContent(self, content: str, + result = await self.__options.merge_options(baml_options).call_function_async( + function_name="SummarizeCode", + args={ + "content": content, + }, + ) + return typing.cast( + types.SummarizedCode, result.cast_to(types, types, stream_types, False, __runtime__) + ) + + async def SummarizeContent( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> types.SummarizedContent: - result = await self.__options.merge_options(baml_options).call_function_async(function_name="SummarizeContent", args={ - "content": content, - }) - return typing.cast(types.SummarizedContent, result.cast_to(types, types, stream_types, False, __runtime__)) - + result = await self.__options.merge_options(baml_options).call_function_async( + function_name="SummarizeContent", + args={ + "content": content, + }, + ) + return typing.cast( + types.SummarizedContent, result.cast_to(types, types, stream_types, False, __runtime__) + ) class BamlStreamClient: @@ -117,67 +184,149 @@ class BamlStreamClient: def __init__(self, options: DoNotUseDirectlyCallManager): self.__options = options - def ExtractCategories(self, content: str, + def ExtractCategories( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.BamlStream[stream_types.DefaultContentPrediction, types.DefaultContentPrediction]: - ctx, result = self.__options.merge_options(baml_options).create_async_stream(function_name="ExtractCategories", args={ - "content": content, - }) - return baml_py.BamlStream[stream_types.DefaultContentPrediction, types.DefaultContentPrediction]( - result, - lambda x: typing.cast(stream_types.DefaultContentPrediction, x.cast_to(types, types, stream_types, True, __runtime__)), - lambda x: typing.cast(types.DefaultContentPrediction, x.cast_to(types, types, stream_types, False, __runtime__)), - ctx, + ctx, result = self.__options.merge_options(baml_options).create_async_stream( + function_name="ExtractCategories", + args={ + "content": content, + }, ) - def ExtractContentGraphGeneric(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + return baml_py.BamlStream[ + stream_types.DefaultContentPrediction, types.DefaultContentPrediction + ]( + result, + lambda x: typing.cast( + stream_types.DefaultContentPrediction, + x.cast_to(types, types, stream_types, True, __runtime__), + ), + lambda x: typing.cast( + types.DefaultContentPrediction, + x.cast_to(types, types, stream_types, False, __runtime__), + ), + ctx, + ) + + def ExtractContentGraphGeneric( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> baml_py.BamlStream[stream_types.KnowledgeGraph, types.KnowledgeGraph]: - ctx, result = self.__options.merge_options(baml_options).create_async_stream(function_name="ExtractContentGraphGeneric", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }) - return baml_py.BamlStream[stream_types.KnowledgeGraph, types.KnowledgeGraph]( - result, - lambda x: typing.cast(stream_types.KnowledgeGraph, x.cast_to(types, types, stream_types, True, __runtime__)), - lambda x: typing.cast(types.KnowledgeGraph, x.cast_to(types, types, stream_types, False, __runtime__)), - ctx, + ctx, result = self.__options.merge_options(baml_options).create_async_stream( + function_name="ExtractContentGraphGeneric", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, ) - def ExtractDynamicContentGraph(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + return baml_py.BamlStream[stream_types.KnowledgeGraph, types.KnowledgeGraph]( + result, + lambda x: typing.cast( + stream_types.KnowledgeGraph, + x.cast_to(types, types, stream_types, True, __runtime__), + ), + lambda x: typing.cast( + types.KnowledgeGraph, x.cast_to(types, types, stream_types, False, __runtime__) + ), + ctx, + ) + + def ExtractDynamicContentGraph( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> baml_py.BamlStream[stream_types.DynamicKnowledgeGraph, types.DynamicKnowledgeGraph]: - ctx, result = self.__options.merge_options(baml_options).create_async_stream(function_name="ExtractDynamicContentGraph", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }) - return baml_py.BamlStream[stream_types.DynamicKnowledgeGraph, types.DynamicKnowledgeGraph]( - result, - lambda x: typing.cast(stream_types.DynamicKnowledgeGraph, x.cast_to(types, types, stream_types, True, __runtime__)), - lambda x: typing.cast(types.DynamicKnowledgeGraph, x.cast_to(types, types, stream_types, False, __runtime__)), - ctx, + ctx, result = self.__options.merge_options(baml_options).create_async_stream( + function_name="ExtractDynamicContentGraph", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, ) - def SummarizeCode(self, content: str, + return baml_py.BamlStream[stream_types.DynamicKnowledgeGraph, types.DynamicKnowledgeGraph]( + result, + lambda x: typing.cast( + stream_types.DynamicKnowledgeGraph, + x.cast_to(types, types, stream_types, True, __runtime__), + ), + lambda x: typing.cast( + types.DynamicKnowledgeGraph, + x.cast_to(types, types, stream_types, False, __runtime__), + ), + ctx, + ) + + def SummarizeCode( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.BamlStream[stream_types.SummarizedCode, types.SummarizedCode]: - ctx, result = self.__options.merge_options(baml_options).create_async_stream(function_name="SummarizeCode", args={ - "content": content, - }) - return baml_py.BamlStream[stream_types.SummarizedCode, types.SummarizedCode]( - result, - lambda x: typing.cast(stream_types.SummarizedCode, x.cast_to(types, types, stream_types, True, __runtime__)), - lambda x: typing.cast(types.SummarizedCode, x.cast_to(types, types, stream_types, False, __runtime__)), - ctx, + ctx, result = self.__options.merge_options(baml_options).create_async_stream( + function_name="SummarizeCode", + args={ + "content": content, + }, ) - def SummarizeContent(self, content: str, + return baml_py.BamlStream[stream_types.SummarizedCode, types.SummarizedCode]( + result, + lambda x: typing.cast( + stream_types.SummarizedCode, + x.cast_to(types, types, stream_types, True, __runtime__), + ), + lambda x: typing.cast( + types.SummarizedCode, x.cast_to(types, types, stream_types, False, __runtime__) + ), + ctx, + ) + + def SummarizeContent( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.BamlStream[stream_types.SummarizedContent, types.SummarizedContent]: - ctx, result = self.__options.merge_options(baml_options).create_async_stream(function_name="SummarizeContent", args={ - "content": content, - }) - return baml_py.BamlStream[stream_types.SummarizedContent, types.SummarizedContent]( - result, - lambda x: typing.cast(stream_types.SummarizedContent, x.cast_to(types, types, stream_types, True, __runtime__)), - lambda x: typing.cast(types.SummarizedContent, x.cast_to(types, types, stream_types, False, __runtime__)), - ctx, + ctx, result = self.__options.merge_options(baml_options).create_async_stream( + function_name="SummarizeContent", + args={ + "content": content, + }, ) - + return baml_py.BamlStream[stream_types.SummarizedContent, types.SummarizedContent]( + result, + lambda x: typing.cast( + stream_types.SummarizedContent, + x.cast_to(types, types, stream_types, True, __runtime__), + ), + lambda x: typing.cast( + types.SummarizedContent, x.cast_to(types, types, stream_types, False, __runtime__) + ), + ctx, + ) + class BamlHttpRequestClient: __options: DoNotUseDirectlyCallManager @@ -185,42 +334,100 @@ class BamlHttpRequestClient: def __init__(self, options: DoNotUseDirectlyCallManager): self.__options = options - async def ExtractCategories(self, content: str, + async def ExtractCategories( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = await self.__options.merge_options(baml_options).create_http_request_async(function_name="ExtractCategories", args={ - "content": content, - }, mode="request") + result = await self.__options.merge_options(baml_options).create_http_request_async( + function_name="ExtractCategories", + args={ + "content": content, + }, + mode="request", + ) return result - async def ExtractContentGraphGeneric(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + + async def ExtractContentGraphGeneric( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = await self.__options.merge_options(baml_options).create_http_request_async(function_name="ExtractContentGraphGeneric", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }, mode="request") + result = await self.__options.merge_options(baml_options).create_http_request_async( + function_name="ExtractContentGraphGeneric", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + mode="request", + ) return result - async def ExtractDynamicContentGraph(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + + async def ExtractDynamicContentGraph( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = await self.__options.merge_options(baml_options).create_http_request_async(function_name="ExtractDynamicContentGraph", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }, mode="request") + result = await self.__options.merge_options(baml_options).create_http_request_async( + function_name="ExtractDynamicContentGraph", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + mode="request", + ) return result - async def SummarizeCode(self, content: str, + + async def SummarizeCode( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = await self.__options.merge_options(baml_options).create_http_request_async(function_name="SummarizeCode", args={ - "content": content, - }, mode="request") + result = await self.__options.merge_options(baml_options).create_http_request_async( + function_name="SummarizeCode", + args={ + "content": content, + }, + mode="request", + ) return result - async def SummarizeContent(self, content: str, + + async def SummarizeContent( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = await self.__options.merge_options(baml_options).create_http_request_async(function_name="SummarizeContent", args={ - "content": content, - }, mode="request") + result = await self.__options.merge_options(baml_options).create_http_request_async( + function_name="SummarizeContent", + args={ + "content": content, + }, + mode="request", + ) return result - + class BamlHttpStreamRequestClient: __options: DoNotUseDirectlyCallManager @@ -228,41 +435,99 @@ class BamlHttpStreamRequestClient: def __init__(self, options: DoNotUseDirectlyCallManager): self.__options = options - async def ExtractCategories(self, content: str, + async def ExtractCategories( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = await self.__options.merge_options(baml_options).create_http_request_async(function_name="ExtractCategories", args={ - "content": content, - }, mode="stream") + result = await self.__options.merge_options(baml_options).create_http_request_async( + function_name="ExtractCategories", + args={ + "content": content, + }, + mode="stream", + ) return result - async def ExtractContentGraphGeneric(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, - baml_options: BamlCallOptions = {}, - ) -> baml_py.baml_py.HTTPRequest: - result = await self.__options.merge_options(baml_options).create_http_request_async(function_name="ExtractContentGraphGeneric", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }, mode="stream") - return result - async def ExtractDynamicContentGraph(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, - baml_options: BamlCallOptions = {}, - ) -> baml_py.baml_py.HTTPRequest: - result = await self.__options.merge_options(baml_options).create_http_request_async(function_name="ExtractDynamicContentGraph", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }, mode="stream") - return result - async def SummarizeCode(self, content: str, - baml_options: BamlCallOptions = {}, - ) -> baml_py.baml_py.HTTPRequest: - result = await self.__options.merge_options(baml_options).create_http_request_async(function_name="SummarizeCode", args={ - "content": content, - }, mode="stream") - return result - async def SummarizeContent(self, content: str, - baml_options: BamlCallOptions = {}, - ) -> baml_py.baml_py.HTTPRequest: - result = await self.__options.merge_options(baml_options).create_http_request_async(function_name="SummarizeContent", args={ - "content": content, - }, mode="stream") - return result - -b = BamlAsyncClient(DoNotUseDirectlyCallManager({})) \ No newline at end of file + async def ExtractContentGraphGeneric( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, + baml_options: BamlCallOptions = {}, + ) -> baml_py.baml_py.HTTPRequest: + result = await self.__options.merge_options(baml_options).create_http_request_async( + function_name="ExtractContentGraphGeneric", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + mode="stream", + ) + return result + + async def ExtractDynamicContentGraph( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, + baml_options: BamlCallOptions = {}, + ) -> baml_py.baml_py.HTTPRequest: + result = await self.__options.merge_options(baml_options).create_http_request_async( + function_name="ExtractDynamicContentGraph", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + mode="stream", + ) + return result + + async def SummarizeCode( + self, + content: str, + baml_options: BamlCallOptions = {}, + ) -> baml_py.baml_py.HTTPRequest: + result = await self.__options.merge_options(baml_options).create_http_request_async( + function_name="SummarizeCode", + args={ + "content": content, + }, + mode="stream", + ) + return result + + async def SummarizeContent( + self, + content: str, + baml_options: BamlCallOptions = {}, + ) -> baml_py.baml_py.HTTPRequest: + result = await self.__options.merge_options(baml_options).create_http_request_async( + function_name="SummarizeContent", + args={ + "content": content, + }, + mode="stream", + ) + return result + + +b = BamlAsyncClient(DoNotUseDirectlyCallManager({})) diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/globals.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/globals.py index 769e055bb..7ef10535c 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/globals.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/globals.py @@ -19,17 +19,19 @@ from .inlinedbaml import get_baml_files from typing import Dict DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME = BamlRuntime.from_files( - "baml_src", - get_baml_files(), - os.environ.copy() + "baml_src", get_baml_files(), os.environ.copy() ) -DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX = BamlCtxManager(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME) +DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX = BamlCtxManager( + DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME +) + def reset_baml_env_vars(env_vars: Dict[str, str]): warnings.warn( "reset_baml_env_vars is deprecated and should be removed. Environment variables are now lazily loaded on each function call", DeprecationWarning, - stacklevel=2 + stacklevel=2, ) + __all__ = [] diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/inlinedbaml.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/inlinedbaml.py index 8eee28982..a03afa95d 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/inlinedbaml.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/inlinedbaml.py @@ -11,11 +11,11 @@ # baml-cli is available with the baml package. _file_map = { - - "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", - "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 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}", - "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", + "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', + "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 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}', + "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', } + def get_baml_files(): - return _file_map \ No newline at end of file + return _file_map diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/parser.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/parser.py index 845ec4b68..d98844e9e 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/parser.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/parser.py @@ -16,6 +16,7 @@ import typing_extensions from . import stream_types, types from .runtime import DoNotUseDirectlyCallManager, BamlCallOptions + class LlmResponseParser: __options: DoNotUseDirectlyCallManager @@ -23,36 +24,55 @@ class LlmResponseParser: self.__options = options def ExtractCategories( - self, llm_response: str, baml_options: BamlCallOptions = {}, + self, + llm_response: str, + baml_options: BamlCallOptions = {}, ) -> types.DefaultContentPrediction: - result = self.__options.merge_options(baml_options).parse_response(function_name="ExtractCategories", llm_response=llm_response, mode="request") + result = self.__options.merge_options(baml_options).parse_response( + function_name="ExtractCategories", llm_response=llm_response, mode="request" + ) return typing.cast(types.DefaultContentPrediction, result) def ExtractContentGraphGeneric( - self, llm_response: str, baml_options: BamlCallOptions = {}, + self, + llm_response: str, + baml_options: BamlCallOptions = {}, ) -> types.KnowledgeGraph: - result = self.__options.merge_options(baml_options).parse_response(function_name="ExtractContentGraphGeneric", llm_response=llm_response, mode="request") + result = self.__options.merge_options(baml_options).parse_response( + function_name="ExtractContentGraphGeneric", llm_response=llm_response, mode="request" + ) return typing.cast(types.KnowledgeGraph, result) def ExtractDynamicContentGraph( - self, llm_response: str, baml_options: BamlCallOptions = {}, + self, + llm_response: str, + baml_options: BamlCallOptions = {}, ) -> types.DynamicKnowledgeGraph: - result = self.__options.merge_options(baml_options).parse_response(function_name="ExtractDynamicContentGraph", llm_response=llm_response, mode="request") + result = self.__options.merge_options(baml_options).parse_response( + function_name="ExtractDynamicContentGraph", llm_response=llm_response, mode="request" + ) return typing.cast(types.DynamicKnowledgeGraph, result) def SummarizeCode( - self, llm_response: str, baml_options: BamlCallOptions = {}, + self, + llm_response: str, + baml_options: BamlCallOptions = {}, ) -> types.SummarizedCode: - result = self.__options.merge_options(baml_options).parse_response(function_name="SummarizeCode", llm_response=llm_response, mode="request") + result = self.__options.merge_options(baml_options).parse_response( + function_name="SummarizeCode", llm_response=llm_response, mode="request" + ) return typing.cast(types.SummarizedCode, result) def SummarizeContent( - self, llm_response: str, baml_options: BamlCallOptions = {}, + self, + llm_response: str, + baml_options: BamlCallOptions = {}, ) -> types.SummarizedContent: - result = self.__options.merge_options(baml_options).parse_response(function_name="SummarizeContent", llm_response=llm_response, mode="request") + result = self.__options.merge_options(baml_options).parse_response( + function_name="SummarizeContent", llm_response=llm_response, mode="request" + ) return typing.cast(types.SummarizedContent, result) - class LlmStreamParser: __options: DoNotUseDirectlyCallManager @@ -61,33 +81,51 @@ class LlmStreamParser: self.__options = options def ExtractCategories( - self, llm_response: str, baml_options: BamlCallOptions = {}, + self, + llm_response: str, + baml_options: BamlCallOptions = {}, ) -> stream_types.DefaultContentPrediction: - result = self.__options.merge_options(baml_options).parse_response(function_name="ExtractCategories", llm_response=llm_response, mode="stream") + result = self.__options.merge_options(baml_options).parse_response( + function_name="ExtractCategories", llm_response=llm_response, mode="stream" + ) return typing.cast(stream_types.DefaultContentPrediction, result) def ExtractContentGraphGeneric( - self, llm_response: str, baml_options: BamlCallOptions = {}, + self, + llm_response: str, + baml_options: BamlCallOptions = {}, ) -> stream_types.KnowledgeGraph: - result = self.__options.merge_options(baml_options).parse_response(function_name="ExtractContentGraphGeneric", llm_response=llm_response, mode="stream") + result = self.__options.merge_options(baml_options).parse_response( + function_name="ExtractContentGraphGeneric", llm_response=llm_response, mode="stream" + ) return typing.cast(stream_types.KnowledgeGraph, result) def ExtractDynamicContentGraph( - self, llm_response: str, baml_options: BamlCallOptions = {}, + self, + llm_response: str, + baml_options: BamlCallOptions = {}, ) -> stream_types.DynamicKnowledgeGraph: - result = self.__options.merge_options(baml_options).parse_response(function_name="ExtractDynamicContentGraph", llm_response=llm_response, mode="stream") + result = self.__options.merge_options(baml_options).parse_response( + function_name="ExtractDynamicContentGraph", llm_response=llm_response, mode="stream" + ) return typing.cast(stream_types.DynamicKnowledgeGraph, result) def SummarizeCode( - self, llm_response: str, baml_options: BamlCallOptions = {}, + self, + llm_response: str, + baml_options: BamlCallOptions = {}, ) -> stream_types.SummarizedCode: - result = self.__options.merge_options(baml_options).parse_response(function_name="SummarizeCode", llm_response=llm_response, mode="stream") + result = self.__options.merge_options(baml_options).parse_response( + function_name="SummarizeCode", llm_response=llm_response, mode="stream" + ) return typing.cast(stream_types.SummarizedCode, result) def SummarizeContent( - self, llm_response: str, baml_options: BamlCallOptions = {}, + self, + llm_response: str, + baml_options: BamlCallOptions = {}, ) -> stream_types.SummarizedContent: - result = self.__options.merge_options(baml_options).parse_response(function_name="SummarizeContent", llm_response=llm_response, mode="stream") + result = self.__options.merge_options(baml_options).parse_response( + function_name="SummarizeContent", llm_response=llm_response, mode="stream" + ) return typing.cast(stream_types.SummarizedContent, result) - - \ No newline at end of file diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/runtime.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/runtime.py index c94bb950e..1955e5c14 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/runtime.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/runtime.py @@ -17,7 +17,10 @@ import typing_extensions import baml_py from . import types, stream_types, type_builder -from .globals import DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME as __runtime__, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX as __ctx__manager__ +from .globals import ( + DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME as __runtime__, + DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX as __ctx__manager__, +) class BamlCallOptions(typing.TypedDict, total=False): @@ -48,9 +51,6 @@ class _ResolvedBamlOptions: self.env_vars = env_vars - - - class DoNotUseDirectlyCallManager: def __init__(self, baml_options: BamlCallOptions): self.__baml_options = baml_options @@ -74,7 +74,9 @@ class DoNotUseDirectlyCallManager: collectors_as_list = ( collector if isinstance(collector, list) - else [collector] if collector is not None else [] + else [collector] + if collector is not None + else [] ) env_vars = os.environ.copy() for k, v in self.__baml_options.get("env", {}).items(): @@ -164,7 +166,9 @@ class DoNotUseDirectlyCallManager: *, function_name: str, args: typing.Dict[str, typing.Any], - ) -> typing.Tuple[baml_py.baml_py.RuntimeContextManager, baml_py.baml_py.SyncFunctionResultStream]: + ) -> typing.Tuple[ + baml_py.baml_py.RuntimeContextManager, baml_py.baml_py.SyncFunctionResultStream + ]: resolved_options = self.__resolve() ctx = __ctx__manager__.get() result = __runtime__.stream_function_sync( @@ -172,7 +176,7 @@ class DoNotUseDirectlyCallManager: args, # this is always None, we set this later! # on_event - None, + None, # ctx ctx, # tb @@ -232,7 +236,13 @@ class DoNotUseDirectlyCallManager: mode == "stream", ) - def parse_response(self, *, function_name: str, llm_response: str, mode: typing_extensions.Literal["stream", "request"]) -> typing.Any: + def parse_response( + self, + *, + function_name: str, + llm_response: str, + mode: typing_extensions.Literal["stream", "request"], + ) -> typing.Any: resolved_options = self.__resolve() return __runtime__.parse_llm_response( function_name, @@ -253,4 +263,4 @@ class DoNotUseDirectlyCallManager: resolved_options.client_registry, # env_vars resolved_options.env_vars, - ) \ No newline at end of file + ) diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/stream_types.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/stream_types.py index 86e76a3bf..81ad00adc 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/stream_types.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/stream_types.py @@ -18,28 +18,37 @@ import baml_py from . import types -StreamStateValueT = typing.TypeVar('StreamStateValueT') +StreamStateValueT = typing.TypeVar("StreamStateValueT") + + class StreamState(BaseModel, typing.Generic[StreamStateValueT]): value: StreamStateValueT state: typing_extensions.Literal["Pending", "Incomplete", "Complete"] + + # ######################################################################### # Generated classes (17) # ######################################################################### + class AudioContent(BaseModel): type: typing.Optional[str] = None subclass: typing.List[str] + class ContentLabel(BaseModel): content_type: typing.Optional[typing.Union[str, str, str, str, str, str, str]] = None type: typing.Optional[str] = None subclass: typing.List[str] + class DefaultContentPrediction(BaseModel): label: typing.Optional["ContentLabel"] = None + class DynamicKnowledgeGraph(BaseModel): - model_config = ConfigDict(extra='allow') + model_config = ConfigDict(extra="allow") + class Edge(BaseModel): # doc string for edge @@ -49,39 +58,47 @@ class Edge(BaseModel): target_node_id: typing.Optional[str] = None relationship_name: typing.Optional[str] = None + class ImageContent(BaseModel): type: typing.Optional[str] = None subclass: typing.List[str] + class KnowledgeGraph(BaseModel): nodes: typing.List["types.Node"] edges: typing.List["Edge"] + class Model3DContent(BaseModel): type: typing.Optional[str] = None subclass: typing.List[str] + class MultimediaContent(BaseModel): type: typing.Optional[str] = None subclass: typing.List[str] + class Node(BaseModel): - model_config = ConfigDict(extra='allow') + model_config = ConfigDict(extra="allow") id: typing.Optional[str] = None name: typing.Optional[str] = None type: typing.Optional[str] = None description: typing.Optional[str] = None + class ProceduralContent(BaseModel): type: typing.Optional[str] = None subclass: typing.List[str] + class SummarizedClass(BaseModel): name: typing.Optional[str] = None description: typing.Optional[str] = None methods: typing.Optional[typing.List["SummarizedFunction"]] = None decorators: typing.Optional[typing.List[str]] = None + class SummarizedCode(BaseModel): high_level_summary: typing.Optional[str] = None key_features: typing.List[str] @@ -91,10 +108,12 @@ class SummarizedCode(BaseModel): functions: typing.List["SummarizedFunction"] workflow_description: typing.Optional[str] = None + class SummarizedContent(BaseModel): summary: typing.Optional[str] = None description: typing.Optional[str] = None + class SummarizedFunction(BaseModel): name: typing.Optional[str] = None description: typing.Optional[str] = None @@ -102,14 +121,17 @@ class SummarizedFunction(BaseModel): outputs: typing.Optional[typing.List[str]] = None decorators: typing.Optional[typing.List[str]] = None + class TextContent(BaseModel): type: typing.Optional[str] = None subclass: typing.List[str] + class VideoContent(BaseModel): type: typing.Optional[str] = None subclass: typing.List[str] + # ######################################################################### # Generated type aliases (0) # ######################################################################### diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/sync_client.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/sync_client.py index ca4f97a2b..854df2d05 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/sync_client.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/sync_client.py @@ -19,6 +19,7 @@ from .parser import LlmResponseParser, LlmStreamParser from .runtime import DoNotUseDirectlyCallManager, BamlCallOptions from .globals import DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME as __runtime__ + class BamlSyncClient: __options: DoNotUseDirectlyCallManager __stream_client: "BamlStreamClient" @@ -48,10 +49,13 @@ class BamlSyncClient: self.__llm_response_parser = LlmResponseParser(self.__options) self.__llm_stream_parser = LlmStreamParser(self.__options) - def with_options(self, + def with_options( + self, tb: typing.Optional[type_builder.TypeBuilder] = None, client_registry: typing.Optional[baml_py.baml_py.ClientRegistry] = None, - collector: typing.Optional[typing.Union[baml_py.baml_py.Collector, typing.List[baml_py.baml_py.Collector]]] = None, + collector: typing.Optional[ + typing.Union[baml_py.baml_py.Collector, typing.List[baml_py.baml_py.Collector]] + ] = None, env: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None, ) -> "BamlSyncClient": options: BamlCallOptions = {} @@ -67,60 +71,124 @@ class BamlSyncClient: @property def stream(self): - return self.__stream_client + return self.__stream_client @property def request(self): - return self.__http_request + return self.__http_request @property def stream_request(self): - return self.__http_stream_request + return self.__http_stream_request @property def parse(self): - return self.__llm_response_parser + return self.__llm_response_parser @property def parse_stream(self): - return self.__llm_stream_parser - - def ExtractCategories(self, content: str, + return self.__llm_stream_parser + + def ExtractCategories( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> types.DefaultContentPrediction: - result = self.__options.merge_options(baml_options).call_function_sync(function_name="ExtractCategories", args={ - "content": content, - }) - return typing.cast(types.DefaultContentPrediction, result.cast_to(types, types, stream_types, False, __runtime__)) - def ExtractContentGraphGeneric(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + result = self.__options.merge_options(baml_options).call_function_sync( + function_name="ExtractCategories", + args={ + "content": content, + }, + ) + return typing.cast( + types.DefaultContentPrediction, + result.cast_to(types, types, stream_types, False, __runtime__), + ) + + def ExtractContentGraphGeneric( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> types.KnowledgeGraph: - result = self.__options.merge_options(baml_options).call_function_sync(function_name="ExtractContentGraphGeneric", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }) - return typing.cast(types.KnowledgeGraph, result.cast_to(types, types, stream_types, False, __runtime__)) - def ExtractDynamicContentGraph(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + result = self.__options.merge_options(baml_options).call_function_sync( + function_name="ExtractContentGraphGeneric", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + ) + return typing.cast( + types.KnowledgeGraph, result.cast_to(types, types, stream_types, False, __runtime__) + ) + + def ExtractDynamicContentGraph( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> types.DynamicKnowledgeGraph: - result = self.__options.merge_options(baml_options).call_function_sync(function_name="ExtractDynamicContentGraph", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }) - return typing.cast(types.DynamicKnowledgeGraph, result.cast_to(types, types, stream_types, False, __runtime__)) - def SummarizeCode(self, content: str, + result = self.__options.merge_options(baml_options).call_function_sync( + function_name="ExtractDynamicContentGraph", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + ) + return typing.cast( + types.DynamicKnowledgeGraph, + result.cast_to(types, types, stream_types, False, __runtime__), + ) + + def SummarizeCode( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> types.SummarizedCode: - result = self.__options.merge_options(baml_options).call_function_sync(function_name="SummarizeCode", args={ - "content": content, - }) - return typing.cast(types.SummarizedCode, result.cast_to(types, types, stream_types, False, __runtime__)) - def SummarizeContent(self, content: str, + result = self.__options.merge_options(baml_options).call_function_sync( + function_name="SummarizeCode", + args={ + "content": content, + }, + ) + return typing.cast( + types.SummarizedCode, result.cast_to(types, types, stream_types, False, __runtime__) + ) + + def SummarizeContent( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> types.SummarizedContent: - result = self.__options.merge_options(baml_options).call_function_sync(function_name="SummarizeContent", args={ - "content": content, - }) - return typing.cast(types.SummarizedContent, result.cast_to(types, types, stream_types, False, __runtime__)) - + result = self.__options.merge_options(baml_options).call_function_sync( + function_name="SummarizeContent", + args={ + "content": content, + }, + ) + return typing.cast( + types.SummarizedContent, result.cast_to(types, types, stream_types, False, __runtime__) + ) class BamlStreamClient: @@ -129,67 +197,153 @@ class BamlStreamClient: def __init__(self, options: DoNotUseDirectlyCallManager): self.__options = options - def ExtractCategories(self, content: str, + def ExtractCategories( + self, + content: str, baml_options: BamlCallOptions = {}, - ) -> baml_py.BamlSyncStream[stream_types.DefaultContentPrediction, types.DefaultContentPrediction]: - ctx, result = self.__options.merge_options(baml_options).create_sync_stream(function_name="ExtractCategories", args={ - "content": content, - }) - return baml_py.BamlSyncStream[stream_types.DefaultContentPrediction, types.DefaultContentPrediction]( - result, - lambda x: typing.cast(stream_types.DefaultContentPrediction, x.cast_to(types, types, stream_types, True, __runtime__)), - lambda x: typing.cast(types.DefaultContentPrediction, x.cast_to(types, types, stream_types, False, __runtime__)), - ctx, + ) -> baml_py.BamlSyncStream[ + stream_types.DefaultContentPrediction, types.DefaultContentPrediction + ]: + ctx, result = self.__options.merge_options(baml_options).create_sync_stream( + function_name="ExtractCategories", + args={ + "content": content, + }, ) - def ExtractContentGraphGeneric(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + return baml_py.BamlSyncStream[ + stream_types.DefaultContentPrediction, types.DefaultContentPrediction + ]( + result, + lambda x: typing.cast( + stream_types.DefaultContentPrediction, + x.cast_to(types, types, stream_types, True, __runtime__), + ), + lambda x: typing.cast( + types.DefaultContentPrediction, + x.cast_to(types, types, stream_types, False, __runtime__), + ), + ctx, + ) + + def ExtractContentGraphGeneric( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> baml_py.BamlSyncStream[stream_types.KnowledgeGraph, types.KnowledgeGraph]: - ctx, result = self.__options.merge_options(baml_options).create_sync_stream(function_name="ExtractContentGraphGeneric", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }) - return baml_py.BamlSyncStream[stream_types.KnowledgeGraph, types.KnowledgeGraph]( - result, - lambda x: typing.cast(stream_types.KnowledgeGraph, x.cast_to(types, types, stream_types, True, __runtime__)), - lambda x: typing.cast(types.KnowledgeGraph, x.cast_to(types, types, stream_types, False, __runtime__)), - ctx, + ctx, result = self.__options.merge_options(baml_options).create_sync_stream( + function_name="ExtractContentGraphGeneric", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, ) - def ExtractDynamicContentGraph(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + return baml_py.BamlSyncStream[stream_types.KnowledgeGraph, types.KnowledgeGraph]( + result, + lambda x: typing.cast( + stream_types.KnowledgeGraph, + x.cast_to(types, types, stream_types, True, __runtime__), + ), + lambda x: typing.cast( + types.KnowledgeGraph, x.cast_to(types, types, stream_types, False, __runtime__) + ), + ctx, + ) + + def ExtractDynamicContentGraph( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> baml_py.BamlSyncStream[stream_types.DynamicKnowledgeGraph, types.DynamicKnowledgeGraph]: - ctx, result = self.__options.merge_options(baml_options).create_sync_stream(function_name="ExtractDynamicContentGraph", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }) - return baml_py.BamlSyncStream[stream_types.DynamicKnowledgeGraph, types.DynamicKnowledgeGraph]( - result, - lambda x: typing.cast(stream_types.DynamicKnowledgeGraph, x.cast_to(types, types, stream_types, True, __runtime__)), - lambda x: typing.cast(types.DynamicKnowledgeGraph, x.cast_to(types, types, stream_types, False, __runtime__)), - ctx, + ctx, result = self.__options.merge_options(baml_options).create_sync_stream( + function_name="ExtractDynamicContentGraph", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, ) - def SummarizeCode(self, content: str, + return baml_py.BamlSyncStream[ + stream_types.DynamicKnowledgeGraph, types.DynamicKnowledgeGraph + ]( + result, + lambda x: typing.cast( + stream_types.DynamicKnowledgeGraph, + x.cast_to(types, types, stream_types, True, __runtime__), + ), + lambda x: typing.cast( + types.DynamicKnowledgeGraph, + x.cast_to(types, types, stream_types, False, __runtime__), + ), + ctx, + ) + + def SummarizeCode( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.BamlSyncStream[stream_types.SummarizedCode, types.SummarizedCode]: - ctx, result = self.__options.merge_options(baml_options).create_sync_stream(function_name="SummarizeCode", args={ - "content": content, - }) - return baml_py.BamlSyncStream[stream_types.SummarizedCode, types.SummarizedCode]( - result, - lambda x: typing.cast(stream_types.SummarizedCode, x.cast_to(types, types, stream_types, True, __runtime__)), - lambda x: typing.cast(types.SummarizedCode, x.cast_to(types, types, stream_types, False, __runtime__)), - ctx, + ctx, result = self.__options.merge_options(baml_options).create_sync_stream( + function_name="SummarizeCode", + args={ + "content": content, + }, ) - def SummarizeContent(self, content: str, + return baml_py.BamlSyncStream[stream_types.SummarizedCode, types.SummarizedCode]( + result, + lambda x: typing.cast( + stream_types.SummarizedCode, + x.cast_to(types, types, stream_types, True, __runtime__), + ), + lambda x: typing.cast( + types.SummarizedCode, x.cast_to(types, types, stream_types, False, __runtime__) + ), + ctx, + ) + + def SummarizeContent( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.BamlSyncStream[stream_types.SummarizedContent, types.SummarizedContent]: - ctx, result = self.__options.merge_options(baml_options).create_sync_stream(function_name="SummarizeContent", args={ - "content": content, - }) - return baml_py.BamlSyncStream[stream_types.SummarizedContent, types.SummarizedContent]( - result, - lambda x: typing.cast(stream_types.SummarizedContent, x.cast_to(types, types, stream_types, True, __runtime__)), - lambda x: typing.cast(types.SummarizedContent, x.cast_to(types, types, stream_types, False, __runtime__)), - ctx, + ctx, result = self.__options.merge_options(baml_options).create_sync_stream( + function_name="SummarizeContent", + args={ + "content": content, + }, ) - + return baml_py.BamlSyncStream[stream_types.SummarizedContent, types.SummarizedContent]( + result, + lambda x: typing.cast( + stream_types.SummarizedContent, + x.cast_to(types, types, stream_types, True, __runtime__), + ), + lambda x: typing.cast( + types.SummarizedContent, x.cast_to(types, types, stream_types, False, __runtime__) + ), + ctx, + ) + class BamlHttpRequestClient: __options: DoNotUseDirectlyCallManager @@ -197,42 +351,100 @@ class BamlHttpRequestClient: def __init__(self, options: DoNotUseDirectlyCallManager): self.__options = options - def ExtractCategories(self, content: str, + def ExtractCategories( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = self.__options.merge_options(baml_options).create_http_request_sync(function_name="ExtractCategories", args={ - "content": content, - }, mode="request") + result = self.__options.merge_options(baml_options).create_http_request_sync( + function_name="ExtractCategories", + args={ + "content": content, + }, + mode="request", + ) return result - def ExtractContentGraphGeneric(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + + def ExtractContentGraphGeneric( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = self.__options.merge_options(baml_options).create_http_request_sync(function_name="ExtractContentGraphGeneric", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }, mode="request") + result = self.__options.merge_options(baml_options).create_http_request_sync( + function_name="ExtractContentGraphGeneric", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + mode="request", + ) return result - def ExtractDynamicContentGraph(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, + + def ExtractDynamicContentGraph( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = self.__options.merge_options(baml_options).create_http_request_sync(function_name="ExtractDynamicContentGraph", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }, mode="request") + result = self.__options.merge_options(baml_options).create_http_request_sync( + function_name="ExtractDynamicContentGraph", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + mode="request", + ) return result - def SummarizeCode(self, content: str, + + def SummarizeCode( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = self.__options.merge_options(baml_options).create_http_request_sync(function_name="SummarizeCode", args={ - "content": content, - }, mode="request") + result = self.__options.merge_options(baml_options).create_http_request_sync( + function_name="SummarizeCode", + args={ + "content": content, + }, + mode="request", + ) return result - def SummarizeContent(self, content: str, + + def SummarizeContent( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = self.__options.merge_options(baml_options).create_http_request_sync(function_name="SummarizeContent", args={ - "content": content, - }, mode="request") + result = self.__options.merge_options(baml_options).create_http_request_sync( + function_name="SummarizeContent", + args={ + "content": content, + }, + mode="request", + ) return result - + class BamlHttpStreamRequestClient: __options: DoNotUseDirectlyCallManager @@ -240,41 +452,99 @@ class BamlHttpStreamRequestClient: def __init__(self, options: DoNotUseDirectlyCallManager): self.__options = options - def ExtractCategories(self, content: str, + def ExtractCategories( + self, + content: str, baml_options: BamlCallOptions = {}, ) -> baml_py.baml_py.HTTPRequest: - result = self.__options.merge_options(baml_options).create_http_request_sync(function_name="ExtractCategories", args={ - "content": content, - }, mode="stream") + result = self.__options.merge_options(baml_options).create_http_request_sync( + function_name="ExtractCategories", + args={ + "content": content, + }, + mode="stream", + ) return result - def ExtractContentGraphGeneric(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, - baml_options: BamlCallOptions = {}, - ) -> baml_py.baml_py.HTTPRequest: - result = self.__options.merge_options(baml_options).create_http_request_sync(function_name="ExtractContentGraphGeneric", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }, mode="stream") - return result - def ExtractDynamicContentGraph(self, content: str,mode: typing.Optional[typing.Union[typing_extensions.Literal['simple'], typing_extensions.Literal['base'], typing_extensions.Literal['guided'], typing_extensions.Literal['strict'], typing_extensions.Literal['custom']]] = None,custom_prompt_content: typing.Optional[str] = None, - baml_options: BamlCallOptions = {}, - ) -> baml_py.baml_py.HTTPRequest: - result = self.__options.merge_options(baml_options).create_http_request_sync(function_name="ExtractDynamicContentGraph", args={ - "content": content,"mode": mode,"custom_prompt_content": custom_prompt_content, - }, mode="stream") - return result - def SummarizeCode(self, content: str, - baml_options: BamlCallOptions = {}, - ) -> baml_py.baml_py.HTTPRequest: - result = self.__options.merge_options(baml_options).create_http_request_sync(function_name="SummarizeCode", args={ - "content": content, - }, mode="stream") - return result - def SummarizeContent(self, content: str, - baml_options: BamlCallOptions = {}, - ) -> baml_py.baml_py.HTTPRequest: - result = self.__options.merge_options(baml_options).create_http_request_sync(function_name="SummarizeContent", args={ - "content": content, - }, mode="stream") - return result - -b = BamlSyncClient(DoNotUseDirectlyCallManager({})) \ No newline at end of file + def ExtractContentGraphGeneric( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, + baml_options: BamlCallOptions = {}, + ) -> baml_py.baml_py.HTTPRequest: + result = self.__options.merge_options(baml_options).create_http_request_sync( + function_name="ExtractContentGraphGeneric", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + mode="stream", + ) + return result + + def ExtractDynamicContentGraph( + self, + content: str, + mode: typing.Optional[ + typing.Union[ + typing_extensions.Literal["simple"], + typing_extensions.Literal["base"], + typing_extensions.Literal["guided"], + typing_extensions.Literal["strict"], + typing_extensions.Literal["custom"], + ] + ] = None, + custom_prompt_content: typing.Optional[str] = None, + baml_options: BamlCallOptions = {}, + ) -> baml_py.baml_py.HTTPRequest: + result = self.__options.merge_options(baml_options).create_http_request_sync( + function_name="ExtractDynamicContentGraph", + args={ + "content": content, + "mode": mode, + "custom_prompt_content": custom_prompt_content, + }, + mode="stream", + ) + return result + + def SummarizeCode( + self, + content: str, + baml_options: BamlCallOptions = {}, + ) -> baml_py.baml_py.HTTPRequest: + result = self.__options.merge_options(baml_options).create_http_request_sync( + function_name="SummarizeCode", + args={ + "content": content, + }, + mode="stream", + ) + return result + + def SummarizeContent( + self, + content: str, + baml_options: BamlCallOptions = {}, + ) -> baml_py.baml_py.HTTPRequest: + result = self.__options.merge_options(baml_options).create_http_request_sync( + function_name="SummarizeContent", + args={ + "content": content, + }, + mode="stream", + ) + return result + + +b = BamlSyncClient(DoNotUseDirectlyCallManager({})) diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/tracing.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/tracing.py index 06725593c..f925306f9 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/tracing.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/tracing.py @@ -14,9 +14,13 @@ from .globals import DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX trace = DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.trace_fn set_tags = DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.upsert_tags + + def flush(): - DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.flush() + DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.flush() + + on_log_event = DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.on_log_event -__all__ = ['trace', 'set_tags', "flush", "on_log_event"] +__all__ = ["trace", "set_tags", "flush", "on_log_event"] diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_builder.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_builder.py index 62b687f71..c90cd96cd 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_builder.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_builder.py @@ -15,19 +15,39 @@ from baml_py import type_builder from baml_py import baml_py from .globals import DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME + class TypeBuilder(type_builder.TypeBuilder): def __init__(self): - super().__init__(classes=set( - ["AudioContent","ContentLabel","DefaultContentPrediction","DynamicKnowledgeGraph","Edge","ImageContent","KnowledgeGraph","Model3DContent","MultimediaContent","Node","ProceduralContent","SummarizedClass","SummarizedCode","SummarizedContent","SummarizedFunction","TextContent","VideoContent",] - ), enums=set( - [] - ), runtime=DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME) + super().__init__( + classes=set( + [ + "AudioContent", + "ContentLabel", + "DefaultContentPrediction", + "DynamicKnowledgeGraph", + "Edge", + "ImageContent", + "KnowledgeGraph", + "Model3DContent", + "MultimediaContent", + "Node", + "ProceduralContent", + "SummarizedClass", + "SummarizedCode", + "SummarizedContent", + "SummarizedFunction", + "TextContent", + "VideoContent", + ] + ), + enums=set([]), + runtime=DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME, + ) # ######################################################################### # Generated enums 0 # ######################################################################### - # ######################################################################### # Generated classes 17 # ######################################################################### @@ -101,7 +121,6 @@ class TypeBuilder(type_builder.TypeBuilder): return VideoContentViewer(self) - # ######################################################################### # Generated enums 0 # ######################################################################### @@ -111,11 +130,17 @@ class TypeBuilder(type_builder.TypeBuilder): # Generated classes 17 # ######################################################################### + class AudioContentAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("AudioContent") - self._properties: typing.Set[str] = set([ "type", "subclass", ]) + self._properties: typing.Set[str] = set( + [ + "type", + "subclass", + ] + ) self._props = AudioContentProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -130,35 +155,38 @@ class AudioContentViewer(AudioContentAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class AudioContentProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def type(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("type")) - + @property def subclass(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("subclass")) - - class ContentLabelAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("ContentLabel") - self._properties: typing.Set[str] = set([ "content_type", "type", "subclass", ]) + self._properties: typing.Set[str] = set( + [ + "content_type", + "type", + "subclass", + ] + ) self._props = ContentLabelProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -173,39 +201,40 @@ class ContentLabelViewer(ContentLabelAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class ContentLabelProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def content_type(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("content_type")) - + @property def type(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("type")) - + @property def subclass(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("subclass")) - - class DefaultContentPredictionAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("DefaultContentPrediction") - self._properties: typing.Set[str] = set([ "label", ]) + self._properties: typing.Set[str] = set( + [ + "label", + ] + ) self._props = DefaultContentPredictionProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -220,31 +249,28 @@ class DefaultContentPredictionViewer(DefaultContentPredictionAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class DefaultContentPredictionProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def label(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("label")) - - class DynamicKnowledgeGraphAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("DynamicKnowledgeGraph") - self._properties: typing.Set[str] = set([ ]) + self._properties: typing.Set[str] = set([]) self._props = DynamicKnowledgeGraphProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -259,7 +285,6 @@ class DynamicKnowledgeGraphBuilder(DynamicKnowledgeGraphAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def add_property(self, name: str, type: baml_py.FieldType) -> baml_py.ClassPropertyBuilder: if name in self._properties: raise ValueError(f"Property {name} already exists.") @@ -268,29 +293,29 @@ class DynamicKnowledgeGraphBuilder(DynamicKnowledgeGraphAst): def list_properties(self) -> typing.List[typing.Tuple[str, baml_py.ClassPropertyBuilder]]: return [(name, self._bldr.property(name)) for name in self._properties] - - class DynamicKnowledgeGraphProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - def __getattr__(self, name: str) -> baml_py.ClassPropertyBuilder: if name not in self.__properties: raise AttributeError(f"Property {name} not found.") return self.__bldr.property(name) - - - class EdgeAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("Edge") - self._properties: typing.Set[str] = set([ "source_node_id", "target_node_id", "relationship_name", ]) + self._properties: typing.Set[str] = set( + [ + "source_node_id", + "target_node_id", + "relationship_name", + ] + ) self._props = EdgeProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -305,39 +330,41 @@ class EdgeViewer(EdgeAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class EdgeProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def source_node_id(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("source_node_id")) - + @property def target_node_id(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("target_node_id")) - + @property def relationship_name(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("relationship_name")) - - class ImageContentAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("ImageContent") - self._properties: typing.Set[str] = set([ "type", "subclass", ]) + self._properties: typing.Set[str] = set( + [ + "type", + "subclass", + ] + ) self._props = ImageContentProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -352,35 +379,37 @@ class ImageContentViewer(ImageContentAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class ImageContentProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def type(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("type")) - + @property def subclass(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("subclass")) - - class KnowledgeGraphAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("KnowledgeGraph") - self._properties: typing.Set[str] = set([ "nodes", "edges", ]) + self._properties: typing.Set[str] = set( + [ + "nodes", + "edges", + ] + ) self._props = KnowledgeGraphProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -395,35 +424,37 @@ class KnowledgeGraphViewer(KnowledgeGraphAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class KnowledgeGraphProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def nodes(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("nodes")) - + @property def edges(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("edges")) - - class Model3DContentAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("Model3DContent") - self._properties: typing.Set[str] = set([ "type", "subclass", ]) + self._properties: typing.Set[str] = set( + [ + "type", + "subclass", + ] + ) self._props = Model3DContentProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -438,35 +469,37 @@ class Model3DContentViewer(Model3DContentAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class Model3DContentProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def type(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("type")) - + @property def subclass(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("subclass")) - - class MultimediaContentAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("MultimediaContent") - self._properties: typing.Set[str] = set([ "type", "subclass", ]) + self._properties: typing.Set[str] = set( + [ + "type", + "subclass", + ] + ) self._props = MultimediaContentProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -481,35 +514,39 @@ class MultimediaContentViewer(MultimediaContentAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class MultimediaContentProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def type(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("type")) - + @property def subclass(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("subclass")) - - class NodeAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("Node") - self._properties: typing.Set[str] = set([ "id", "name", "type", "description", ]) + self._properties: typing.Set[str] = set( + [ + "id", + "name", + "type", + "description", + ] + ) self._props = NodeProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -524,7 +561,6 @@ class NodeBuilder(NodeAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def add_property(self, name: str, type: baml_py.FieldType) -> baml_py.ClassPropertyBuilder: if name in self._properties: raise ValueError(f"Property {name} already exists.") @@ -533,45 +569,44 @@ class NodeBuilder(NodeAst): def list_properties(self) -> typing.List[typing.Tuple[str, baml_py.ClassPropertyBuilder]]: return [(name, self._bldr.property(name)) for name in self._properties] - - class NodeProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - def __getattr__(self, name: str) -> baml_py.ClassPropertyBuilder: if name not in self.__properties: raise AttributeError(f"Property {name} not found.") return self.__bldr.property(name) - @property def id(self) -> baml_py.ClassPropertyBuilder: return self.__bldr.property("id") - + @property def name(self) -> baml_py.ClassPropertyBuilder: return self.__bldr.property("name") - + @property def type(self) -> baml_py.ClassPropertyBuilder: return self.__bldr.property("type") - + @property def description(self) -> baml_py.ClassPropertyBuilder: return self.__bldr.property("description") - - class ProceduralContentAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("ProceduralContent") - self._properties: typing.Set[str] = set([ "type", "subclass", ]) + self._properties: typing.Set[str] = set( + [ + "type", + "subclass", + ] + ) self._props = ProceduralContentProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -586,35 +621,39 @@ class ProceduralContentViewer(ProceduralContentAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class ProceduralContentProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def type(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("type")) - + @property def subclass(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("subclass")) - - class SummarizedClassAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("SummarizedClass") - self._properties: typing.Set[str] = set([ "name", "description", "methods", "decorators", ]) + self._properties: typing.Set[str] = set( + [ + "name", + "description", + "methods", + "decorators", + ] + ) self._props = SummarizedClassProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -629,43 +668,50 @@ class SummarizedClassViewer(SummarizedClassAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class SummarizedClassProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def name(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("name")) - + @property def description(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("description")) - + @property def methods(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("methods")) - + @property def decorators(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("decorators")) - - class SummarizedCodeAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("SummarizedCode") - self._properties: typing.Set[str] = set([ "high_level_summary", "key_features", "imports", "constants", "classes", "functions", "workflow_description", ]) + self._properties: typing.Set[str] = set( + [ + "high_level_summary", + "key_features", + "imports", + "constants", + "classes", + "functions", + "workflow_description", + ] + ) self._props = SummarizedCodeProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -680,55 +726,57 @@ class SummarizedCodeViewer(SummarizedCodeAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class SummarizedCodeProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def high_level_summary(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("high_level_summary")) - + @property def key_features(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("key_features")) - + @property def imports(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("imports")) - + @property def constants(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("constants")) - + @property def classes(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("classes")) - + @property def functions(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("functions")) - + @property def workflow_description(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("workflow_description")) - - class SummarizedContentAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("SummarizedContent") - self._properties: typing.Set[str] = set([ "summary", "description", ]) + self._properties: typing.Set[str] = set( + [ + "summary", + "description", + ] + ) self._props = SummarizedContentProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -743,35 +791,40 @@ class SummarizedContentViewer(SummarizedContentAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class SummarizedContentProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def summary(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("summary")) - + @property def description(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("description")) - - class SummarizedFunctionAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("SummarizedFunction") - self._properties: typing.Set[str] = set([ "name", "description", "inputs", "outputs", "decorators", ]) + self._properties: typing.Set[str] = set( + [ + "name", + "description", + "inputs", + "outputs", + "decorators", + ] + ) self._props = SummarizedFunctionProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -786,47 +839,49 @@ class SummarizedFunctionViewer(SummarizedFunctionAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class SummarizedFunctionProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def name(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("name")) - + @property def description(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("description")) - + @property def inputs(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("inputs")) - + @property def outputs(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("outputs")) - + @property def decorators(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("decorators")) - - class TextContentAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("TextContent") - self._properties: typing.Set[str] = set([ "type", "subclass", ]) + self._properties: typing.Set[str] = set( + [ + "type", + "subclass", + ] + ) self._props = TextContentProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -841,35 +896,37 @@ class TextContentViewer(TextContentAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class TextContentProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def type(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("type")) - + @property def subclass(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("subclass")) - - class VideoContentAst: def __init__(self, tb: type_builder.TypeBuilder): - _tb = tb._tb # type: ignore (we know how to use this private attribute) + _tb = tb._tb # type: ignore (we know how to use this private attribute) self._bldr = _tb.class_("VideoContent") - self._properties: typing.Set[str] = set([ "type", "subclass", ]) + self._properties: typing.Set[str] = set( + [ + "type", + "subclass", + ] + ) self._props = VideoContentProperties(self._bldr, self._properties) def type(self) -> baml_py.FieldType: @@ -884,26 +941,22 @@ class VideoContentViewer(VideoContentAst): def __init__(self, tb: type_builder.TypeBuilder): super().__init__(tb) - def list_properties(self) -> typing.List[typing.Tuple[str, type_builder.ClassPropertyViewer]]: - return [(name, type_builder.ClassPropertyViewer(self._bldr.property(name))) for name in self._properties] - + return [ + (name, type_builder.ClassPropertyViewer(self._bldr.property(name))) + for name in self._properties + ] class VideoContentProperties: def __init__(self, bldr: baml_py.ClassBuilder, properties: typing.Set[str]): self.__bldr = bldr - self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 + self.__properties = properties # type: ignore (we know how to use this private attribute) # noqa: F821 - - @property def type(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("type")) - + @property def subclass(self) -> type_builder.ClassPropertyViewer: return type_builder.ClassPropertyViewer(self.__bldr.property("subclass")) - - - diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_map.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_map.py index 6e6866109..d8188a7b3 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_map.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_map.py @@ -15,57 +15,38 @@ from . import stream_types type_map = { - "types.AudioContent": types.AudioContent, "stream_types.AudioContent": stream_types.AudioContent, - "types.ContentLabel": types.ContentLabel, "stream_types.ContentLabel": stream_types.ContentLabel, - "types.DefaultContentPrediction": types.DefaultContentPrediction, "stream_types.DefaultContentPrediction": stream_types.DefaultContentPrediction, - "types.DynamicKnowledgeGraph": types.DynamicKnowledgeGraph, "stream_types.DynamicKnowledgeGraph": stream_types.DynamicKnowledgeGraph, - "types.Edge": types.Edge, "stream_types.Edge": stream_types.Edge, - "types.ImageContent": types.ImageContent, "stream_types.ImageContent": stream_types.ImageContent, - "types.KnowledgeGraph": types.KnowledgeGraph, "stream_types.KnowledgeGraph": stream_types.KnowledgeGraph, - "types.Model3DContent": types.Model3DContent, "stream_types.Model3DContent": stream_types.Model3DContent, - "types.MultimediaContent": types.MultimediaContent, "stream_types.MultimediaContent": stream_types.MultimediaContent, - "types.Node": types.Node, "stream_types.Node": stream_types.Node, - "types.ProceduralContent": types.ProceduralContent, "stream_types.ProceduralContent": stream_types.ProceduralContent, - "types.SummarizedClass": types.SummarizedClass, "stream_types.SummarizedClass": stream_types.SummarizedClass, - "types.SummarizedCode": types.SummarizedCode, "stream_types.SummarizedCode": stream_types.SummarizedCode, - "types.SummarizedContent": types.SummarizedContent, "stream_types.SummarizedContent": stream_types.SummarizedContent, - "types.SummarizedFunction": types.SummarizedFunction, "stream_types.SummarizedFunction": stream_types.SummarizedFunction, - "types.TextContent": types.TextContent, "stream_types.TextContent": stream_types.TextContent, - "types.VideoContent": types.VideoContent, "stream_types.VideoContent": stream_types.VideoContent, - - -} \ No newline at end of file +} diff --git a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/types.py b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/types.py index a3d0ea358..7b965d889 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/types.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml/baml_client/types.py @@ -20,22 +20,29 @@ from pydantic import BaseModel, ConfigDict import baml_py -CheckT = typing_extensions.TypeVar('CheckT') -CheckName = typing_extensions.TypeVar('CheckName', bound=str) +CheckT = typing_extensions.TypeVar("CheckT") +CheckName = typing_extensions.TypeVar("CheckName", bound=str) + class Check(BaseModel): name: str expression: str status: str + + class Checked(BaseModel, typing.Generic[CheckT, CheckName]): value: CheckT checks: typing.Dict[CheckName, Check] + def get_checks(checks: typing.Dict[CheckName, Check]) -> typing.List[Check]: return list(checks.values()) + def all_succeeded(checks: typing.Dict[CheckName, Check]) -> bool: return all(check.status == "succeeded" for check in get_checks(checks)) + + # ######################################################################### # Generated enums (0) # ######################################################################### @@ -44,20 +51,33 @@ def all_succeeded(checks: typing.Dict[CheckName, Check]) -> bool: # Generated classes (17) # ######################################################################### + class AudioContent(BaseModel): type: str subclass: typing.List[str] + class ContentLabel(BaseModel): - content_type: typing.Union[typing_extensions.Literal['text'], typing_extensions.Literal['audio'], typing_extensions.Literal['image'], typing_extensions.Literal['video'], typing_extensions.Literal['multimedia'], typing_extensions.Literal['3d_model'], typing_extensions.Literal['procedural']] + content_type: typing.Union[ + typing_extensions.Literal["text"], + typing_extensions.Literal["audio"], + typing_extensions.Literal["image"], + typing_extensions.Literal["video"], + typing_extensions.Literal["multimedia"], + typing_extensions.Literal["3d_model"], + typing_extensions.Literal["procedural"], + ] type: str subclass: typing.List[str] + class DefaultContentPrediction(BaseModel): label: "ContentLabel" + class DynamicKnowledgeGraph(BaseModel): - model_config = ConfigDict(extra='allow') + model_config = ConfigDict(extra="allow") + class Edge(BaseModel): # doc string for edge @@ -67,39 +87,47 @@ class Edge(BaseModel): target_node_id: str relationship_name: str + class ImageContent(BaseModel): type: str subclass: typing.List[str] + class KnowledgeGraph(BaseModel): nodes: typing.List["Node"] edges: typing.List["Edge"] + class Model3DContent(BaseModel): type: str subclass: typing.List[str] + class MultimediaContent(BaseModel): type: str subclass: typing.List[str] + class Node(BaseModel): - model_config = ConfigDict(extra='allow') + model_config = ConfigDict(extra="allow") id: str name: str type: str description: str + class ProceduralContent(BaseModel): type: str subclass: typing.List[str] + class SummarizedClass(BaseModel): name: str description: str methods: typing.Optional[typing.List["SummarizedFunction"]] = None decorators: typing.Optional[typing.List[str]] = None + class SummarizedCode(BaseModel): high_level_summary: str key_features: typing.List[str] @@ -109,10 +137,12 @@ class SummarizedCode(BaseModel): functions: typing.List["SummarizedFunction"] workflow_description: typing.Optional[str] = None + class SummarizedContent(BaseModel): summary: str description: str + class SummarizedFunction(BaseModel): name: str description: str @@ -120,14 +150,17 @@ class SummarizedFunction(BaseModel): outputs: typing.Optional[typing.List[str]] = None decorators: typing.Optional[typing.List[str]] = None + class TextContent(BaseModel): type: str subclass: typing.List[str] + class VideoContent(BaseModel): type: str subclass: typing.List[str] + # ######################################################################### # Generated type aliases (0) # ######################################################################### diff --git a/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/extract_categories.py b/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/extract_categories.py index 02397d956..58cb67043 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/extract_categories.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/extract_categories.py @@ -2,13 +2,14 @@ import os from typing import Type from pydantic import BaseModel from cognee.infrastructure.llm.structured_output_framework.baml_src.config import get_llm_config - -config = get_llm_config() from cognee.infrastructure.llm.structured_output_framework.baml.baml_client.async_client import b from cognee.shared.data_models import SummarizedCode from cognee.shared.logging_utils import get_logger from baml_py import ClientRegistry +config = get_llm_config() + + logger = get_logger("extract_summary_baml") diff --git a/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/extract_summary.py b/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/extract_summary.py index c35b3f69c..3ccc8f817 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/extract_summary.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/extract_summary.py @@ -1,13 +1,15 @@ import os from typing import Type from pydantic import BaseModel -from cognee.infrastructure.llm.structured_output_framework.baml_src.config import get_llm_config -config = get_llm_config() +from baml_py import ClientRegistry +from cognee.shared.logging_utils import get_logger +from cognee.shared.data_models import SummarizedCode from cognee.infrastructure.llm.structured_output_framework.baml.baml_client.async_client import b from cognee.infrastructure.llm.structured_output_framework.baml_src.config import get_llm_config -from cognee.shared.data_models import SummarizedCode -from cognee.shared.logging_utils import get_logger -from baml_py import ClientRegistry + +config = get_llm_config() + + logger = get_logger("extract_summary_baml") @@ -45,9 +47,10 @@ async def extract_summary(content: str, response_model: Type[BaseModel]): options={ "model": config.llm_model, "temperature": config.llm_temperature, - "api_key": config.llm_api_key - }) - baml_registry.set_primary('def') + "api_key": config.llm_api_key, + }, + ) + baml_registry.set_primary("def") # Use BAML's SummarizeContent function summary_result = await b.SummarizeContent( @@ -97,12 +100,11 @@ async def extract_code_summary(content: str): options={ "model": config.llm_model, "temperature": config.llm_temperature, - "api_key": config.llm_api_key - }) - baml_registry.set_primary('def') - result = await b.SummarizeCode( - content, baml_options={"client_registry": baml_registry} + "api_key": config.llm_api_key, + }, ) + baml_registry.set_primary("def") + result = await b.SummarizeCode(content, baml_options={"client_registry": baml_registry}) except Exception as e: logger.error( "Failed to extract code summary with BAML, falling back to mock summary", exc_info=e diff --git a/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/knowledge_graph/extract_content_graph.py b/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/knowledge_graph/extract_content_graph.py index 978c5711e..6ddfdbde2 100644 --- a/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/knowledge_graph/extract_content_graph.py +++ b/cognee/infrastructure/llm/structured_output_framework/baml_src/extraction/knowledge_graph/extract_content_graph.py @@ -1,12 +1,11 @@ -import os +from baml_py import ClientRegistry from typing import Type from pydantic import BaseModel from cognee.infrastructure.llm.structured_output_framework.baml_src.config import get_llm_config +from cognee.shared.logging_utils import get_logger, setup_logging +from cognee.infrastructure.llm.structured_output_framework.baml.baml_client.async_client import b config = get_llm_config() -from cognee.infrastructure.llm.structured_output_framework.baml.baml_client.async_client import b -from cognee.shared.logging_utils import get_logger, setup_logging -from baml_py import ClientRegistry async def extract_content_graph( diff --git a/cognee/tasks/graph/extract_graph_from_data.py b/cognee/tasks/graph/extract_graph_from_data.py index 700f928d6..3abcac029 100644 --- a/cognee/tasks/graph/extract_graph_from_data.py +++ b/cognee/tasks/graph/extract_graph_from_data.py @@ -27,9 +27,6 @@ else: extract_content_graph, ) -from cognee.tasks.storage.add_data_points import add_data_points - - async def integrate_chunk_graphs( data_chunks: list[DocumentChunk], diff --git a/pyproject.toml b/pyproject.toml index c7b88d5d5..c7180e7f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,7 @@ dependencies = [ "dlt[sqlalchemy]>=1.9.0,<2", "sentry-sdk[fastapi]>=2.9.0,<3", "structlog>=25.2.0,<26", - "baml-py (>=0.201.0,<0.202.0)" + "baml-py (>=0.201.0,<0.202.0)", "pympler>=1.1,<2.0.0", "onnxruntime>=1.0.0,<2.0.0", "pylance>=0.22.0,<1.0.0",