From e0da839f3cd7c429b95ddd021104dca976a3a21e Mon Sep 17 00:00:00 2001 From: rcholic Date: Tue, 30 Dec 2025 19:01:37 -0800 Subject: [PATCH 1/3] more llm providers: GLM & Gemini --- sentience/llm_provider.py | 206 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) diff --git a/sentience/llm_provider.py b/sentience/llm_provider.py index a333e26..6758c1c 100644 --- a/sentience/llm_provider.py +++ b/sentience/llm_provider.py @@ -263,6 +263,212 @@ def model_name(self) -> str: return self._model_name +class GLMProvider(LLMProvider): + """ + Zhipu AI GLM provider implementation (GLM-4, GLM-4-Plus, etc.) + + Requirements: + pip install zhipuai + + Example: + >>> from sentience.llm_provider import GLMProvider + >>> llm = GLMProvider(api_key="your-api-key", model="glm-4-plus") + >>> response = llm.generate("You are a helpful assistant", "Hello!") + >>> print(response.content) + """ + + def __init__(self, api_key: str | None = None, model: str = "glm-4-plus"): + """ + Initialize GLM provider + + Args: + api_key: Zhipu AI API key (or set GLM_API_KEY env var) + model: Model name (glm-4-plus, glm-4, glm-4-air, glm-4-flash, etc.) + """ + try: + from zhipuai import ZhipuAI + except ImportError: + raise ImportError("ZhipuAI package not installed. Install with: pip install zhipuai") + + self.client = ZhipuAI(api_key=api_key) + self._model_name = model + + def generate( + self, + system_prompt: str, + user_prompt: str, + temperature: float = 0.0, + max_tokens: int | None = None, + **kwargs, + ) -> LLMResponse: + """ + Generate response using GLM API + + Args: + system_prompt: System instruction + user_prompt: User query + temperature: Sampling temperature (0.0 = deterministic, 1.0 = creative) + max_tokens: Maximum tokens to generate + **kwargs: Additional GLM API parameters + + Returns: + LLMResponse object + """ + messages = [] + if system_prompt: + messages.append({"role": "system", "content": system_prompt}) + messages.append({"role": "user", "content": user_prompt}) + + # Build API parameters + api_params = { + "model": self._model_name, + "messages": messages, + "temperature": temperature, + } + + if max_tokens: + api_params["max_tokens"] = max_tokens + + # Merge additional parameters + api_params.update(kwargs) + + # Call GLM API + response = self.client.chat.completions.create(**api_params) + + choice = response.choices[0] + usage = response.usage + + return LLMResponse( + content=choice.message.content, + prompt_tokens=usage.prompt_tokens if usage else None, + completion_tokens=usage.completion_tokens if usage else None, + total_tokens=usage.total_tokens if usage else None, + model_name=response.model, + finish_reason=choice.finish_reason, + ) + + def supports_json_mode(self) -> bool: + """GLM-4 models support JSON mode""" + return "glm-4" in self._model_name.lower() + + @property + def model_name(self) -> str: + return self._model_name + + +class GeminiProvider(LLMProvider): + """ + Google Gemini provider implementation (Gemini 2.0, Gemini 1.5 Pro, etc.) + + Requirements: + pip install google-generativeai + + Example: + >>> from sentience.llm_provider import GeminiProvider + >>> llm = GeminiProvider(api_key="your-api-key", model="gemini-2.0-flash-exp") + >>> response = llm.generate("You are a helpful assistant", "Hello!") + >>> print(response.content) + """ + + def __init__(self, api_key: str | None = None, model: str = "gemini-2.0-flash-exp"): + """ + Initialize Gemini provider + + Args: + api_key: Google API key (or set GEMINI_API_KEY or GOOGLE_API_KEY env var) + model: Model name (gemini-2.0-flash-exp, gemini-1.5-pro, gemini-1.5-flash, etc.) + """ + try: + import google.generativeai as genai + except ImportError: + raise ImportError( + "Google Generative AI package not installed. Install with: pip install google-generativeai" + ) + + # Configure API key + if api_key: + genai.configure(api_key=api_key) + else: + import os + + api_key = os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY") + if api_key: + genai.configure(api_key=api_key) + + self.genai = genai + self._model_name = model + self.model = genai.GenerativeModel(model) + + def generate( + self, + system_prompt: str, + user_prompt: str, + temperature: float = 0.0, + max_tokens: int | None = None, + **kwargs, + ) -> LLMResponse: + """ + Generate response using Gemini API + + Args: + system_prompt: System instruction + user_prompt: User query + temperature: Sampling temperature (0.0 = deterministic, 2.0 = very creative) + max_tokens: Maximum tokens to generate + **kwargs: Additional Gemini API parameters + + Returns: + LLMResponse object + """ + # Combine system and user prompts (Gemini doesn't have separate system role in all versions) + full_prompt = f"{system_prompt}\n\n{user_prompt}" if system_prompt else user_prompt + + # Build generation config + generation_config = { + "temperature": temperature, + } + + if max_tokens: + generation_config["max_output_tokens"] = max_tokens + + # Merge additional parameters + generation_config.update(kwargs) + + # Call Gemini API + response = self.model.generate_content(full_prompt, generation_config=generation_config) + + # Extract content + content = response.text if response.text else "" + + # Token usage (if available) + prompt_tokens = None + completion_tokens = None + total_tokens = None + + if hasattr(response, "usage_metadata") and response.usage_metadata: + prompt_tokens = response.usage_metadata.prompt_token_count + completion_tokens = response.usage_metadata.candidates_token_count + total_tokens = response.usage_metadata.total_token_count + + return LLMResponse( + content=content, + prompt_tokens=prompt_tokens, + completion_tokens=completion_tokens, + total_tokens=total_tokens, + model_name=self._model_name, + finish_reason=None, # Gemini uses different finish reason format + ) + + def supports_json_mode(self) -> bool: + """Gemini 1.5+ models support JSON mode via response_mime_type""" + model_lower = self._model_name.lower() + return any(x in model_lower for x in ["gemini-1.5", "gemini-2.0"]) + + @property + def model_name(self) -> str: + return self._model_name + + class LocalLLMProvider(LLMProvider): """ Local LLM provider using HuggingFace Transformers From f4dbe63749a79e2578058dc2cd18282adae994cf Mon Sep 17 00:00:00 2001 From: rcholic Date: Tue, 30 Dec 2025 21:31:20 -0800 Subject: [PATCH 2/3] new license --- LICENSE | 24 ++++++ LICENSE-APACHE | 201 +++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE-MIT | 21 ++++++ LICENSE.md | 43 ----------- README.md | 17 ++--- pyproject.toml | 3 +- 6 files changed, 255 insertions(+), 54 deletions(-) create mode 100644 LICENSE create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT delete mode 100644 LICENSE.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0c3da38 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +# License + +This project is dual-licensed under your choice of either: + +* **MIT License** ([LICENSE-MIT](./LICENSE-MIT)) +* **Apache License 2.0** ([LICENSE-APACHE](./LICENSE-APACHE)) + +## Choosing a License + +You may use this software under the terms of either license, at your option. + +### MIT License +The MIT License is a permissive license that is short and to the point. It lets people do almost anything they want with your project, like making and distributing closed source versions. + +### Apache License 2.0 +The Apache License 2.0 is also a permissive license, similar to MIT, but it also provides an express grant of patent rights from contributors to users. + +## Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you shall be dual-licensed as above, without any additional terms or conditions. + +--- + +Copyright (c) 2025 Sentience Contributors diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..a159214 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "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. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "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. + + "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). + + "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. + + "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." + + "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. + + 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. + + 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. + + 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: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (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 + + (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. + + 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. + + 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. + + 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. + + 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. + + 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. + + 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. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + 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. + + Copyright 2025 Sentience Contributors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..763e027 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 SentienceAPI Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index e9c3b11..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,43 +0,0 @@ -# Elastic License -## Acceptance -By using the software, you agree to all of the terms and conditions below. - -## Copyright License -The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below. - -## Limitations -You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software. - -You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key. - -You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law. - -## Patents -The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company. - -## Notices -You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms. - -If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software. - -## No Other Rights -These terms do not imply any licenses other than those expressly granted in these terms. - -## Termination -If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently. - -## No Liability -As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim. - -## Definitions -The **licensor** is the entity offering these terms, and the **software** is the software the licensor makes available under these terms, including any portion of it. - -you refers to the individual or entity agreeing to these terms. - -**your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. control means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect. - -**your licenses** are all the licenses granted to you for the software under these terms. - -**use** means anything you do with the software requiring one of your licenses. - -**trademark** means trademarks, service marks, and similar rights. diff --git a/README.md b/README.md index 75d052e..49dcc6e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Sentience Python SDK -The SDK is open under ELv2; the core semantic geometry and reliability logic runs in Sentience-hosted services. + ## 📦 Installation @@ -832,18 +832,15 @@ pytest -v tests/ ## 📜 License -This SDK is licensed under the **Elastic License 2.0 (ELv2)**. +This project is licensed under either of: + +* Apache License, Version 2.0, ([LICENSE-APACHE](./LICENSE-APACHE)) +* MIT license ([LICENSE-MIT](./LICENSE-MIT)) -The Elastic License 2.0 allows you to use, modify, and distribute this SDK for internal, research, and non-competitive purposes. It **does not permit offering this SDK or a derivative as a hosted or managed service**, nor using it to build a competing product or service. +at your option. ### Important Notes - This SDK is a **client-side library** that communicates with proprietary Sentience services and browser components. -- The Sentience backend services (including semantic geometry grounding, ranking, visual cues, and trace processing) are **not open source** and are governed by Sentience's Terms of Service. - -- Use of this SDK does **not** grant rights to operate, replicate, or reimplement Sentience's hosted services. - -For commercial usage, hosted offerings, or enterprise deployments, please contact Sentience to obtain a commercial license. - -See the full license text in [`LICENSE`](./LICENSE.md). +- The Sentience backend services (including semantic geometry grounding, ranking, visual cues, reranking and trace processing) are **not open source** and are governed by Sentience's Terms of Service. diff --git a/pyproject.toml b/pyproject.toml index 59e462b..5a1bd80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ version = "0.90.14" description = "Python SDK for Sentience AI Agent Browser Automation" readme = "README.md" requires-python = ">=3.11" -license = {text = "MIT"} +license = {text = "MIT OR Apache-2.0"} authors = [ {name = "Sentience Team"} ] @@ -17,6 +17,7 @@ classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", + "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.11", ] From 6a6ad397bfc7152ce3a9e03c7baf1d22a4e904d9 Mon Sep 17 00:00:00 2001 From: rcholic Date: Tue, 30 Dec 2025 21:46:54 -0800 Subject: [PATCH 3/3] updated readme --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 49dcc6e..3692606 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Sentience Python SDK - +**Semantic geometry grounding for deterministic, debuggable AI web agents with time-travel traces.** ## 📦 Installation @@ -838,9 +838,3 @@ This project is licensed under either of: * MIT license ([LICENSE-MIT](./LICENSE-MIT)) at your option. - -### Important Notes - -- This SDK is a **client-side library** that communicates with proprietary Sentience services and browser components. - -- The Sentience backend services (including semantic geometry grounding, ranking, visual cues, reranking and trace processing) are **not open source** and are governed by Sentience's Terms of Service.