llama-stack-haystack 1.2.0__py3-none-any.whl → 2.0.0__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.
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
- from typing import Any, Dict, Optional
5
+ from typing import Any
6
6
 
7
7
  from haystack import component, default_from_dict, default_to_dict, logging
8
8
  from haystack.components.generators.chat import OpenAIChatGenerator
@@ -10,6 +10,8 @@ from haystack.dataclasses import StreamingCallbackT
10
10
  from haystack.tools import ToolsType, deserialize_tools_or_toolset_inplace, serialize_tools_or_toolset
11
11
  from haystack.utils import deserialize_callable, serialize_callable
12
12
  from haystack.utils.auth import Secret
13
+ from openai.lib._pydantic import to_strict_json_schema
14
+ from pydantic import BaseModel
13
15
 
14
16
  logger = logging.getLogger(__name__)
15
17
 
@@ -58,14 +60,14 @@ class LlamaStackChatGenerator(OpenAIChatGenerator):
58
60
  *,
59
61
  model: str,
60
62
  api_base_url: str = "http://localhost:8321/v1/openai/v1",
61
- organization: Optional[str] = None,
62
- streaming_callback: Optional[StreamingCallbackT] = None,
63
- generation_kwargs: Optional[Dict[str, Any]] = None,
64
- timeout: Optional[int] = None,
65
- tools: Optional[ToolsType] = None,
63
+ organization: str | None = None,
64
+ streaming_callback: StreamingCallbackT | None = None,
65
+ generation_kwargs: dict[str, Any] | None = None,
66
+ timeout: int | None = None,
67
+ tools: ToolsType | None = None,
66
68
  tools_strict: bool = False,
67
- max_retries: Optional[int] = None,
68
- http_client_kwargs: Optional[Dict[str, Any]] = None,
69
+ max_retries: int | None = None,
70
+ http_client_kwargs: dict[str, Any] | None = None,
69
71
  ):
70
72
  """
71
73
  Creates an instance of LlamaStackChatGenerator. To use this chat generator,
@@ -94,6 +96,13 @@ class LlamaStackChatGenerator(OpenAIChatGenerator):
94
96
  events as they become available, with the stream terminated by a data: [DONE] message.
95
97
  - `safe_prompt`: Whether to inject a safety prompt before all conversations.
96
98
  - `random_seed`: The seed to use for random sampling.
99
+ - `response_format`: A JSON schema or a Pydantic model that enforces the structure of the model's response.
100
+ If provided, the output will always be validated against this
101
+ format (unless the model returns a tool call).
102
+ For details, see the [OpenAI Structured Outputs documentation](https://platform.openai.com/docs/guides/structured-outputs).
103
+ Notes:
104
+ - For structured outputs with streaming,
105
+ the `response_format` must be a JSON schema and not a Pydantic model.
97
106
  :param timeout:
98
107
  Timeout for client calls using OpenAI API. If not set, it defaults to either the
99
108
  `OPENAI_TIMEOUT` environment variable, or 30 seconds.
@@ -129,7 +138,7 @@ class LlamaStackChatGenerator(OpenAIChatGenerator):
129
138
  http_client_kwargs=http_client_kwargs,
130
139
  )
131
140
 
132
- def to_dict(self) -> Dict[str, Any]:
141
+ def to_dict(self) -> dict[str, Any]:
133
142
  """
134
143
  Serialize this component to a dictionary.
135
144
 
@@ -137,13 +146,29 @@ class LlamaStackChatGenerator(OpenAIChatGenerator):
137
146
  The serialized component as a dictionary.
138
147
  """
139
148
  callback_name = serialize_callable(self.streaming_callback) if self.streaming_callback else None
149
+ generation_kwargs = self.generation_kwargs.copy()
150
+ response_format = generation_kwargs.get("response_format")
151
+ # If the response format is a Pydantic model, it's converted to openai's json schema format
152
+ # If it's already a json schema, it's left as is
153
+ if response_format and isinstance(response_format, type) and issubclass(response_format, BaseModel):
154
+ json_schema = {
155
+ "type": "json_schema",
156
+ "json_schema": {
157
+ "name": response_format.__name__,
158
+ "strict": True,
159
+ "schema": to_strict_json_schema(response_format),
160
+ },
161
+ }
162
+
163
+ generation_kwargs["response_format"] = json_schema
164
+
140
165
  return default_to_dict(
141
166
  self,
142
167
  model=self.model,
143
168
  streaming_callback=callback_name,
144
169
  api_base_url=self.api_base_url,
145
170
  organization=self.organization,
146
- generation_kwargs=self.generation_kwargs,
171
+ generation_kwargs=generation_kwargs,
147
172
  timeout=self.timeout,
148
173
  max_retries=self.max_retries,
149
174
  tools=serialize_tools_or_toolset(self.tools),
@@ -152,7 +177,7 @@ class LlamaStackChatGenerator(OpenAIChatGenerator):
152
177
  )
153
178
 
154
179
  @classmethod
155
- def from_dict(cls, data: Dict[str, Any]) -> "LlamaStackChatGenerator":
180
+ def from_dict(cls, data: dict[str, Any]) -> "LlamaStackChatGenerator":
156
181
  """
157
182
  Deserialize this component from a dictionary.
158
183
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: llama-stack-haystack
3
- Version: 1.2.0
3
+ Version: 2.0.0
4
4
  Summary: Use Llama Stack framework for text generation
5
5
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/llama-stack#readme
6
6
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
@@ -16,8 +16,8 @@ Classifier: Programming Language :: Python :: 3.13
16
16
  Classifier: Programming Language :: Python :: Implementation :: CPython
17
17
  Classifier: Programming Language :: Python :: Implementation :: PyPy
18
18
  Requires-Python: >=3.12
19
- Requires-Dist: haystack-ai>=2.19.0
20
- Requires-Dist: llama-stack>=0.2.17
19
+ Requires-Dist: haystack-ai>=2.22.0
20
+ Requires-Dist: llama-stack<0.4.0,>=0.2.17
21
21
  Description-Content-Type: text/markdown
22
22
 
23
23
  # llama-stack-haystack
@@ -1,8 +1,8 @@
1
1
  haystack_integrations/components/generators/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  haystack_integrations/components/generators/llama_stack/__init__.py,sha256=Zx6ZeC2pqN_CYjjRLXO7gQmPlq-n1FNlC_tIKAH6OL0,96
3
3
  haystack_integrations/components/generators/llama_stack/chat/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- haystack_integrations/components/generators/llama_stack/chat/chat_generator.py,sha256=0I8jWGNPZ8HJjr9Jrtg4fPSniYnwBJvy1-6UCYkTwo4,8525
5
- llama_stack_haystack-1.2.0.dist-info/METADATA,sha256=zrpsOWp7hchqSWhQkHTjhcnJB3rWLDkJJEFOkqGhlhM,1938
6
- llama_stack_haystack-1.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- llama_stack_haystack-1.2.0.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
8
- llama_stack_haystack-1.2.0.dist-info/RECORD,,
4
+ haystack_integrations/components/generators/llama_stack/chat/chat_generator.py,sha256=bPgto2LuI1eNZrItO-QGaZH1cU0SpQYyowPcNNhq710,9887
5
+ llama_stack_haystack-2.0.0.dist-info/METADATA,sha256=1ISssjiN7YXdB19dvXOnFRXI6vPAaWkU70Q6kyztN9c,1945
6
+ llama_stack_haystack-2.0.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
7
+ llama_stack_haystack-2.0.0.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
8
+ llama_stack_haystack-2.0.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any