gllm-inference-binary 0.5.65__cp313-cp313-macosx_13_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. gllm_inference/__init__.pyi +0 -0
  2. gllm_inference/builder/__init__.pyi +6 -0
  3. gllm_inference/builder/_build_invoker.pyi +28 -0
  4. gllm_inference/builder/build_em_invoker.pyi +130 -0
  5. gllm_inference/builder/build_lm_invoker.pyi +222 -0
  6. gllm_inference/builder/build_lm_request_processor.pyi +88 -0
  7. gllm_inference/builder/build_output_parser.pyi +29 -0
  8. gllm_inference/catalog/__init__.pyi +4 -0
  9. gllm_inference/catalog/catalog.pyi +121 -0
  10. gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
  11. gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
  12. gllm_inference/constants.pyi +12 -0
  13. gllm_inference/em_invoker/__init__.pyi +12 -0
  14. gllm_inference/em_invoker/azure_openai_em_invoker.pyi +88 -0
  15. gllm_inference/em_invoker/bedrock_em_invoker.pyi +118 -0
  16. gllm_inference/em_invoker/cohere_em_invoker.pyi +127 -0
  17. gllm_inference/em_invoker/em_invoker.pyi +90 -0
  18. gllm_inference/em_invoker/google_em_invoker.pyi +129 -0
  19. gllm_inference/em_invoker/jina_em_invoker.pyi +103 -0
  20. gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
  21. gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +84 -0
  22. gllm_inference/em_invoker/langchain_em_invoker.pyi +46 -0
  23. gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +41 -0
  24. gllm_inference/em_invoker/openai_em_invoker.pyi +118 -0
  25. gllm_inference/em_invoker/schema/__init__.pyi +0 -0
  26. gllm_inference/em_invoker/schema/bedrock.pyi +29 -0
  27. gllm_inference/em_invoker/schema/cohere.pyi +20 -0
  28. gllm_inference/em_invoker/schema/google.pyi +9 -0
  29. gllm_inference/em_invoker/schema/jina.pyi +29 -0
  30. gllm_inference/em_invoker/schema/langchain.pyi +5 -0
  31. gllm_inference/em_invoker/schema/openai.pyi +7 -0
  32. gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
  33. gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
  34. gllm_inference/em_invoker/schema/voyage.pyi +15 -0
  35. gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +101 -0
  36. gllm_inference/em_invoker/voyage_em_invoker.pyi +104 -0
  37. gllm_inference/exceptions/__init__.pyi +4 -0
  38. gllm_inference/exceptions/error_parser.pyi +41 -0
  39. gllm_inference/exceptions/exceptions.pyi +132 -0
  40. gllm_inference/exceptions/provider_error_map.pyi +24 -0
  41. gllm_inference/lm_invoker/__init__.pyi +15 -0
  42. gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +320 -0
  43. gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +237 -0
  44. gllm_inference/lm_invoker/batch/__init__.pyi +3 -0
  45. gllm_inference/lm_invoker/batch/batch_operations.pyi +128 -0
  46. gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +212 -0
  47. gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +157 -0
  48. gllm_inference/lm_invoker/google_lm_invoker.pyi +421 -0
  49. gllm_inference/lm_invoker/langchain_lm_invoker.pyi +239 -0
  50. gllm_inference/lm_invoker/litellm_lm_invoker.pyi +224 -0
  51. gllm_inference/lm_invoker/lm_invoker.pyi +183 -0
  52. gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +252 -0
  53. gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +52 -0
  54. gllm_inference/lm_invoker/openai_lm_invoker.pyi +437 -0
  55. gllm_inference/lm_invoker/portkey_lm_invoker.pyi +296 -0
  56. gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
  57. gllm_inference/lm_invoker/schema/anthropic.pyi +56 -0
  58. gllm_inference/lm_invoker/schema/bedrock.pyi +53 -0
  59. gllm_inference/lm_invoker/schema/datasaur.pyi +14 -0
  60. gllm_inference/lm_invoker/schema/google.pyi +36 -0
  61. gllm_inference/lm_invoker/schema/langchain.pyi +23 -0
  62. gllm_inference/lm_invoker/schema/openai.pyi +109 -0
  63. gllm_inference/lm_invoker/schema/openai_chat_completions.pyi +62 -0
  64. gllm_inference/lm_invoker/schema/portkey.pyi +31 -0
  65. gllm_inference/lm_invoker/schema/xai.pyi +31 -0
  66. gllm_inference/lm_invoker/sea_lion_lm_invoker.pyi +48 -0
  67. gllm_inference/lm_invoker/xai_lm_invoker.pyi +252 -0
  68. gllm_inference/model/__init__.pyi +13 -0
  69. gllm_inference/model/em/__init__.pyi +0 -0
  70. gllm_inference/model/em/cohere_em.pyi +17 -0
  71. gllm_inference/model/em/google_em.pyi +16 -0
  72. gllm_inference/model/em/jina_em.pyi +22 -0
  73. gllm_inference/model/em/openai_em.pyi +15 -0
  74. gllm_inference/model/em/twelvelabs_em.pyi +13 -0
  75. gllm_inference/model/em/voyage_em.pyi +20 -0
  76. gllm_inference/model/lm/__init__.pyi +0 -0
  77. gllm_inference/model/lm/anthropic_lm.pyi +22 -0
  78. gllm_inference/model/lm/google_lm.pyi +18 -0
  79. gllm_inference/model/lm/openai_lm.pyi +27 -0
  80. gllm_inference/model/lm/sea_lion_lm.pyi +16 -0
  81. gllm_inference/model/lm/xai_lm.pyi +19 -0
  82. gllm_inference/output_parser/__init__.pyi +3 -0
  83. gllm_inference/output_parser/json_output_parser.pyi +60 -0
  84. gllm_inference/output_parser/output_parser.pyi +27 -0
  85. gllm_inference/prompt_builder/__init__.pyi +3 -0
  86. gllm_inference/prompt_builder/format_strategy/__init__.pyi +4 -0
  87. gllm_inference/prompt_builder/format_strategy/format_strategy.pyi +55 -0
  88. gllm_inference/prompt_builder/format_strategy/jinja_format_strategy.pyi +45 -0
  89. gllm_inference/prompt_builder/format_strategy/string_format_strategy.pyi +20 -0
  90. gllm_inference/prompt_builder/prompt_builder.pyi +73 -0
  91. gllm_inference/prompt_formatter/__init__.pyi +7 -0
  92. gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
  93. gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
  94. gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
  95. gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
  96. gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
  97. gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
  98. gllm_inference/realtime_chat/__init__.pyi +3 -0
  99. gllm_inference/realtime_chat/google_realtime_chat.pyi +205 -0
  100. gllm_inference/realtime_chat/input_streamer/__init__.pyi +4 -0
  101. gllm_inference/realtime_chat/input_streamer/input_streamer.pyi +36 -0
  102. gllm_inference/realtime_chat/input_streamer/keyboard_input_streamer.pyi +27 -0
  103. gllm_inference/realtime_chat/input_streamer/linux_mic_input_streamer.pyi +36 -0
  104. gllm_inference/realtime_chat/output_streamer/__init__.pyi +4 -0
  105. gllm_inference/realtime_chat/output_streamer/console_output_streamer.pyi +21 -0
  106. gllm_inference/realtime_chat/output_streamer/linux_speaker_output_streamer.pyi +42 -0
  107. gllm_inference/realtime_chat/output_streamer/output_streamer.pyi +33 -0
  108. gllm_inference/realtime_chat/realtime_chat.pyi +28 -0
  109. gllm_inference/request_processor/__init__.pyi +4 -0
  110. gllm_inference/request_processor/lm_request_processor.pyi +101 -0
  111. gllm_inference/request_processor/uses_lm_mixin.pyi +130 -0
  112. gllm_inference/schema/__init__.pyi +19 -0
  113. gllm_inference/schema/activity.pyi +64 -0
  114. gllm_inference/schema/attachment.pyi +102 -0
  115. gllm_inference/schema/code_exec_result.pyi +14 -0
  116. gllm_inference/schema/config.pyi +15 -0
  117. gllm_inference/schema/enums.pyi +82 -0
  118. gllm_inference/schema/events.pyi +105 -0
  119. gllm_inference/schema/formatter.pyi +31 -0
  120. gllm_inference/schema/lm_input.pyi +4 -0
  121. gllm_inference/schema/lm_output.pyi +266 -0
  122. gllm_inference/schema/mcp.pyi +31 -0
  123. gllm_inference/schema/message.pyi +52 -0
  124. gllm_inference/schema/model_id.pyi +176 -0
  125. gllm_inference/schema/reasoning.pyi +15 -0
  126. gllm_inference/schema/token_usage.pyi +75 -0
  127. gllm_inference/schema/tool_call.pyi +14 -0
  128. gllm_inference/schema/tool_result.pyi +11 -0
  129. gllm_inference/schema/type_alias.pyi +11 -0
  130. gllm_inference/utils/__init__.pyi +5 -0
  131. gllm_inference/utils/io_utils.pyi +26 -0
  132. gllm_inference/utils/langchain.pyi +30 -0
  133. gllm_inference/utils/validation.pyi +15 -0
  134. gllm_inference.build/.gitignore +1 -0
  135. gllm_inference.cpython-313-darwin.so +0 -0
  136. gllm_inference.pyi +156 -0
  137. gllm_inference_binary-0.5.65.dist-info/METADATA +138 -0
  138. gllm_inference_binary-0.5.65.dist-info/RECORD +140 -0
  139. gllm_inference_binary-0.5.65.dist-info/WHEEL +5 -0
  140. gllm_inference_binary-0.5.65.dist-info/top_level.txt +1 -0
@@ -0,0 +1,130 @@
1
+ from gllm_inference.builder.build_lm_invoker import build_lm_invoker as build_lm_invoker
2
+ from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
3
+ from gllm_inference.output_parser.output_parser import BaseOutputParser as BaseOutputParser
4
+ from gllm_inference.prompt_builder.prompt_builder import PromptBuilder as PromptBuilder
5
+ from gllm_inference.request_processor.lm_request_processor import LMRequestProcessor as LMRequestProcessor
6
+ from gllm_inference.schema import LMOutput as LMOutput
7
+ from pydantic import BaseModel as BaseModel
8
+ from typing import Any
9
+
10
+ class UsesLM:
11
+ '''A mixin to be extended by components that use LMRequestProcessor.
12
+
13
+ This mixin should be extended by components that use LMRequestProcessor. Components that extend this mixin
14
+ must have a constructor that accepts the LMRequestProcessor instance as its first argument.
15
+
16
+ LM based components can be categorized into two types:
17
+ 1. Components that do not utilize structured output.
18
+ 2. Components that utilize structured output.
19
+
20
+ Building a component without structured output:
21
+ As defined above, the component must accepts an LMRequestProcessor instance as its first argument, e.g.:
22
+ ```python
23
+ class LMBasedComponent(Component, UsesLM):
24
+ def __init__(self, lm_request_processor: LMRequestProcessor, custom_kwarg: str):
25
+ self.lm_request_processor = lm_request_processor
26
+ self.custom_kwarg = custom_kwarg
27
+ ```
28
+
29
+ Using the `from_lm_components` method provided by this mixin, the component can be instantiated as follows:
30
+ ```python
31
+ component = LMBasedComponent.from_lm_components(
32
+ prompt_builder,
33
+ lm_invoker,
34
+ output_parser,
35
+ custom_kwarg="custom_value",
36
+ )
37
+ ```
38
+
39
+ Building a component with structured output:
40
+ When the component utilizes structured output, the `_parse_structured_output` method can be used
41
+ to simplify the process of extracting the structured output in the component\'s runtime methods, e.g.:
42
+ ```python
43
+ class LMBasedComponent(Component, UsesLM):
44
+ def __init__(self, lm_request_processor: LMRequestProcessor, custom_kwarg: str):
45
+ self.lm_request_processor = lm_request_processor
46
+ self.custom_kwarg = custom_kwarg
47
+
48
+ def runtime_method(self, param1: str, param2: str) -> str:
49
+ lm_output = self.lm_request_processor.process(param1=param1, param2=param2)
50
+ return self._parse_structured_output(lm_output, "target_key", "fallback_output")
51
+ ```
52
+
53
+ Notice that in the above example, the LMRequestProcessor is configured to take `param1` and `param2`
54
+ as keyword arguments and output a structured output that contains the `target_key` key. Hence,
55
+ these conditions must be fulfilled when instantiating the component.
56
+
57
+ This mixin also provides the `with_structured_output` method to simplify the process of instantiating
58
+ the component with structured output. Let\'s take a look at an example that meets the above conditions:
59
+ ```python
60
+ class Schema(BaseModel):
61
+ target_key: str
62
+
63
+ component = LMBasedComponent.with_structured_output(
64
+ model_id="openai/gpt-4.1-mini",
65
+ response_schema=Schema,
66
+ system_template="system_template {param1}",
67
+ user_template="user_template {param2}",
68
+ custom_kwarg="custom_value",
69
+ )
70
+ ```
71
+
72
+ Building a structured output preset:
73
+ If desired, the component can also define a quick preset. This can be done by providing default prompts
74
+ as response schema. Here\'s an example:
75
+ ```python
76
+ class Schema(BaseModel):
77
+ target_key: str
78
+
79
+ @classmethod
80
+ def from_preset(cls, model_id: str, custom_kwarg: str) -> "LMBasedComponent":
81
+ return cls.with_structured_output(
82
+ model_id=model_id,
83
+ response_schema=Schema,
84
+ system_template=PRESET_SYSTEM_TEMPLATE,
85
+ user_template=PRESET_USER_TEMPLATE,
86
+ custom_kwarg=custom_kwarg,
87
+ )
88
+ )
89
+ ```
90
+
91
+ Then, the preset can be instantiated as follows:
92
+ ```python
93
+ component = LMBasedComponent.from_preset(
94
+ model_id="openai/gpt-4.1-mini",
95
+ custom_kwarg="custom_value",
96
+ )
97
+ ```
98
+ '''
99
+ @classmethod
100
+ def from_lm_components(cls, prompt_builder: PromptBuilder, lm_invoker: BaseLMInvoker, output_parser: BaseOutputParser | None = None, **kwargs: Any) -> UsesLM:
101
+ """Creates an instance from LMRequestProcessor components directly.
102
+
103
+ This method is a shortcut to initialize the class by providing the LMRequestProcessor components directly.
104
+
105
+ Args:
106
+ prompt_builder (PromptBuilder): The prompt builder used to format the prompt.
107
+ lm_invoker (BaseLMInvoker): The language model invoker that handles the model inference.
108
+ output_parser (BaseOutputParser, optional): An optional parser to process the model's output.
109
+ Defaults to None.
110
+ **kwargs (Any): Additional keyword arguments to be passed to the class constructor.
111
+
112
+ Returns:
113
+ UsesLM: An instance of the class that mixes in this mixin.
114
+ """
115
+ @classmethod
116
+ def with_structured_output(cls, model_id: str, response_schema: type[BaseModel], system_template: str = '', user_template: str = '', **kwargs: Any) -> UsesLM:
117
+ """Creates an instance with structured output configuration.
118
+
119
+ This method is a shortcut to initialize the class with structured output configuration.
120
+
121
+ Args:
122
+ model_id (str): The model ID of the language model.
123
+ response_schema (type[BaseModel]): The response schema of the language model.
124
+ system_template (str, optional): The system template of the language model. Defaults to an empty string.
125
+ user_template (str, optional): The user template of the language model. Defaults to an empty string.
126
+ **kwargs (Any): Additional keyword arguments to be passed to the class constructor.
127
+
128
+ Returns:
129
+ UsesLM: An instance of the class that mixes in this mixin with structured output configuration.
130
+ """
@@ -0,0 +1,19 @@
1
+ from gllm_inference.schema.activity import Activity as Activity, MCPCallActivity as MCPCallActivity, MCPListToolsActivity as MCPListToolsActivity, WebSearchActivity as WebSearchActivity
2
+ from gllm_inference.schema.attachment import Attachment as Attachment
3
+ from gllm_inference.schema.code_exec_result import CodeExecResult as CodeExecResult
4
+ from gllm_inference.schema.config import TruncationConfig as TruncationConfig
5
+ from gllm_inference.schema.enums import AttachmentType as AttachmentType, BatchStatus as BatchStatus, EmitDataType as EmitDataType, JinjaEnvType as JinjaEnvType, LMEventType as LMEventType, LMEventTypeSuffix as LMEventTypeSuffix, LMOutputType as LMOutputType, MessageRole as MessageRole, TruncateSide as TruncateSide
6
+ from gllm_inference.schema.events import ActivityEvent as ActivityEvent, CodeEvent as CodeEvent, ThinkingEvent as ThinkingEvent
7
+ from gllm_inference.schema.formatter import HistoryFormatter as HistoryFormatter
8
+ from gllm_inference.schema.lm_input import LMInput as LMInput
9
+ from gllm_inference.schema.lm_output import LMOutput as LMOutput, LMOutputData as LMOutputData, LMOutputItem as LMOutputItem
10
+ from gllm_inference.schema.mcp import MCPCall as MCPCall, MCPServer as MCPServer
11
+ from gllm_inference.schema.message import Message as Message
12
+ from gllm_inference.schema.model_id import ModelId as ModelId, ModelProvider as ModelProvider
13
+ from gllm_inference.schema.reasoning import Reasoning as Reasoning
14
+ from gllm_inference.schema.token_usage import InputTokenDetails as InputTokenDetails, OutputTokenDetails as OutputTokenDetails, TokenUsage as TokenUsage
15
+ from gllm_inference.schema.tool_call import ToolCall as ToolCall
16
+ from gllm_inference.schema.tool_result import ToolResult as ToolResult
17
+ from gllm_inference.schema.type_alias import EMContent as EMContent, MessageContent as MessageContent, ResponseSchema as ResponseSchema, Vector as Vector
18
+
19
+ __all__ = ['Activity', 'ActivityEvent', 'Attachment', 'AttachmentType', 'BatchStatus', 'CodeEvent', 'CodeExecResult', 'EMContent', 'EmitDataType', 'HistoryFormatter', 'InputTokenDetails', 'JinjaEnvType', 'LMEventType', 'LMEventTypeSuffix', 'LMInput', 'LMOutput', 'LMOutputItem', 'LMOutputData', 'LMOutputType', 'MCPCall', 'MCPCallActivity', 'MCPListToolsActivity', 'MCPServer', 'Message', 'MessageContent', 'MessageRole', 'ModelId', 'ModelProvider', 'OutputTokenDetails', 'Reasoning', 'ResponseSchema', 'ThinkingEvent', 'TokenUsage', 'ToolCall', 'ToolResult', 'TruncateSide', 'TruncationConfig', 'Vector', 'WebSearchActivity']
@@ -0,0 +1,64 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_inference.schema.enums import ActivityType as ActivityType, WebSearchKey as WebSearchKey
3
+ from pydantic import BaseModel
4
+ from typing import Literal
5
+
6
+ WEB_SEARCH_VISIBLE_FIELDS: Incomplete
7
+ WebSearchActivityTypes: Incomplete
8
+
9
+ class Activity(BaseModel):
10
+ """Base schema for any activity.
11
+
12
+ Attributes:
13
+ type (str): The type of activity being performed. Defaults to an empty string.
14
+ """
15
+ type: str
16
+
17
+ class MCPListToolsActivity(Activity):
18
+ """Schema for listing tools in MCP.
19
+
20
+ Attributes:
21
+ type (Literal[ActivityType.MCP_LIST_TOOLS]): The type of activity being performed.
22
+ Defaults to ActivityType.MCP_LIST_TOOLS.
23
+ server_name (str): The name of the MCP server. Defaults to an empty string.
24
+ tools (list[dict[str, str]] | None): The tools in the MCP server. Defaults to None.
25
+ """
26
+ type: Literal[ActivityType.MCP_LIST_TOOLS]
27
+ server_name: str
28
+ tools: list[dict[str, str]] | None
29
+
30
+ class MCPCallActivity(Activity):
31
+ """Schema for MCP tool call.
32
+
33
+ Attributes:
34
+ type (Literal[ActivityType.MCP_CALL]): The type of activity being performed. Defaults to ActivityType.MCP_CALL.
35
+ server_name (str): The name of the MCP server.
36
+ tool_name (str): The name of the tool.
37
+ args (dict[str, str]): The arguments of the tool.
38
+ """
39
+ type: Literal[ActivityType.MCP_CALL]
40
+ server_name: str
41
+ tool_name: str
42
+ args: dict[str, str]
43
+
44
+ class WebSearchActivity(Activity):
45
+ """Schema for web search tool call.
46
+
47
+ Attributes:
48
+ type (WebSearchActivityTypes): The type of activity being performed. Defaults to ActivityType.SEARCH.
49
+ query (str | None): The query of the web search. Defaults to None.
50
+ url (str | None): The URL of the page. Defaults to None.
51
+ pattern (str | None): The pattern of the web search. Defaults to None.
52
+ sources (list[dict[str, str]] | None): The sources of the web search.
53
+ """
54
+ type: WebSearchActivityTypes
55
+ query: str | None
56
+ url: str | None
57
+ pattern: str | None
58
+ sources: list[dict[str, str]] | None
59
+ def model_dump(self, *args, **kwargs) -> dict[str, str]:
60
+ """Serialize the activity for display.
61
+
62
+ Returns:
63
+ dict[str, str]: The serialized activity.
64
+ """
@@ -0,0 +1,102 @@
1
+ from _typeshed import Incomplete
2
+ from pydantic import BaseModel
3
+ from typing import Any
4
+
5
+ HEX_REPR_LENGTH: int
6
+ METADATA_ITEM_REPR_LENGTH: int
7
+ logger: Incomplete
8
+
9
+ class Attachment(BaseModel):
10
+ """Defines a file attachment schema.
11
+
12
+ Attributes:
13
+ data (bytes): The content data of the file attachment.
14
+ filename (str): The filename of the file attachment.
15
+ mime_type (str): The mime type of the file attachment.
16
+ extension (str): The extension of the file attachment.
17
+ url (str | None): The URL of the file attachment. Defaults to None.
18
+ metadata (dict[str, Any]): The metadata of the file attachment. Defaults to an empty dictionary.
19
+ """
20
+ data: bytes
21
+ filename: str
22
+ mime_type: str
23
+ extension: str
24
+ url: str | None
25
+ metadata: dict[str, Any]
26
+ @classmethod
27
+ def from_bytes(cls, bytes: bytes, filename: str | None = None, metadata: dict[str, Any] | None = None) -> Attachment:
28
+ """Creates an Attachment from bytes.
29
+
30
+ Args:
31
+ bytes (bytes): The bytes of the file.
32
+ filename (str | None, optional): The filename of the file. Defaults to None,
33
+ in which case the filename will be derived from the extension.
34
+ metadata (dict[str, Any] | None, optional): The metadata of the file attachment. Defaults to None,
35
+ in which case an empty dictionary will be used.
36
+
37
+ Returns:
38
+ Attachment: The instantiated Attachment.
39
+ """
40
+ @classmethod
41
+ def from_base64(cls, base64_data: str, filename: str | None = None, metadata: dict[str, Any] | None = None) -> Attachment:
42
+ """Creates an Attachment from a base64 string.
43
+
44
+ Args:
45
+ base64_data (str): The base64 string of the file.
46
+ filename (str | None, optional): The filename of the file. Defaults to None,
47
+ in which case the filename will be derived from the mime type.
48
+ metadata (dict[str, Any] | None, optional): The metadata of the file attachment. Defaults to None,
49
+ in which case an empty dictionary will be used.
50
+
51
+ Returns:
52
+ Attachment: The instantiated Attachment.
53
+ """
54
+ @classmethod
55
+ def from_data_url(cls, data_url: str, filename: str | None = None, metadata: dict[str, Any] | None = None) -> Attachment:
56
+ """Creates an Attachment from a data URL (data:[mime/type];base64,[bytes]).
57
+
58
+ Args:
59
+ data_url (str): The data URL of the file.
60
+ filename (str | None, optional): The filename of the file. Defaults to None,
61
+ in which case the filename will be derived from the mime type.
62
+ metadata (dict[str, Any] | None, optional): The metadata of the file attachment. Defaults to None,
63
+ in which case an empty dictionary will be used.
64
+
65
+ Returns:
66
+ Attachment: The instantiated Attachment.
67
+ """
68
+ @classmethod
69
+ def from_url(cls, url: str, filename: str | None = None, metadata: dict[str, Any] | None = None) -> Attachment:
70
+ """Creates an Attachment from a URL.
71
+
72
+ Args:
73
+ url (str): The URL of the file.
74
+ filename (str | None, optional): The filename of the file. Defaults to None,
75
+ in which case the filename will be derived from the URL.
76
+ metadata (dict[str, Any] | None, optional): The metadata of the file attachment. Defaults to None,
77
+ in which case an empty dictionary will be used.
78
+
79
+ Returns:
80
+ Attachment: The instantiated Attachment.
81
+ """
82
+ @classmethod
83
+ def from_path(cls, path: str, filename: str | None = None, metadata: dict[str, Any] | None = None) -> Attachment:
84
+ """Creates an Attachment from a path.
85
+
86
+ Args:
87
+ path (str): The path to the file.
88
+ filename (str | None, optional): The filename of the file. Defaults to None,
89
+ in which case the filename will be derived from the path.
90
+ metadata (dict[str, Any] | None, optional): The metadata of the file attachment. Defaults to None,
91
+ in which case an empty dictionary will be used.
92
+
93
+ Returns:
94
+ Attachment: The instantiated Attachment.
95
+ """
96
+ def write_to_file(self, path: str | None = None) -> None:
97
+ """Writes the Attachment to a file.
98
+
99
+ Args:
100
+ path (str | None, optional): The path to the file. Defaults to None,
101
+ in which case the filename will be used as the path.
102
+ """
@@ -0,0 +1,14 @@
1
+ from gllm_inference.schema.attachment import Attachment as Attachment
2
+ from pydantic import BaseModel
3
+
4
+ class CodeExecResult(BaseModel):
5
+ """Defines a code execution result when a language model is configured to execute code.
6
+
7
+ Attributes:
8
+ id (str): The ID of the code execution. Defaults to an empty string.
9
+ code (str): The executed code. Defaults to an empty string.
10
+ output (list[str | Attachment]): The output of the executed code. Defaults to an empty list.
11
+ """
12
+ id: str
13
+ code: str
14
+ output: list[str | Attachment]
@@ -0,0 +1,15 @@
1
+ from gllm_inference.schema.enums import TruncateSide as TruncateSide
2
+ from pydantic import BaseModel
3
+
4
+ class TruncationConfig(BaseModel):
5
+ """Configuration for text truncation behavior.
6
+
7
+ Attributes:
8
+ max_length (int): Maximum length of text content. Required.
9
+ truncate_side (TruncateSide | None): Side to truncate from when max_length is exceeded.
10
+ 1. TruncateSide.RIGHT: Keep the beginning of the text, truncate from the end (default)
11
+ 2. TruncateSide.LEFT: Keep the end of the text, truncate from the beginning
12
+ If None, defaults to TruncateSide.RIGHT
13
+ """
14
+ max_length: int
15
+ truncate_side: TruncateSide | None
@@ -0,0 +1,82 @@
1
+ from enum import StrEnum
2
+
3
+ class AttachmentType(StrEnum):
4
+ """Defines valid attachment types."""
5
+ AUDIO = 'audio'
6
+ DOCUMENT = 'document'
7
+ IMAGE = 'image'
8
+ VIDEO = 'video'
9
+
10
+ class BatchStatus(StrEnum):
11
+ """Defines the status of a batch job."""
12
+ IN_PROGRESS = 'in_progress'
13
+ FINISHED = 'finished'
14
+ FAILED = 'failed'
15
+ CANCELING = 'canceling'
16
+ EXPIRED = 'expired'
17
+ UNKNOWN = 'unknown'
18
+
19
+ class LMEventType(StrEnum):
20
+ """Defines event types to be emitted by the LM invoker."""
21
+ ACTIVITY = 'activity'
22
+ CODE = 'code'
23
+ THINKING = 'thinking'
24
+
25
+ class LMEventTypeSuffix(StrEnum):
26
+ """Defines suffixes for LM event types."""
27
+ START = '_start'
28
+ END = '_end'
29
+
30
+ class EmitDataType(StrEnum):
31
+ """Defines valid data types for emitting events."""
32
+ ACTIVITY = 'activity'
33
+ CODE = 'code'
34
+ CODE_START = 'code_start'
35
+ CODE_END = 'code_end'
36
+ THINKING = 'thinking'
37
+ THINKING_START = 'thinking_start'
38
+ THINKING_END = 'thinking_end'
39
+
40
+ class LMOutputType(StrEnum):
41
+ """Defines valid types for language model outputs."""
42
+ TEXT = 'text'
43
+ STRUCTURED = 'structured'
44
+ ATTACHMENT = 'attachment'
45
+ TOOL_CALL = 'tool_call'
46
+ THINKING = 'thinking'
47
+ CITATION = 'citation'
48
+ CODE_EXEC_RESULT = 'code_exec_result'
49
+ MCP_CALL = 'mcp_call'
50
+
51
+ class ActivityType(StrEnum):
52
+ """Defines valid activity types."""
53
+ FIND_IN_PAGE = 'find_in_page'
54
+ MCP_CALL = 'mcp_call'
55
+ MCP_LIST_TOOLS = 'mcp_list_tools'
56
+ OPEN_PAGE = 'open_page'
57
+ SEARCH = 'search'
58
+ WEB_SEARCH = 'web_search'
59
+
60
+ class MessageRole(StrEnum):
61
+ """Defines valid message roles."""
62
+ SYSTEM = 'system'
63
+ USER = 'user'
64
+ ASSISTANT = 'assistant'
65
+
66
+ class TruncateSide(StrEnum):
67
+ """Enumeration for truncation sides."""
68
+ RIGHT = 'RIGHT'
69
+ LEFT = 'LEFT'
70
+
71
+ class JinjaEnvType(StrEnum):
72
+ """Enumeration for Jinja environment types."""
73
+ JINJA_DEFAULT = 'jinja_default'
74
+ RESTRICTED = 'restricted'
75
+
76
+ class WebSearchKey(StrEnum):
77
+ """Defines valid web search keys."""
78
+ PATTERN = 'pattern'
79
+ QUERY = 'query'
80
+ SOURCES = 'sources'
81
+ TYPE = 'type'
82
+ URL = 'url'
@@ -0,0 +1,105 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_core.constants import EventType
3
+ from gllm_core.schema import Event
4
+ from gllm_inference.schema.activity import Activity as Activity
5
+ from typing import Any, Literal, Self
6
+
7
+ CodeEventType: Incomplete
8
+ ThinkingEventType: Incomplete
9
+
10
+ class ActivityEvent(Event):
11
+ """Event schema for model-triggered activities (e.g. web search, MCP call, etc.).
12
+
13
+ Attributes:
14
+ id (str): The ID of the activity event. Defaults to None.
15
+ value (dict[str, Any]): The value of the activity event.
16
+ level (EventLevel): The severity level of the activity event. Defaults to EventLevel.INFO.
17
+ type (Literal[EventType.ACTIVITY]): The type of the activity event. Defaults to EventType.ACTIVITY.
18
+ timestamp (datetime): The timestamp of the activity event. Defaults to the current timestamp.
19
+ metadata (dict[str, Any]): The metadata of the activity event. Defaults to an empty dictionary.
20
+ """
21
+ value: dict[str, Any]
22
+ type: Literal[EventType.ACTIVITY]
23
+ @classmethod
24
+ def from_activity(cls, id_: str | None = None, activity: Activity | None = None) -> ActivityEvent:
25
+ """Create an activity event from an Activity object.
26
+
27
+ Args:
28
+ id_ (str | None, optional): The ID of the activity event. Defaults to None.
29
+ activity (Activity | None, optional): The activity object to create the event from.
30
+ Defaults to None, in which case the value will be an empty dictionary.
31
+
32
+ Returns:
33
+ ActivityEvent: The activity event.
34
+ """
35
+
36
+ class BlockBasedEvent(Event):
37
+ """Event schema block-based events, which are limited by start and end events.
38
+
39
+ Attributes:
40
+ id (str): The ID of the block-based event. Defaults to None.
41
+ value (str): The value of the block-based event. Defaults to an empty string.
42
+ level (EventLevel): The severity level of the block-based event. Defaults to EventLevel.INFO.
43
+ type (str): The type of the block-based event. Defaults to an empty string.
44
+ timestamp (datetime): The timestamp of the block-based event. Defaults to the current timestamp.
45
+ metadata (dict[str, Any]): The metadata of the block-based event. Defaults to an empty dictionary.
46
+ """
47
+ value: str
48
+ type: str
49
+ @classmethod
50
+ def start(cls, id_: str | None = None) -> Self:
51
+ """Create a block-based start event.
52
+
53
+ Args:
54
+ id_ (str | None, optional): The ID of the block-based event. Defaults to None.
55
+
56
+ Returns:
57
+ Self: The block-based start event.
58
+ """
59
+ @classmethod
60
+ def content(cls, id_: str | None = None, value: str = '') -> Self:
61
+ """Create a block-based content event.
62
+
63
+ Args:
64
+ id_ (str | None, optional): The ID of the block-based event. Defaults to None.
65
+ value (str, optional): The block-based content. Defaults to an empty string.
66
+
67
+ Returns:
68
+ Self: The block-based content event.
69
+ """
70
+ @classmethod
71
+ def end(cls, id_: str | None = None) -> Self:
72
+ """Create a block-based end event.
73
+
74
+ Args:
75
+ id_ (str | None, optional): The ID of the block-based event. Defaults to None.
76
+
77
+ Returns:
78
+ Self: The block-based end event.
79
+ """
80
+
81
+ class CodeEvent(BlockBasedEvent):
82
+ """Event schema for model-generated code to be executed.
83
+
84
+ Attributes:
85
+ id (str): The ID of the code event. Defaults to None.
86
+ value (str): The value of the code event. Defaults to an empty string.
87
+ level (EventLevel): The severity level of the code event. Defaults to EventLevel.INFO.
88
+ type (CodeEventType): The type of the code event. Defaults to EventType.CODE.
89
+ timestamp (datetime): The timestamp of the code event. Defaults to the current timestamp.
90
+ metadata (dict[str, Any]): The metadata of the code event. Defaults to an empty dictionary.
91
+ """
92
+ type: CodeEventType
93
+
94
+ class ThinkingEvent(BlockBasedEvent):
95
+ """Event schema for model-generated thinking.
96
+
97
+ Attributes:
98
+ id (str): The ID of the thinking event. Defaults to None.
99
+ value (str): The value of the thinking event. Defaults to an empty string.
100
+ level (EventLevel): The severity level of the thinking event. Defaults to EventLevel.INFO.
101
+ type (ThinkingEventType): The type of the thinking event. Defaults to EventType.THINKING.
102
+ timestamp (datetime): The timestamp of the thinking event. Defaults to the current timestamp.
103
+ metadata (dict[str, Any]): The metadata of the thinking event. Defaults to an empty dictionary.
104
+ """
105
+ type: ThinkingEventType
@@ -0,0 +1,31 @@
1
+ from gllm_inference.schema.enums import MessageRole as MessageRole
2
+ from gllm_inference.schema.message import Message as Message
3
+ from gllm_inference.schema.type_alias import MessageContent as MessageContent
4
+ from pydantic import BaseModel
5
+
6
+ class HistoryFormatter(BaseModel):
7
+ """Configuration for history formatting.
8
+
9
+ Attributes:
10
+ prefix_user_message (str): Prefix for user messages.
11
+ suffix_user_message (str): Suffix for user messages.
12
+ prefix_assistant_message (str): Prefix for assistant messages.
13
+ suffix_assistant_message (str): Suffix for assistant messages.
14
+ """
15
+ prefix_user_message: str
16
+ suffix_user_message: str
17
+ prefix_assistant_message: str
18
+ suffix_assistant_message: str
19
+ def format_history(self, history: list[Message]) -> list[Message]:
20
+ """Formats a list of messages based on their roles.
21
+
22
+ This method formats each message in the history list by applying the appropriate
23
+ formatting based on the message role (user or assistant). Other message types
24
+ are added to the result without modification.
25
+
26
+ Args:
27
+ history (list[Message]): The list of messages to format.
28
+
29
+ Returns:
30
+ list[Message]: A new list containing the formatted messages.
31
+ """
@@ -0,0 +1,4 @@
1
+ from gllm_inference.schema.message import Message as Message
2
+ from gllm_inference.schema.type_alias import MessageContent as MessageContent
3
+
4
+ LMInput = list[Message] | list[MessageContent] | str