gllm-inference-binary 0.5.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of gllm-inference-binary might be problematic. Click here for more details.

Files changed (94) hide show
  1. gllm_inference/__init__.pyi +0 -0
  2. gllm_inference/builder/__init__.pyi +6 -0
  3. gllm_inference/builder/build_em_invoker.pyi +122 -0
  4. gllm_inference/builder/build_lm_invoker.pyi +150 -0
  5. gllm_inference/builder/build_lm_request_processor.pyi +93 -0
  6. gllm_inference/builder/build_output_parser.pyi +29 -0
  7. gllm_inference/catalog/__init__.pyi +4 -0
  8. gllm_inference/catalog/catalog.pyi +121 -0
  9. gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
  10. gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
  11. gllm_inference/constants.pyi +10 -0
  12. gllm_inference/em_invoker/__init__.pyi +9 -0
  13. gllm_inference/em_invoker/azure_openai_em_invoker.pyi +86 -0
  14. gllm_inference/em_invoker/em_invoker.pyi +83 -0
  15. gllm_inference/em_invoker/google_em_invoker.pyi +124 -0
  16. gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
  17. gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +62 -0
  18. gllm_inference/em_invoker/langchain_em_invoker.pyi +41 -0
  19. gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +92 -0
  20. gllm_inference/em_invoker/openai_em_invoker.pyi +86 -0
  21. gllm_inference/em_invoker/schema/__init__.pyi +0 -0
  22. gllm_inference/em_invoker/schema/google.pyi +7 -0
  23. gllm_inference/em_invoker/schema/langchain.pyi +4 -0
  24. gllm_inference/em_invoker/schema/openai.pyi +7 -0
  25. gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
  26. gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
  27. gllm_inference/em_invoker/schema/voyage.pyi +15 -0
  28. gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +99 -0
  29. gllm_inference/em_invoker/voyage_em_invoker.pyi +101 -0
  30. gllm_inference/exceptions/__init__.pyi +4 -0
  31. gllm_inference/exceptions/error_parser.pyi +48 -0
  32. gllm_inference/exceptions/exceptions.pyi +120 -0
  33. gllm_inference/lm_invoker/__init__.pyi +11 -0
  34. gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +275 -0
  35. gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +253 -0
  36. gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +232 -0
  37. gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +166 -0
  38. gllm_inference/lm_invoker/google_lm_invoker.pyi +310 -0
  39. gllm_inference/lm_invoker/langchain_lm_invoker.pyi +258 -0
  40. gllm_inference/lm_invoker/litellm_lm_invoker.pyi +248 -0
  41. gllm_inference/lm_invoker/lm_invoker.pyi +151 -0
  42. gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +265 -0
  43. gllm_inference/lm_invoker/openai_lm_invoker.pyi +361 -0
  44. gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
  45. gllm_inference/lm_invoker/schema/anthropic.pyi +50 -0
  46. gllm_inference/lm_invoker/schema/bedrock.pyi +48 -0
  47. gllm_inference/lm_invoker/schema/datasaur.pyi +12 -0
  48. gllm_inference/lm_invoker/schema/google.pyi +24 -0
  49. gllm_inference/lm_invoker/schema/langchain.pyi +22 -0
  50. gllm_inference/lm_invoker/schema/openai.pyi +90 -0
  51. gllm_inference/lm_invoker/schema/openai_compatible.pyi +56 -0
  52. gllm_inference/model/__init__.pyi +9 -0
  53. gllm_inference/model/em/__init__.pyi +0 -0
  54. gllm_inference/model/em/google_em.pyi +16 -0
  55. gllm_inference/model/em/openai_em.pyi +15 -0
  56. gllm_inference/model/em/twelvelabs_em.pyi +13 -0
  57. gllm_inference/model/em/voyage_em.pyi +20 -0
  58. gllm_inference/model/lm/__init__.pyi +0 -0
  59. gllm_inference/model/lm/anthropic_lm.pyi +20 -0
  60. gllm_inference/model/lm/google_lm.pyi +17 -0
  61. gllm_inference/model/lm/openai_lm.pyi +27 -0
  62. gllm_inference/output_parser/__init__.pyi +3 -0
  63. gllm_inference/output_parser/json_output_parser.pyi +60 -0
  64. gllm_inference/output_parser/output_parser.pyi +27 -0
  65. gllm_inference/prompt_builder/__init__.pyi +3 -0
  66. gllm_inference/prompt_builder/prompt_builder.pyi +56 -0
  67. gllm_inference/prompt_formatter/__init__.pyi +7 -0
  68. gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
  69. gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
  70. gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
  71. gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
  72. gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
  73. gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
  74. gllm_inference/request_processor/__init__.pyi +4 -0
  75. gllm_inference/request_processor/lm_request_processor.pyi +92 -0
  76. gllm_inference/request_processor/uses_lm_mixin.pyi +50 -0
  77. gllm_inference/schema/__init__.pyi +13 -0
  78. gllm_inference/schema/attachment.pyi +88 -0
  79. gllm_inference/schema/code_exec_result.pyi +14 -0
  80. gllm_inference/schema/enums.pyi +24 -0
  81. gllm_inference/schema/lm_output.pyi +36 -0
  82. gllm_inference/schema/message.pyi +52 -0
  83. gllm_inference/schema/model_id.pyi +138 -0
  84. gllm_inference/schema/reasoning.pyi +15 -0
  85. gllm_inference/schema/token_usage.pyi +11 -0
  86. gllm_inference/schema/tool_call.pyi +14 -0
  87. gllm_inference/schema/tool_result.pyi +11 -0
  88. gllm_inference/schema/type_alias.pyi +15 -0
  89. gllm_inference/utils/__init__.pyi +4 -0
  90. gllm_inference/utils/langchain.pyi +30 -0
  91. gllm_inference/utils/validation.pyi +12 -0
  92. gllm_inference_binary-0.5.9.dist-info/METADATA +108 -0
  93. gllm_inference_binary-0.5.9.dist-info/RECORD +94 -0
  94. gllm_inference_binary-0.5.9.dist-info/WHEEL +4 -0
@@ -0,0 +1,232 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_core.event import EventEmitter as EventEmitter
3
+ from gllm_core.schema.tool import Tool as Tool
4
+ from gllm_core.utils.retry import RetryConfig as RetryConfig
5
+ from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
6
+ from gllm_inference.lm_invoker.schema.bedrock import InputType as InputType, Key as Key, OutputType as OutputType
7
+ from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, LMOutput as LMOutput, Message as Message, ModelId as ModelId, ModelProvider as ModelProvider, ResponseSchema as ResponseSchema, TokenUsage as TokenUsage, ToolCall as ToolCall, ToolResult as ToolResult
8
+ from langchain_core.tools import Tool as LangChainTool
9
+ from typing import Any
10
+
11
+ SUPPORTED_ATTACHMENTS: Incomplete
12
+
13
+ class BedrockLMInvoker(BaseLMInvoker):
14
+ '''A language model invoker to interact with AWS Bedrock language models.
15
+
16
+ Attributes:
17
+ model_id (str): The model ID of the language model.
18
+ model_provider (str): The provider of the language model.
19
+ model_name (str): The name of the language model.
20
+ session (Session): The Bedrock client session.
21
+ client_kwargs (dict[str, Any]): The Bedrock client kwargs.
22
+ default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
23
+ tools (list[Tool]): Tools provided to the model to enable tool calling.
24
+ response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
25
+ structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
26
+ output_analytics (bool): Whether to output the invocation analytics.
27
+ retry_config (RetryConfig): The retry configuration for the language model.
28
+
29
+ Basic usage:
30
+ The `BedrockLMInvoker` can be used as follows:
31
+ ```python
32
+ lm_invoker = BedrockLMInvoker(
33
+ model_name="us.anthropic.claude-sonnet-4-20250514-v1:0",
34
+ aws_access_key_id="<your-aws-access-key-id>",
35
+ aws_secret_access_key="<your-aws-secret-access-key>",
36
+ )
37
+ result = await lm_invoker.invoke("Hi there!")
38
+ ```
39
+
40
+ Input types:
41
+ The `BedrockLMInvoker` supports the following input types: text, document, image, and video.
42
+ Non-text inputs can be passed as an `Attachment` object with the `user` role.
43
+
44
+ Usage example:
45
+ ```python
46
+ text = "What animal is in this image?"
47
+ image = Attachment.from_path("path/to/local/image.png")
48
+ result = await lm_invoker.invoke([text, image])
49
+ ```
50
+
51
+ Tool calling:
52
+ Tool calling is a feature that allows the language model to call tools to perform tasks.
53
+ Tools can be passed to the via the `tools` parameter as a list of `Tool` objects.
54
+ When tools are provided and the model decides to call a tool, the tool calls are stored in the
55
+ `tool_calls` attribute in the output.
56
+
57
+ Usage example:
58
+ ```python
59
+ lm_invoker = BedrockLMInvoker(..., tools=[tool_1, tool_2])
60
+ ```
61
+
62
+ Output example:
63
+ ```python
64
+ LMOutput(
65
+ response="Let me call the tools...",
66
+ tool_calls=[
67
+ ToolCall(id="123", name="tool_1", args={"key": "value"}),
68
+ ToolCall(id="456", name="tool_2", args={"key": "value"}),
69
+ ]
70
+ )
71
+ ```
72
+
73
+ Structured output:
74
+ Structured output is a feature that allows the language model to output a structured response.
75
+ This feature can be enabled by providing a schema to the `response_schema` parameter.
76
+
77
+ The schema must be either a JSON schema dictionary or a Pydantic BaseModel class.
78
+ If JSON schema is used, it must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
79
+ For this reason, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
80
+
81
+ Structured output is achieved by providing the schema name in the `tool_choice` parameter. This forces
82
+ the model to call the provided schema as a tool. Thus, structured output is not compatible with tool calling,
83
+ since the tool calling is reserved to force the model to call the provided schema as a tool.
84
+ The language model also doesn\'t need to stream anything when structured output is enabled. Thus, standard
85
+ invocation will be performed regardless of whether the `event_emitter` parameter is provided or not.
86
+
87
+ When enabled, the structured output is stored in the `structured_output` attribute in the output.
88
+ 1. If the schema is a JSON schema dictionary, the structured output is a dictionary.
89
+ 2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
90
+
91
+ # Example 1: Using a JSON schema dictionary
92
+ Usage example:
93
+ ```python
94
+ schema = {
95
+ "title": "Animal",
96
+ "description": "A description of an animal.",
97
+ "properties": {
98
+ "color": {"title": "Color", "type": "string"},
99
+ "name": {"title": "Name", "type": "string"},
100
+ },
101
+ "required": ["name", "color"],
102
+ "type": "object",
103
+ }
104
+ lm_invoker = BedrockLMInvoker(..., response_schema=schema)
105
+ ```
106
+ Output example:
107
+ ```python
108
+ LMOutput(structured_output={"name": "Golden retriever", "color": "Golden"})
109
+ ```
110
+
111
+ # Example 2: Using a Pydantic BaseModel class
112
+ Usage example:
113
+ ```python
114
+ class Animal(BaseModel):
115
+ name: str
116
+ color: str
117
+
118
+ lm_invoker = BedrockLMInvoker(..., response_schema=Animal)
119
+ ```
120
+ Output example:
121
+ ```python
122
+ LMOutput(structured_output=Animal(name="Golden retriever", color="Golden"))
123
+ ```
124
+
125
+ Analytics tracking:
126
+ Analytics tracking is a feature that allows the module to output additional information about the invocation.
127
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
128
+ When enabled, the following attributes will be stored in the output:
129
+ 1. `token_usage`: The token usage.
130
+ 2. `duration`: The duration in seconds.
131
+ 3. `finish_details`: The details about how the generation finished.
132
+
133
+ Output example:
134
+ ```python
135
+ LMOutput(
136
+ response="Golden retriever is a good dog breed.",
137
+ token_usage=TokenUsage(input_tokens=100, output_tokens=50),
138
+ duration=0.729,
139
+ finish_details={"stop_reason": "end_turn"},
140
+ )
141
+ ```
142
+
143
+ Retry and timeout:
144
+ The `BedrockLMInvoker` supports retry and timeout configuration.
145
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
146
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
147
+
148
+ Retry config examples:
149
+ ```python
150
+ retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
151
+ retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
152
+ retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
153
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
154
+ ```
155
+
156
+ Usage example:
157
+ ```python
158
+ lm_invoker = BedrockLMInvoker(..., retry_config=retry_config)
159
+ ```
160
+
161
+ Output types:
162
+ The output of the `BedrockLMInvoker` can either be:
163
+ 1. `str`: The text response if no additional output is needed.
164
+ 2. `LMOutput`: A Pydantic model with the following attributes if any additional output is needed:
165
+ 2.1. response (str): The text response.
166
+ 2.2. tool_calls (list[ToolCall]): The tool calls, if the `tools` parameter is defined and the language
167
+ model decides to invoke tools. Defaults to an empty list.
168
+ 2.3. structured_output (dict[str, Any] | BaseModel | None): The structured output, if the `response_schema`
169
+ parameter is defined. Defaults to None.
170
+ 2.4. token_usage (TokenUsage | None): The token usage information, if the `output_analytics` parameter is
171
+ set to `True`. Defaults to None.
172
+ 2.5. duration (float | None): The duration of the invocation in seconds, if the `output_analytics`
173
+ parameter is set to `True`. Defaults to None.
174
+ 2.6. finish_details (dict[str, Any]): The details about how the generation finished, if the
175
+ `output_analytics` parameter is set to `True`. Defaults to an empty dictionary.
176
+ 2.7. reasoning (list[Reasoning]): The reasoning objects. Currently not supported. Defaults to an empty list.
177
+ 2.8. citations (list[Chunk]): The citations. Currently not supported. Defaults to an empty list.
178
+ 2.9. code_exec_results (list[CodeExecResult]): The code execution results. Currently not supported.
179
+ Defaults to an empty list.
180
+ '''
181
+ session: Incomplete
182
+ client_kwargs: Incomplete
183
+ def __init__(self, model_name: str, access_key_id: str | None = None, secret_access_key: str | None = None, region_name: str = 'us-east-1', model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, tools: list[Tool | LangChainTool] | None = None, response_schema: ResponseSchema | None = None, output_analytics: bool = False, retry_config: RetryConfig | None = None) -> None:
184
+ '''Initializes the BedrockLMInvoker instance.
185
+
186
+ Args:
187
+ model_name (str): The name of the Bedrock language model.
188
+ access_key_id (str | None, optional): The AWS access key ID. Defaults to None, in which case
189
+ the `AWS_ACCESS_KEY_ID` environment variable will be used.
190
+ secret_access_key (str | None, optional): The AWS secret access key. Defaults to None, in which case
191
+ the `AWS_SECRET_ACCESS_KEY` environment variable will be used.
192
+ region_name (str, optional): The AWS region name. Defaults to "us-east-1".
193
+ model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the Bedrock client.
194
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
195
+ Defaults to None.
196
+ tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
197
+ Defaults to None.
198
+ response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
199
+ output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
200
+ dictionary. Defaults to None.
201
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
202
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
203
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
204
+
205
+ Raises:
206
+ ValueError: If `response_schema` is provided, but `tools` are also provided.
207
+ ValueError: If `access_key_id` or `secret_access_key` is neither provided nor set in the
208
+ `AWS_ACCESS_KEY_ID` or `AWS_SECRET_ACCESS_KEY` environment variables, respectively.
209
+ '''
210
+ def set_tools(self, tools: list[Tool | LangChainTool]) -> None:
211
+ """Sets the tools for the Bedrock language model.
212
+
213
+ This method sets the tools for the Bedrock language model. Any existing tools will be replaced.
214
+
215
+ Args:
216
+ tools (list[Tool | LangChainTool]): The list of tools to be used.
217
+
218
+ Raises:
219
+ ValueError: If `response_schema` exists.
220
+ """
221
+ def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
222
+ """Sets the response schema for the Bedrock language model.
223
+
224
+ This method sets the response schema for the Bedrock language model. Any existing response schema will be
225
+ replaced.
226
+
227
+ Args:
228
+ response_schema (ResponseSchema | None): The response schema to be used.
229
+
230
+ Raises:
231
+ ValueError: If `tools` exists.
232
+ """
@@ -0,0 +1,166 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_core.event import EventEmitter as EventEmitter
3
+ from gllm_core.schema.tool import Tool as Tool
4
+ from gllm_core.utils.retry import RetryConfig as RetryConfig
5
+ from gllm_inference.constants import DOCUMENT_MIME_TYPES as DOCUMENT_MIME_TYPES, INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
6
+ from gllm_inference.lm_invoker.openai_compatible_lm_invoker import OpenAICompatibleLMInvoker as OpenAICompatibleLMInvoker
7
+ from gllm_inference.lm_invoker.schema.datasaur import InputType as InputType, Key as Key
8
+ from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, LMOutput as LMOutput, Message as Message, ModelId as ModelId, ModelProvider as ModelProvider, ResponseSchema as ResponseSchema, ToolCall as ToolCall, ToolResult as ToolResult
9
+ from langchain_core.tools import Tool as LangChainTool
10
+ from typing import Any
11
+
12
+ SUPPORTED_ATTACHMENTS: Incomplete
13
+
14
+ class DatasaurLMInvoker(OpenAICompatibleLMInvoker):
15
+ '''A language model invoker to interact with Datasaur LLM Projects Deployment API.
16
+
17
+ Attributes:
18
+ model_id (str): The model ID of the language model.
19
+ model_provider (str): The provider of the language model.
20
+ model_name (str): The name of the language model.
21
+ client (AsyncOpenAI): The OpenAI client instance.
22
+ default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
23
+ tools (list[Any]): The list of tools provided to the model to enable tool calling. Currently not supported.
24
+ response_schema (ResponseSchema | None): The schema of the response. Currently not supported.
25
+ output_analytics (bool): Whether to output the invocation analytics.
26
+ retry_config (RetryConfig | None): The retry configuration for the language model.
27
+ citations (bool): Whether to output the citations.
28
+
29
+ Basic usage:
30
+ The `DatasaurLMInvoker` can be used as follows:
31
+ ```python
32
+ lm_invoker = DatasaurLMInvoker(base_url="https://deployment.datasaur.ai/api/deployment/teamId/deploymentId/")
33
+ result = await lm_invoker.invoke("Hi there!")
34
+ ```
35
+
36
+ Input types:
37
+ The `DatasaurLMInvoker` supports the following input types: text, audio, image, and document.
38
+ Non-text inputs can be passed as an `Attachment` object with the `user` role.
39
+
40
+ Usage example:
41
+ ```python
42
+ text = "What animal is in this image?"
43
+ image = Attachment.from_path("path/to/local/image.png")
44
+ result = await lm_invoker.invoke([text, image])
45
+ ```
46
+
47
+ Analytics tracking:
48
+ Analytics tracking is a feature that allows the module to output additional information about the invocation.
49
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
50
+ When enabled, the following attributes will be stored in the output:
51
+ 1. `token_usage`: The token usage.
52
+ 2. `duration`: The duration in seconds.
53
+ 3. `finish_details`: The details about how the generation finished.
54
+
55
+ Output example:
56
+ ```python
57
+ LMOutput(
58
+ response="Golden retriever is a good dog breed.",
59
+ token_usage=TokenUsage(input_tokens=100, output_tokens=50),
60
+ duration=0.729,
61
+ finish_details={"finish_reason": "stop"},
62
+ )
63
+ ```
64
+
65
+ When streaming is enabled, token usage is not supported. Therefore, the `token_usage` attribute will be `None`
66
+ regardless of the value of the `output_analytics` parameter.
67
+
68
+ Retry and timeout:
69
+ The `DatasaurLMInvoker` supports retry and timeout configuration.
70
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
71
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
72
+
73
+ Retry config examples:
74
+ ```python
75
+ retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
76
+ retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
77
+ retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
78
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
79
+ ```
80
+
81
+ Usage example:
82
+ ```python
83
+ lm_invoker = DatasaurLMInvoker(..., retry_config=retry_config)
84
+ ```
85
+
86
+ Citations:
87
+ The `DatasaurLMInvoker` can be configured to output the citations used to generate the response.
88
+ They can be enabled by setting the `citations` parameter to `True`.
89
+ When enabled, the citations will be stored as `Chunk` objects in the `citations` attribute in the output.
90
+
91
+ Usage example:
92
+ ```python
93
+ lm_invoker = DatasaurLMInvoker(..., citations=True)
94
+ ```
95
+
96
+ Output example:
97
+ ```python
98
+ LMOutput(
99
+ response="The winner of the match is team A ([Example title](https://www.example.com)).",
100
+ citations=[Chunk(id="123", content="...", metadata={...}, score=0.95)],
101
+ )
102
+ ```
103
+
104
+ Output types:
105
+ The output of the `DatasaurLMInvoker` can either be:
106
+ 1. `str`: The text response if no additional output is needed.
107
+ 2. `LMOutput`: A Pydantic model with the following attributes if any additional output is needed:
108
+ 2.1. response (str): The text response.
109
+ 2.2. tool_calls (list[ToolCall]): The tool calls. Currently not supported. Defaults to an empty list.
110
+ 2.3. structured_output (dict[str, Any] | BaseModel | None): The structured output. Currently not supported.
111
+ Defaults to None.
112
+ 2.4. token_usage (TokenUsage | None): The token usage analytics, if the `output_analytics` parameter is
113
+ set to `True`. Defaults to None.
114
+ 2.5. duration (float | None): The duration of the invocation in seconds, if the `output_analytics`
115
+ parameter is set to `True`. Defaults to None.
116
+ 2.6. finish_details (dict[str, Any] | None): The details about how the generation finished, if the
117
+ `output_analytics` parameter is set to `True`. Defaults to None.
118
+ 2.7. reasoning (list[Reasoning]): The reasoning objects. Currently not supported. Defaults to an empty list.
119
+ 2.8. citations (list[Chunk]): The citations. Currently not supported. Defaults to an empty list.
120
+ 2.9. code_exec_results (list[CodeExecResult]): The code execution results. Currently not supported.
121
+ Defaults to an empty list.
122
+ '''
123
+ client: Incomplete
124
+ citations: Incomplete
125
+ def __init__(self, base_url: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, output_analytics: bool = False, retry_config: RetryConfig | None = None, citations: bool = False) -> None:
126
+ """Initializes a new instance of the DatasaurLMInvoker class.
127
+
128
+ Args:
129
+ base_url (str): The base URL of the Datasaur LLM Projects Deployment API.
130
+ api_key (str | None, optional): The API key for authenticating with Datasaur LLM Projects Deployment API.
131
+ Defaults to None, in which case the `DATASAUR_API_KEY` environment variable will be used.
132
+ model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
133
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
134
+ Defaults to None.
135
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
136
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
137
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
138
+ citations (bool, optional): Whether to output the citations. Defaults to False.
139
+
140
+ Raises:
141
+ ValueError: If the `api_key` is not provided and the `DATASAUR_API_KEY` environment variable is not set.
142
+ """
143
+ def set_tools(self, tools: list[Tool | LangChainTool]) -> None:
144
+ """Sets the tools for the Datasaur LLM Projects Deployment API.
145
+
146
+ This method is raises a `NotImplementedError` because the Datasaur LLM Projects Deployment API does not
147
+ support tools.
148
+
149
+ Args:
150
+ tools (list[Tool | LangChainTool]): The list of tools to be used.
151
+
152
+ Raises:
153
+ NotImplementedError: This method is not supported for the Datasaur LLM Projects Deployment API.
154
+ """
155
+ def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
156
+ """Sets the response schema for the Datasaur LLM Projects Deployment API.
157
+
158
+ This method is raises a `NotImplementedError` because the Datasaur LLM Projects Deployment API does not
159
+ support response schema.
160
+
161
+ Args:
162
+ response_schema (ResponseSchema | None): The response schema to be used.
163
+
164
+ Raises:
165
+ NotImplementedError: This method is not supported for the Datasaur LLM Projects Deployment API.
166
+ """