weave-haystack 0.0.1__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.
@@ -0,0 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from .weave_connector import WeaveConnector
6
+
7
+ __all__ = ["WeaveConnector"]
@@ -0,0 +1,127 @@
1
+ from typing import Any, Optional
2
+
3
+ from haystack import component, default_from_dict, default_to_dict, logging, tracing
4
+ from weave.trace.autopatch import AutopatchSettings
5
+
6
+ from haystack_integrations.tracing.weave import WeaveTracer
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+
11
+ @component
12
+ class WeaveConnector:
13
+ """
14
+ Collects traces from your pipeline and sends them to Weights & Biases.
15
+
16
+ Add this component to your pipeline to integrate with the Weights & Biases Weave framework for tracing and
17
+ monitoring your pipeline components.
18
+
19
+ Note that you need to have the `WANDB_API_KEY` environment variable set to your Weights & Biases API key.
20
+
21
+ NOTE: If you don't have a Weights & Biases account it will interactively ask you to set one and your input
22
+ will then be stored in ~/.netrc
23
+
24
+ In addition, you need to set the `HAYSTACK_CONTENT_TRACING_ENABLED` environment variable to `true` in order to
25
+ enable Haystack tracing in your pipeline.
26
+
27
+ To use this connector simply add it to your pipeline without any connections, and it will automatically start
28
+ sending traces to Weights & Biases.
29
+
30
+ Example:
31
+ ```python
32
+ import os
33
+
34
+ from haystack import Pipeline
35
+ from haystack.components.builders import ChatPromptBuilder
36
+ from haystack.components.generators.chat import OpenAIChatGenerator
37
+ from haystack.dataclasses import ChatMessage
38
+
39
+ from haystack_integrations.components.connectors import WeaveConnector
40
+
41
+ os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
42
+
43
+ pipe = Pipeline()
44
+ pipe.add_component("prompt_builder", ChatPromptBuilder())
45
+ pipe.add_component("llm", OpenAIChatGenerator(model="gpt-3.5-turbo"))
46
+ pipe.connect("prompt_builder.prompt", "llm.messages")
47
+
48
+ connector = WeaveConnector(pipeline_name="test_pipeline")
49
+ pipe.add_component("weave", connector)
50
+
51
+ messages = [
52
+ ChatMessage.from_system(
53
+ "Always respond in German even if some input data is in other languages."
54
+ ),
55
+ ChatMessage.from_user("Tell me about {{location}}"),
56
+ ]
57
+
58
+ response = pipe.run(
59
+ data={
60
+ "prompt_builder": {
61
+ "template_variables": {"location": "Berlin"},
62
+ "template": messages,
63
+ }
64
+ }
65
+ )
66
+ print(response["llm"]["replies"][0])
67
+ ```
68
+
69
+ You should then head to `https://wandb.ai/<user_name>/projects` and see the complete trace for your pipeline under
70
+ the pipeline name you specified, when creating the `WeaveConnector`
71
+
72
+ """
73
+
74
+ def __init__(self, pipeline_name: str, weave_init_kwargs: Optional[dict[str, Any]] = None) -> None:
75
+ """
76
+ Initialize WeaveConnector.
77
+
78
+ :param pipeline_name: The name of the pipeline you want to trace.
79
+ :param weave_init_kwargs: Additional arguments to pass to the WeaveTracer client.
80
+ """
81
+ self.pipeline_name = pipeline_name
82
+ self.weave_init_kwargs = weave_init_kwargs or {}
83
+ self.tracer: Optional[WeaveTracer] = None
84
+
85
+ def warm_up(self) -> None:
86
+ """Initialize the WeaveTracer."""
87
+ if self.tracer is None:
88
+ self.tracer = WeaveTracer(project_name=self.pipeline_name, **self.weave_init_kwargs)
89
+ tracing.enable_tracing(self.tracer)
90
+
91
+ @component.output_types(pipeline_name=str)
92
+ def run(self) -> dict[str, str]:
93
+ # NOTE: this is a no-op component - it simply triggers the Tracer to sends traces to Weights & Biases
94
+ return {"pipeline_name": self.pipeline_name}
95
+
96
+ def to_dict(self) -> dict[str, Any]:
97
+ """
98
+ Serializes the component to a dictionary.
99
+
100
+ :returns:
101
+ Dictionary with all the necessary information to recreate this component.
102
+ """
103
+ weave_init_kwargs = self.weave_init_kwargs.copy()
104
+ autopatch_settings = weave_init_kwargs.get("autopatch_settings", None)
105
+ if isinstance(autopatch_settings, AutopatchSettings):
106
+ weave_init_kwargs["autopatch_settings"] = autopatch_settings.model_dump(exclude_defaults=True)
107
+
108
+ return default_to_dict(self, pipeline_name=self.pipeline_name, weave_init_kwargs=weave_init_kwargs)
109
+
110
+ @classmethod
111
+ def from_dict(cls, data: dict[str, Any]) -> "WeaveConnector":
112
+ """
113
+ Deserializes the component from a dictionary.
114
+
115
+ :param data: Dictionary to deserialize from.
116
+ :returns:
117
+ Deserialized component.
118
+ """
119
+ if (
120
+ autopatch_settings := data.get("init_parameters", {})
121
+ .get("weave_init_kwargs", {})
122
+ .get("autopatch_settings", None)
123
+ ):
124
+ parsed_settings = AutopatchSettings.model_validate(autopatch_settings)
125
+ data["init_parameters"]["weave_init_kwargs"]["autopatch_settings"] = parsed_settings
126
+
127
+ return default_from_dict(cls, data)
@@ -0,0 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from .tracer import WeaveSpan, WeaveTracer
6
+
7
+ __all__ = ["WeaveSpan", "WeaveTracer"]
@@ -0,0 +1,223 @@
1
+ import contextlib
2
+ import os
3
+ from collections.abc import Iterator
4
+ from typing import Any, Optional, Union
5
+
6
+ from haystack import logging
7
+ from haystack.tracing import Span, Tracer
8
+ from haystack.tracing import tracer as haystack_tracer
9
+ from haystack.tracing.utils import coerce_tag_value
10
+
11
+ import weave
12
+ from weave.trace.weave_client import Call, WeaveClient
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+
17
+ class WeaveSpan(Span):
18
+ """
19
+ A bridge between Haystack's Span interface and Weave's Call object.
20
+
21
+ Stores metadata about a component execution and its inputs and outputs, and manages the attributes/tags
22
+ that describe the operation.
23
+ """
24
+
25
+ def __init__(
26
+ self, call: Optional[Call] = None, parent: Optional[Call] = None, operation: Optional[str] = None
27
+ ) -> None:
28
+ self._call = call
29
+ self._parent = parent
30
+ self._operation = operation
31
+ self._attributes: dict[str, Any] = {}
32
+
33
+ def set_tag(self, key: str, value: Any) -> None:
34
+ """
35
+ Set a tag by adding it to the call's inputs.
36
+
37
+ :param key: The tag key.
38
+ :param value: The tag value.
39
+ """
40
+ self._attributes[key] = value
41
+
42
+ def set_tags(self, tags: dict[str, Any]) -> None:
43
+ for k, v in tags.items():
44
+ self.set_tag(k, v)
45
+
46
+ def raw_span(self) -> Any:
47
+ """Access to the underlying Weave Call object."""
48
+ return self._call
49
+
50
+ def get_correlation_data_for_logs(self) -> dict[str, Any]:
51
+ """Correlation data for logging."""
52
+ if not self._call:
53
+ return {}
54
+ return {"weave.call_id": self._call.id, "weave.run_id": getattr(self._call, "run_id", "")}
55
+
56
+ def set_call(self, call: "weave.Call") -> None:
57
+ self._call = call
58
+
59
+ def get_attributes(self) -> dict[str, Any]:
60
+ return self._attributes
61
+
62
+
63
+ class WeaveTracer(Tracer):
64
+ """
65
+ Implements a Haystack's Tracer to make an interface with Weights and Bias Weave.
66
+
67
+ It's responsible for creating and managing Weave calls, and for converting Haystack spans
68
+ to Weave spans. It creates spans for each Haystack component run.
69
+ """
70
+
71
+ def __init__(self, project_name: str, **weave_init_kwargs: Any) -> None:
72
+ """
73
+ Initialize the WeaveTracer.
74
+
75
+ :param project_name: The name of the project to trace, this is will be the name appearing in Weave project.
76
+ :param weave_init_kwargs: Additional arguments to pass to the Weave client.
77
+ """
78
+
79
+ content_tracing_enabled = os.getenv("HAYSTACK_CONTENT_TRACING_ENABLED", "false").lower()
80
+ haystack_tracer.is_content_tracing_enabled = content_tracing_enabled == "true"
81
+ if not haystack_tracer.is_content_tracing_enabled:
82
+ logger.warning(
83
+ "Inputs and Outputs of components traces will not be logged because Haystack tracing is disabled."
84
+ "To enable, set the HAYSTACK_CONTENT_TRACING_ENABLED environment variable to true "
85
+ "before importing Haystack."
86
+ )
87
+
88
+ self._client = weave.init(project_name, **weave_init_kwargs)
89
+ self._current_span: Optional[WeaveSpan] = None
90
+
91
+ @staticmethod
92
+ def create_call(
93
+ attributes: dict, client: WeaveClient, parent_span: Union[WeaveSpan, None], operation_name: str
94
+ ) -> Call:
95
+ comp_name = attributes.pop("haystack.component.name", "")
96
+ comp_type = attributes.pop("haystack.component.type", "")
97
+ comp_input = attributes.pop("haystack.component.input", {})
98
+ call = client.create_call(
99
+ op=operation_name,
100
+ inputs={key: coerce_tag_value(value) for key, value in comp_input.items()},
101
+ attributes={key: coerce_tag_value(value) for key, value in attributes.items()},
102
+ display_name=f"{comp_name}[{comp_type}].run",
103
+ parent=parent_span.raw_span() if parent_span else None,
104
+ )
105
+ return call
106
+
107
+ def current_span(self) -> Optional[Span]:
108
+ """Get the current active span."""
109
+ return self._current_span
110
+
111
+ @staticmethod
112
+ def _create_component_span(parent_span: Optional[WeaveSpan], operation_name: str) -> WeaveSpan:
113
+ """Create a span for component runs with deferred call creation."""
114
+ return WeaveSpan(parent=parent_span.raw_span() if parent_span else None, operation=operation_name)
115
+
116
+ def _create_regular_span(
117
+ self, operation_name: str, tags: Optional[dict], parent_span: Optional[WeaveSpan]
118
+ ) -> WeaveSpan:
119
+ """Create a span for regular operations with immediate call creation."""
120
+ call = self._client.create_call(
121
+ op=operation_name,
122
+ inputs=tags,
123
+ parent=parent_span.raw_span() if parent_span else None,
124
+ )
125
+ return WeaveSpan(call=call)
126
+
127
+ def _finish_component_call(self, span: WeaveSpan, parent_span: Optional[WeaveSpan], operation_name: str) -> None:
128
+ """Create and finish call for component runs."""
129
+ attributes = span.get_attributes()
130
+ call = self.create_call(
131
+ attributes=attributes,
132
+ client=self._client,
133
+ parent_span=parent_span,
134
+ operation_name=operation_name,
135
+ )
136
+ span.set_call(call)
137
+ comp_output = attributes.pop("haystack.component.output", {})
138
+ self._client.finish_call(
139
+ call,
140
+ output={key: coerce_tag_value(value) for key, value in comp_output.items()},
141
+ )
142
+
143
+ def _finish_regular_call(self, span: WeaveSpan) -> None:
144
+ """Finish call for regular operations."""
145
+ attributes = span.get_attributes()
146
+ pipeline_output = attributes.pop("haystack.pipeline.output_data", {})
147
+ self._client.finish_call(
148
+ span.raw_span(),
149
+ output={key: coerce_tag_value(value) for key, value in pipeline_output.items()},
150
+ )
151
+
152
+ @contextlib.contextmanager
153
+ def trace(
154
+ self, operation_name: str, tags: Optional[dict[str, Any]] = None, parent_span: Optional[WeaveSpan] = None
155
+ ) -> Iterator[WeaveSpan]:
156
+ """
157
+ A context manager that creates and manages spans for tracking operations in Weights & Biases Weave.
158
+
159
+ It has two main workflows:
160
+
161
+ A) For regular operations (operation_name != "haystack.component.run"):
162
+ Creates a Weave Call immediately
163
+ Creates a WeaveSpan with this call
164
+ Sets any provided tags
165
+ Yields the span for use in the with block
166
+ When the block ends, updates the call with pipeline output data
167
+
168
+ B) For component runs (operation_name == "haystack.component.run"):
169
+ Creates a WeaveSpan WITHOUT a call initially (deferred creation)
170
+ Sets any provided tags
171
+ Yields the span for use in the with block
172
+ Creates the actual Weave Call only at the end, when all component information is available
173
+ Updates the call with component output data
174
+
175
+ This distinction is important because Weave's calls can't be updated once created, but the content
176
+ tags are only set on the Span at a later stage. To get the inputs on call creation, we need to create
177
+ the call after we yield the span.
178
+
179
+ """
180
+ # create an appropriate span based on operation type
181
+ is_component_run = operation_name == "haystack.component.run"
182
+ span = (
183
+ self._create_component_span(parent_span, operation_name)
184
+ if is_component_run
185
+ else self._create_regular_span(operation_name, tags, parent_span)
186
+ )
187
+
188
+ self._current_span = span
189
+ if tags:
190
+ span.set_tags(tags)
191
+
192
+ # this method acts as a context manager so yielding the span yields the context to the caller
193
+ # try-except-else-finally to ensure that a call is created and finished correctly for both types of operations
194
+ try:
195
+ yield span
196
+
197
+ except Exception as e:
198
+ # case when an exception is raised, an error occurred note that for a component run ensure call is
199
+ # created even on error
200
+ if is_component_run:
201
+ attributes = span.get_attributes()
202
+ call = self.create_call(
203
+ attributes=attributes,
204
+ client=self._client,
205
+ parent_span=parent_span,
206
+ operation_name=operation_name,
207
+ )
208
+ span.set_call(call)
209
+ self._client.finish_call(call, exception=e)
210
+ else:
211
+ self._client.finish_call(span.raw_span(), exception=e)
212
+ raise # re-raise the same exception
213
+
214
+ else:
215
+ # case when no exception is raised, operation was successful
216
+ if is_component_run:
217
+ self._finish_component_call(span, parent_span, operation_name)
218
+ else:
219
+ self._finish_regular_call(span)
220
+
221
+ finally:
222
+ # reset the current span
223
+ self._current_span = None
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: weave-haystack
3
+ Version: 0.0.1
4
+ Summary: An integration of Weights & Biases Weave tracer with Haystack
5
+ Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations
6
+ Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/weights_and_biases_weave/README.md
7
+ Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
8
+ Author-email: deepset GmbH <info@deepset.ai>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE.txt
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: Implementation :: CPython
20
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
21
+ Requires-Python: >=3.9
22
+ Requires-Dist: haystack-ai
23
+ Requires-Dist: weave>=0.51.33
24
+ Description-Content-Type: text/markdown
25
+
26
+ # weave-haystack
27
+
28
+ [![PyPI - Version](https://img.shields.io/pypi/v/weave-haystack.svg)](https://pypi.org/project/weave-haystack)
29
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/weave-haystack)](https://pypi.org/project/weave-haystack)
30
+
31
+ - [Installation](#installation)
32
+ - [Example](#example)
33
+ - [License](#license)
34
+
35
+
36
+ ## Installation
37
+
38
+ ```console
39
+ pip install weave-haystack
40
+ ```
41
+
42
+ ## Weave by Weights & Biases
43
+
44
+ ### Example
45
+
46
+ You need to have a Weave account to use this feature. You can sign up for free at https://wandb.ai/site.
47
+
48
+ You then need to set the `WANDB_API_KEY:` environment variable with your Weights & Biases API key. You should find
49
+ your API key in https://wandb.ai/home when you are logged in.
50
+
51
+ You should then head to `https://wandb.ai/<user_name>/projects` and see the complete trace for your pipeline under
52
+ the pipeline name you specified, when creating the `WeaveConnector`.
53
+
54
+ You also need to have the `HAYSTACK_CONTENT_TRACING_ENABLED` environment variable set to `true`.
55
+
56
+ To use this connector simply add it to your pipeline without any connections, and it will automatically start
57
+ sending traces to Weights & Biases.
58
+
59
+ ```python
60
+ import os
61
+
62
+ from haystack import Pipeline
63
+ from haystack.components.builders import ChatPromptBuilder
64
+ from haystack.components.generators.chat import OpenAIChatGenerator
65
+ from haystack.dataclasses import ChatMessage
66
+
67
+ from haystack_integrations.components.connectors import WeaveConnector
68
+
69
+ os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
70
+
71
+ pipe = Pipeline()
72
+ pipe.add_component("prompt_builder", ChatPromptBuilder())
73
+ pipe.add_component("llm", OpenAIChatGenerator(model="gpt-3.5-turbo"))
74
+ pipe.connect("prompt_builder.prompt", "llm.messages")
75
+
76
+ connector = WeaveConnector(pipeline_name="test_pipeline")
77
+ pipe.add_component("weave", connector)
78
+
79
+ messages = [
80
+ ChatMessage.from_system(
81
+ "Always respond in German even if some input data is in other languages."
82
+ ),
83
+ ChatMessage.from_user("Tell me about {{location}}"),
84
+ ]
85
+
86
+ response = pipe.run(
87
+ data={
88
+ "prompt_builder": {
89
+ "template_variables": {"location": "Berlin"},
90
+ "template": messages,
91
+ }
92
+ }
93
+ )
94
+ print(response["llm"]["replies"][0])
95
+ ```
96
+
97
+ ## License
98
+
99
+ `weave-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.
@@ -0,0 +1,8 @@
1
+ haystack_integrations/components/connectors/__init__.py,sha256=eEQe5ucdC5Mtr0tubqToafxlmMQkAKtaUaCshmxn5ag,185
2
+ haystack_integrations/components/connectors/weave_connector.py,sha256=Ft7MhKspboHUtoTrAMutshJNptk13J1_g2Mnm4W82I8,4792
3
+ haystack_integrations/tracing/weave/__init__.py,sha256=RUtwv7ZN8QeSTAidwjoQjxVfSdubYUGvjFw_ErkHEJg,194
4
+ haystack_integrations/tracing/weave/tracer.py,sha256=sxF_zQQvv8Q3am3J_7-j-TvnLE3lo3Q8uc6LSP4LjxU,8933
5
+ weave_haystack-0.0.1.dist-info/METADATA,sha256=RewiR4umn-H5ZNMVwXeBrai4_eaSOEMKpy6O3i1g3Yg,3540
6
+ weave_haystack-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ weave_haystack-0.0.1.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
8
+ weave_haystack-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,73 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+
37
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
38
+
39
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+
41
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
42
+
43
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
56
+
57
+ APPENDIX: How to apply the Apache License to your work.
58
+
59
+ To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
60
+
61
+ Copyright [yyyy] [name of copyright owner]
62
+
63
+ Licensed under the Apache License, Version 2.0 (the "License");
64
+ you may not use this file except in compliance with the License.
65
+ You may obtain a copy of the License at
66
+
67
+ http://www.apache.org/licenses/LICENSE-2.0
68
+
69
+ Unless required by applicable law or agreed to in writing, software
70
+ distributed under the License is distributed on an "AS IS" BASIS,
71
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72
+ See the License for the specific language governing permissions and
73
+ limitations under the License.