├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENCE ├── README.md ├── ThebAI.ipynb ├── ThebAI.py ├── Theb_AI_Login.py └── requirements.txt /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct for Claude-3-Opus-Free-Reverse-Engineered-API 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | - Using welcoming and inclusive language 12 | - Being respectful of differing viewpoints and experiences 13 | - Gracefully accepting constructive criticism 14 | - Focusing on what is best for the community 15 | - Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | - The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | - Trolling, insulting/derogatory comments, and personal or political attacks 21 | - Public or private harassment 22 | - Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | - Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [your email]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. 38 | 39 | ## Attribution 40 | 41 | This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html. 42 | 43 | Date: May 4, 2024 44 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 |
2 | Contribution Guide Badge 3 |

🌟 Contributing to Claude-3-Opus-Free-Reverse-Engineered-API🌟

4 |
5 | 6 |
7 | 8 | YouTube 9 | Telegram 10 | Instagram 11 | LinkedIn 12 | Buy Me A Coffee 13 |
14 | 15 | We're thrilled to have you on board and excited to see your contributions to the `Claude-3-Opus-Free-Reverse-Engineered-API` project. Your expertise will help shape the future of this innovative tool! 16 | 17 | ## 📜 Code of Conduct 18 | 19 | To maintain a harmonious community, we ask that you review and adhere to our [Code of Conduct](CODE_OF_CONDUCT.md). 20 | 21 | ## 🚀 Getting Started with Contributions 22 | 23 | 1. **Fork the Repository**: 24 | ```bash 25 | git fork https://github.com/SreejanPersonal/Claude-3-Opus-Free-Reverse-Engineered-API.git 26 | ``` 27 | 2. **Clone Your Fork**: 28 | ```bash 29 | git clone https://github.com/SreejanPersonal/Claude-3-Opus-Free-Reverse-Engineered-API.git 30 | ``` 31 | 3. **Branch Out**: 32 | ```bash 33 | git checkout -b feature/your-awesome-feature 34 | ``` 35 | 4. **Commit Your Changes**: 36 | ```bash 37 | git add . 38 | git commit -m "Add a brief description of your awesome feature" 39 | ``` 40 | 41 | ## 📏 Contribution Guidelines 42 | 43 | ### Code Style 44 | 45 | - Embrace the established coding conventions. 46 | - Opt for descriptive variable names and document your logic with comments. 47 | 48 | ### Testing 49 | 50 | - Craft unit tests for new features using our preferred testing framework. 51 | - Verify that all tests are green before proposing your changes. 52 | 53 | ### Documentation 54 | 55 | - Update existing documentation to mirror your modifications. 56 | - Aim for clarity and brevity in your documentation. 57 | 58 | ### Pull Requests 59 | 60 | - Initiate a pull request targeting the `main` branch. 61 | - Summarize your contributions and their impact. 62 | - Engage constructively with feedback from our maintainers. 63 | 64 | ## 🔍 Review Process 65 | 66 | Our dedicated team of maintainers will evaluate your pull request, offering insights and suggestions. Collaborate with us to refine your contribution until it shines! 67 | 68 | ## 🛠️ Additional Resources 69 | 70 | - Explore our [Youtube Video](#) for in-depth documentation. 71 | - Join the conversation on our [Telegram](#). 72 | 73 | Your participation is what drives the `Claude-3-Opus-Free-Reverse-Engineered-API` forward. We eagerly anticipate your innovative ideas and thank you for contributing to a brighter open-source future! 74 | 75 | 76 |
77 | 78 | YouTube 79 | Telegram 80 | Instagram 81 | LinkedIn 82 | Buy Me A Coffee 83 |
-------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Devs Do Code (Sree) License 2 | ========================== 3 | 4 | Version 1.0, March 2023 5 | 6 | **TERMS AND CONDITIONS** 7 | 8 | 1. **Definitions** 9 | * "Software" refers to the SreejanPersonal/Claude-3-Opus-Free-Reverse-Engineered-API software, including all source code, object code, and documentation. 10 | * "Licensor" refers to Devs Do Code (Sree), the copyright holder of the Software. 11 | * "Licensee" refers to any individual or organization using the Software. 12 | 2. **Grant of License** 13 | The Licensor hereby grants to the Licensee a non-exclusive, worldwide, royalty-free license to use, reproduce, modify, display, and distribute the Software. 14 | 3. **Conditions** 15 | The Licensee must: 16 | * Retain all copyright and proprietary notices in the Software. 17 | * Not use the Software for any illegal or malicious purposes. 18 | * Not sell or distribute the Software as a standalone product. 19 | 4. **Warranty Disclaimer** 20 | 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 non-infringement. 21 | 5. **Limitation of Liability** 22 | In no event shall the Licensor be liable for any damages, including but not limited to incidental, consequential, or punitive damages, arising out of the use or inability to use the Software. 23 | 6. **Termination** 24 | This License will terminate automatically if the Licensee fails to comply with any of its terms and conditions. 25 | 7. **Governing Law** 26 | This License shall be governed by and construed in accordance with the laws of [Country/State]. 27 | 28 | **BY USING THE SOFTWARE, YOU ACKNOWLEDGE THAT YOU HAVE READ, UNDERSTAND, AND AGREE TO BE BOUND BY THE TERMS AND CONDITIONS OF THIS LICENSE.** 29 | 30 | Copyright (c) 2023 Devs Do Code (Sree). All rights reserved. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

Claude 3 Opus API 🤖 - Unofficial Reverse Engineering 🚀

3 |

4 | 5 | GitHub stars 6 | 7 | 8 | GitHub forks 9 | 10 | 11 | GitHub issues 12 | 13 |

14 |
15 | 16 |
17 | 18 | YouTube 19 | Telegram 20 | Instagram 21 | LinkedIn 22 | Buy Me A Coffee 23 |
24 | 25 | ## Crafted with ❤️ by Devs Do Code (Sree) 26 | 27 | > **Disclaimer:** This project is not officially associated with Claude 3 Opus. It is an independent reverse engineering effort to explore the Claude 3 Opus API. 28 | 29 | 🚀 **Repository Status Update:** 30 | 31 | 🛑 **Important Notice:** 32 | This repository is no longer maintained by the owner `Devs Do Code (Sree)`. Any contribution in this repository is heartly welcomed 💝💝 33 | 34 | 41 | 42 | ### 🪛 Intallation 43 | 44 | To get started with the Claude 3 Opus Free Reverse Engineered API, follow these steps to unlock the full potential of this innovative project: 45 | 46 | 1. **Clone the Repository**: Begin by cloning the repository using the following command: 47 | ```bash 48 | git clone https://github.com/SreejanPersonal/Claude-3-Opus-Free-Reverse-Engineered-API.git 49 | ``` 50 | This will download the entire project to your local machine, giving you access to the source code and necessary files. 51 | 52 | 2. **Install Required Modules**: Next, navigate to the project directory and install the required Python modules listed in `requirements.txt`. Run `pip install -r requirements.txt` 53 | 54 | 3. **Run API Key Generation Script**: Execute the `Theb_AI_Login.py` script to initiate the API key generation process. This script will automatically login to `https://beta.theb.ai/` using temporary emails and generate API keys for you. 55 | 56 | 4. **Configure Parallel API Key Generation**: To optimize the API key generation process, configure the `at_once` value according to your system specifications (Defaults to 5 i.e. On running once it will generate five api keys). This will allow you to generate API keys in parallel, significantly reducing the time required to obtain the desired number of keys. 57 | 58 | 5. **Understand API Key Limitations**: It's essential to note that each API key provides $0.05 credit, but this limit only applies to specific responses. For instance, if you ask a query with a 100K context window, there is no issue, and there is no bound on the output token generated by the AI model. However, you won't be able to send a second request since you have exhausted all your top-up amount in the first response. This is a known glitch in the website. 59 | 60 | 6. **Run AI Interaction Script**: Once you have generated the API keys, run either `ThebAI.ipynb` (recommended for faster execution) or `ThebAI.py` to interact with the AI model. These scripts will allow you to leverage the capabilities of Claude 3 Opus and explore its features. 61 | 62 | 7. **Explore Additional Models**: Don't limit yourself to Claude 3 Opus! You can also explore other models available in the project, each with its unique features and capabilities. 63 | 64 | 8. **Optional: Implement Concurrent Execution**: To take your project to the next level, consider implementing multitasking or threading to run API key generation and AI responses concurrently. This will significantly improve the overall performance and efficiency of your project. 65 | 66 | By following these steps, you'll be well on your way to harnessing the power of the Claude 3 Opus Free Reverse Engineered API and unlocking its full potential. 67 | 68 | ### 🚀 Quick Start 69 | 70 | 1. Run `Theb_AI_Login.py` 71 | 2. Run `ThebAI.ipynb` 72 | 73 | ### 🤝 Contributing 74 | 75 | Your contributions are welcome! Please refer to our [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines. 76 | 77 | ### 📜 License 78 | 79 | This project is licensed under the [MIT License](LICENSE). Full license text is available in the [LICENSE](LICENSE) file. 80 | 81 | ### 📬 Get in Touch 82 | 83 | For inquiries or assistance, please open an issue or reach out through our social channels: 84 | 85 |
86 | 87 | YouTube 88 | Telegram 89 | Instagram 90 | LinkedIn 91 | Buy Me A Coffee 92 |
93 | 94 | We appreciate your interest in `Claude-3-Opus-Free-Reverse-Engineered-API` 95 | -------------------------------------------------------------------------------- /ThebAI.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Claude-3-Opus-Free-Reverse-Engineered-API\n", 8 | "======================================\n", 9 | "Author: Devs Do Code (Sree)\n", 10 | "\n", 11 | "Description: Free and unlimited API interface to Claude 3 Opus and other AI models.\n", 12 | "\n", 13 | "Features: Free and unlimited, Reverse-engineered, 10+ AI models available, including Claude 3 Opus\n", 14 | "\n", 15 | "License: MIT License\n", 16 | "\n", 17 | "Contributing: Fork and submit a pull request to contribute." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "import json\n", 27 | "import random\n", 28 | "import re\n", 29 | "import requests\n", 30 | "import json\n", 31 | "\n", 32 | "def load_api_info():\n", 33 | " with open(\"Theb_API.json\", \"r\") as file:\n", 34 | " return json.load(file)\n", 35 | " \n", 36 | "def remove_apis():\n", 37 | " with open(\"Theb_API.json\", \"r\") as file:\n", 38 | " data = json.load(file)\n", 39 | " if data: data.pop(0)\n", 40 | " with open(\"Theb_API.json\", \"w\") as file:\n", 41 | " json.dump(data, file, indent=4)\n", 42 | "\n", 43 | "def initiate_api_conversation(input_text: str, model_identifier: str = 'Claude-3-Opus', organization_id: str = load_api_info()[0]['ORGANIZATION_ID'], access_token: str = load_api_info()[0]['API_KEY']) -> str:\n", 44 | " \"\"\"\n", 45 | " Initiates an API conversation request and retrieves the response content.\n", 46 | "\n", 47 | " Parameters:\n", 48 | " - organization_id (str): The unique identifier for the API organization.\n", 49 | " - model_identifier (str): The identifier for the desired conversation model.\n", 50 | " - input_text (str): The textual input for initiating the conversation.\n", 51 | "\n", 52 | " Returns:\n", 53 | " - str: The textual content of the API response.\n", 54 | "\n", 55 | " Note:\n", 56 | " - The model_identifier should correspond to one of the predefined model keys.\n", 57 | " \"\"\"\n", 58 | "\n", 59 | " # Mapping of model identifiers to their respective keys\n", 60 | " model_key_mapping = {\n", 61 | " 'Claude-3-Opus' : 'ade084104e614c31ada6892744fcd3c5',\n", 62 | " 'Claude-3-Haiku' : \"d2c2b37c042d4b248af62a033eccd1b2\",\n", 63 | " 'Claude-3-Sonnet' : \"8b851ff081d54ba7b46a42a5099fcc64\",\n", 64 | " 'Claude 2': 'a248a40fe3c4493598064c9ba725e8c9',\n", 65 | "\n", 66 | " 'llama-3-70b': '5da08fc7ac704d0d9bee545cbbb91793',\n", 67 | " 'llama-3-8b': 'c60d009ce85f47f087952f17eead4eab',\n", 68 | " 'cod-llama-70b': 'bccdb1b4dee94dc59d6e15e2a73ac2ba',\n", 69 | "\n", 70 | " 'mistral 8x22b': '70b3f32d71a34b97af9d660e1245fe15',\n", 71 | " 'WizardLM 2 8x22B' : 'ebf8820be60f40a38a3cae32795f8bd2',\n", 72 | "\n", 73 | " 'chatgpt-3-5-turbo': '58f5e7e50fee4779a1e5fe16c3aa302b',\n", 74 | " 'dbrx': '20ea474d42dd44eaa618971cdb16bfa7',\n", 75 | " 'Theb-ai': '7e682da4dde7ee214baa0efc0cf6d7a4',\n", 76 | " \n", 77 | " }\n", 78 | "\n", 79 | " # API endpoint construction\n", 80 | " api_endpoint = f\"https://beta.theb.ai/api/conversation?org_id={organization_id}&req_rand={random.random()}\"\n", 81 | "\n", 82 | " # HTTP request headers\n", 83 | " request_headers = {\n", 84 | " \"Authorization\": f\"Bearer {access_token}\",\n", 85 | " }\n", 86 | "\n", 87 | " # HTTP request payload\n", 88 | " request_payload = {\n", 89 | " \"text\": input_text,\n", 90 | " \"model\": model_key_mapping[model_identifier],\n", 91 | " \"functions\": None,\n", 92 | " \"attachments\": [],\n", 93 | " \"model_params\": {\n", 94 | " \"system_prompt\": \"Be Helpful and Friendly\",\n", 95 | " \"temperature\": \"1\",\n", 96 | " \"top_p\": \"1\",\n", 97 | " \"frequency_penalty\": \"0\",\n", 98 | " \"presence_penalty\": \"0\",\n", 99 | " \"long_term_memory\": \"ltm\"\n", 100 | " },\n", 101 | " }\n", 102 | "\n", 103 | " # Execution of the API request\n", 104 | " payload_as_json = json.dumps(request_payload)\n", 105 | " response = requests.post(api_endpoint, headers=request_headers, data=payload_as_json, stream=True)\n", 106 | " if response.status_code == 200:\n", 107 | " accumulated_response_text = \"\"\n", 108 | " for line in response.iter_lines(decode_unicode=True, chunk_size=1, delimiter=\"\\n\"):\n", 109 | " if line and \"event: \" not in line:\n", 110 | " line_content = re.sub(\"data:\", \"\", line)\n", 111 | " try:\n", 112 | " response_data = json.loads(line_content)\n", 113 | " if 'tid' in response_data: continue\n", 114 | " print(response_data['args']['content'].replace(accumulated_response_text, ''), end=\"\")\n", 115 | " accumulated_response_text = response_data['args']['content']\n", 116 | " except json.JSONDecodeError:\n", 117 | " continue\n", 118 | "\n", 119 | " \n", 120 | " if accumulated_response_text != \"\": return accumulated_response_text\n", 121 | " else : \n", 122 | " resp_lines = response.text.split(\"\\r\")\n", 123 | " for line in reversed(resp_lines):\n", 124 | " if \"event: \" not in line and line.strip():\n", 125 | " try:\n", 126 | " data_value = re.sub(\"data:\", \"\", line)\n", 127 | " json_data = json.loads(data_value)\n", 128 | " return json_data['args']['content']\n", 129 | " except Exception as e:\n", 130 | " continue\n", 131 | " \n", 132 | " elif response.status_code == 400:\n", 133 | " print(\"\\033[91m\" + f\"Switching to Next API \" + \"\\033[0m\")\n", 134 | " remove_apis()\n", 135 | " return initiate_api_conversation(input_text=input_text, model_identifier=model_identifier, organization_id= load_api_info()[0]['ORGANIZATION_ID'], access_token = load_api_info()[0]['API_KEY'])\n", 136 | "\n", 137 | "\n", 138 | "if __name__ == \"__main__\":\n", 139 | " print(f\"\\033[91mIt is worth noting that, when running in a Jupyter notebook environment, the code output may appear to be faster compared to a regular Python script. This discrepancy in performance has not been fully understood, but it is possible that contributing to resolving this issue could be beneficial. Additionally, the website that has been reverse engineered for this API interaction has been observed to be slow in terms of response time. Therefore, it is to be expected that the API responses will also be slower in comparison. It is suggested to use smaller models, such as 'llama-3-8b', to improve the responsiveness of the API interaction. Furthermore, it should be noted that the underlying website does not support fast API inference, resulting in slower responses\\n\\n\\033[92m1This will be printed on every command. It is recommended that you remove this print statement for not getting irritated\\033[0m\")\n", 140 | " \n", 141 | " response_content = initiate_api_conversation(input_text=\"Write 30 Lines about India \")\n", 142 | " # response_content = initiate_api_conversation(input_text=\"Can you please provide information about your development team, including the company or organization that created you, the names of your creators or lead developers, the programming languages and frameworks used to build you, and any notable features or technologies that enable your conversational capabilities?\", model_identifier=\"Claude-3-Sonnet\")\n", 143 | " # print(\"\\n\\n\\n\" + response_content)" 144 | ] 145 | } 146 | ], 147 | "metadata": { 148 | "kernelspec": { 149 | "display_name": "Python 3", 150 | "language": "python", 151 | "name": "python3" 152 | }, 153 | "language_info": { 154 | "codemirror_mode": { 155 | "name": "ipython", 156 | "version": 3 157 | }, 158 | "file_extension": ".py", 159 | "mimetype": "text/x-python", 160 | "name": "python", 161 | "nbconvert_exporter": "python", 162 | "pygments_lexer": "ipython3", 163 | "version": "3.10.10" 164 | } 165 | }, 166 | "nbformat": 4, 167 | "nbformat_minor": 2 168 | } 169 | -------------------------------------------------------------------------------- /ThebAI.py: -------------------------------------------------------------------------------- 1 | # Claude-3-Opus-Free-Reverse-Engineered-API 2 | # ====================================== 3 | # Author: Devs Do Code (Sree) 4 | # Description: Free and unlimited API interface to Claude 3 Opus and other AI models. 5 | # Features: Free and unlimited, Reverse-engineered, 10+ AI models available, including Claude 3 Opus 6 | # License: MIT License 7 | # Contributing: Fork and submit a pull request to contribute. 8 | 9 | import json 10 | import random 11 | import re 12 | import requests 13 | import json 14 | 15 | def load_api_info(): 16 | with open("Theb_API.json", "r") as file: 17 | return json.load(file) 18 | 19 | def remove_apis(): 20 | with open("Theb_API.json", "r") as file: 21 | data = json.load(file) 22 | if data: data.pop(0) 23 | with open("Theb_API.json", "w") as file: 24 | json.dump(data, file, indent=4) 25 | 26 | def initiate_api_conversation(input_text: str, model_identifier: str = 'Claude-3-Opus', organization_id: str = load_api_info()[0]['ORGANIZATION_ID'], access_token: str = load_api_info()[0]['API_KEY']) -> str: 27 | """ 28 | Initiates an API conversation request and retrieves the response content. 29 | 30 | Parameters: 31 | - organization_id (str): The unique identifier for the API organization. 32 | - model_identifier (str): The identifier for the desired conversation model. 33 | - input_text (str): The textual input for initiating the conversation. 34 | 35 | Returns: 36 | - str: The textual content of the API response. 37 | 38 | Note: 39 | - The model_identifier should correspond to one of the predefined model keys. 40 | """ 41 | 42 | # Mapping of model identifiers to their respective keys 43 | model_key_mapping = { 44 | 'Claude-3-Opus' : 'ade084104e614c31ada6892744fcd3c5', 45 | 'Claude-3-Haiku' : "d2c2b37c042d4b248af62a033eccd1b2", 46 | 'Claude-3-Sonnet' : "8b851ff081d54ba7b46a42a5099fcc64", 47 | 'Claude 2': 'a248a40fe3c4493598064c9ba725e8c9', 48 | 49 | 'llama-3-70b': '5da08fc7ac704d0d9bee545cbbb91793', 50 | 'llama-3-8b': 'c60d009ce85f47f087952f17eead4eab', 51 | 'cod-llama-70b': 'bccdb1b4dee94dc59d6e15e2a73ac2ba', 52 | 53 | 'mistral 8x22b': '70b3f32d71a34b97af9d660e1245fe15', 54 | 'WizardLM 2 8x22B' : 'ebf8820be60f40a38a3cae32795f8bd2', 55 | 56 | 'chatgpt-3-5-turbo': '58f5e7e50fee4779a1e5fe16c3aa302b', 57 | 'dbrx': '20ea474d42dd44eaa618971cdb16bfa7', 58 | 'Theb-ai': '7e682da4dde7ee214baa0efc0cf6d7a4', 59 | 60 | } 61 | 62 | # API endpoint construction 63 | api_endpoint = f"https://beta.theb.ai/api/conversation?org_id={organization_id}&req_rand={random.random()}" 64 | 65 | # HTTP request headers 66 | request_headers = { 67 | "Authorization": f"Bearer {access_token}", 68 | } 69 | 70 | # HTTP request payload 71 | request_payload = { 72 | "text": input_text, 73 | "model": model_key_mapping[model_identifier], 74 | "functions": None, 75 | "attachments": [], 76 | "model_params": { 77 | "system_prompt": "Be Helpful and Friendly", 78 | "temperature": "1", 79 | "top_p": "1", 80 | "frequency_penalty": "0", 81 | "presence_penalty": "0", 82 | "long_term_memory": "ltm" 83 | }, 84 | } 85 | 86 | # Execution of the API request 87 | payload_as_json = json.dumps(request_payload) 88 | response = requests.post(api_endpoint, headers=request_headers, data=payload_as_json, stream=True) 89 | if response.status_code == 200: 90 | accumulated_response_text = "" 91 | for line in response.iter_lines(decode_unicode=True, chunk_size=1, delimiter="\n"): 92 | if line and "event: " not in line: 93 | line_content = re.sub("data:", "", line) 94 | try: 95 | response_data = json.loads(line_content) 96 | if 'tid' in response_data: continue 97 | print(response_data['args']['content'].replace(accumulated_response_text, ''), end="") 98 | accumulated_response_text = response_data['args']['content'] 99 | except json.JSONDecodeError: 100 | continue 101 | 102 | 103 | if accumulated_response_text != "": return accumulated_response_text 104 | else : 105 | resp_lines = response.text.split("\r") 106 | for line in reversed(resp_lines): 107 | if "event: " not in line and line.strip(): 108 | try: 109 | data_value = re.sub("data:", "", line) 110 | json_data = json.loads(data_value) 111 | return json_data['args']['content'] 112 | except Exception as e: 113 | continue 114 | 115 | elif response.status_code == 400: 116 | print("\033[91m" + f"Switching to Next API " + "\033[0m") 117 | remove_apis() 118 | return initiate_api_conversation(input_text=input_text, model_identifier=model_identifier, organization_id= load_api_info()[0]['ORGANIZATION_ID'], access_token = load_api_info()[0]['API_KEY']) 119 | 120 | 121 | if __name__ == "__main__": 122 | print(f"\033[91mIt is worth noting that, when running in a Jupyter notebook environment, the code output may appear to be faster compared to a regular Python script. This discrepancy in performance has not been fully understood, but it is possible that contributing to resolving this issue could be beneficial. Additionally, the website that has been reverse engineered for this API interaction has been observed to be slow in terms of response time. Therefore, it is to be expected that the API responses will also be slower in comparison. It is suggested to use smaller models, such as 'llama-3-8b', to improve the responsiveness of the API interaction. Furthermore, it should be noted that the underlying website does not support fast API inference, resulting in slower responses\n\n\033[92m1This will be printed on every command. It is recommended that you remove this print statement for not getting irritated\033[0m") 123 | response_content = initiate_api_conversation(input_text="Write 30 Lines about India ") 124 | # response_content = initiate_api_conversation(input_text="Can you please provide information about your development team, including the company or organization that created you, the names of your creators or lead developers, the programming languages and frameworks used to build you, and any notable features or technologies that enable your conversational capabilities?", model_identifier="Claude-3-Sonnet") 125 | # print("\n\n\n" + response_content) -------------------------------------------------------------------------------- /Theb_AI_Login.py: -------------------------------------------------------------------------------- 1 | # Theb-API-Generator 2 | # ==================== 3 | # Author: Devs Do Code (Sree) 4 | # Description: A Python script to generate API keys and organization IDs for Theb AI platform. 5 | # Features: Automatic email creation, registration, verification, and API token generation. 6 | # License: MIT License 7 | # Contributing: Fork and submit a pull request to contribute. 8 | 9 | import re 10 | import requests 11 | import asyncio 12 | import time 13 | from selenium import webdriver 14 | from selenium.webdriver.chrome.options import Options 15 | from webscout import tempid 16 | import json 17 | import threading 18 | import os 19 | 20 | def update_file(api_key, organization_id): 21 | data = [] # Initialize an empty list 22 | 23 | # Check if the JSON file exists and is not empty 24 | if os.path.exists("Theb_API.json") and os.path.getsize("Theb_API.json") > 0: 25 | # Read the existing JSON data as a list of dictionaries 26 | with open("Theb_API.json", "r") as file: 27 | try: 28 | data = json.load(file) 29 | except json.JSONDecodeError: 30 | pass # Ignore and continue with an empty list if the file is not valid JSON 31 | 32 | # Update the API key and organization ID 33 | data.append({"API_KEY": api_key, "ORGANIZATION_ID": organization_id}) 34 | 35 | # Write the updated data back to the JSON file 36 | with open("Theb_API.json", "w") as file: 37 | json.dump(data, file, indent=4) 38 | 39 | async def generate_email(): 40 | """Generates a temporary email using webscout.""" 41 | client = tempid.Client() 42 | domains = await client.get_domains() 43 | email = await client.create_email(domain=domains[0].name) 44 | print(f"\033[96mTemporary email created: {email.email}\033[0m") 45 | return email 46 | 47 | async def register_user(email, fullname="DevsDoCode", password="DevsDoCode@07"): 48 | """Registers on the website using the temporary email.""" 49 | print("\033[91m--- REGISTRATION ---\033[0m") 50 | url = "https://beta.theb.ai/api/register" 51 | payload = { 52 | "fullname": fullname, 53 | "email": email.email, 54 | "password": password, 55 | } 56 | headers = { 57 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", 58 | "X-Cf-Turnstile-Token": "", 59 | } 60 | response = requests.post(url, json=payload, headers=headers) 61 | print("Response Status Code (Registration):", response.status_code) 62 | print("Response Content (Registration):", response.json()) 63 | return fullname, password 64 | 65 | async def verify_email(email, client, headless=True): 66 | """Extracts the verification link from the temporary email and verifies it.""" 67 | print("\033[91m--- VERIFICATION ---\033[0m") 68 | async def get_verification_link() -> str: 69 | while True: 70 | print("Waiting for the verification email...", flush=True, end="\r") 71 | messages = await client.get_messages(email.email) 72 | if messages: 73 | break 74 | for message in messages: 75 | match = re.search(r'https://beta\.theb\.ai/verify-email\?t=[^ ]+', message.body_text) 76 | if match: 77 | return match.group(0) 78 | return None 79 | 80 | verification_link = await get_verification_link() 81 | if verification_link: 82 | print("Verification link found in the email:", verification_link) 83 | options = Options() 84 | if headless: options.add_argument("--headless") 85 | options.add_argument("--disable-gpu") 86 | 87 | # Create a new instance of the Chrome driver 88 | driver = webdriver.Chrome(options=options) 89 | 90 | # Open the verification link 91 | driver.get(verification_link) 92 | time.sleep(5) 93 | driver.quit() 94 | print("Email verified successfully!") 95 | else: 96 | print("Verification link not found in the email.") 97 | return 98 | 99 | async def get_api_token(email, fullname="DevsDoCode", password="DevsDoCode@07"): 100 | """Gets the API token for the user.""" 101 | print("\033[91m--- API TOKEN ---\033[0m") 102 | url = "https://beta.theb.ai/api/token" 103 | payload = { 104 | "username": email.email, 105 | "password": password 106 | } 107 | headers = { 108 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", 109 | "X-Client-Language": "en" 110 | } 111 | response = requests.post(url, data=payload, headers=headers) 112 | print("Response Status Code (Token):", response.status_code) 113 | print("Response Content (Token):", response.json()) 114 | 115 | if response.status_code == 200: 116 | access_token = response.json()['access_token'] 117 | print("Access Token:", access_token) 118 | return access_token 119 | else: 120 | print("Failed to retrieve API token. Error:", response.json().get('data', {}).get('detail', 'Unknown error')) 121 | return # Exit the function if the token request fails 122 | 123 | async def get_organization_id(access_token): 124 | print("\033[91m--- ORGANIZATION ID ---\033[0m") 125 | url = "https://beta.theb.ai/api/me" 126 | headers = { 127 | "Authorization": f"Bearer {access_token}", 128 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", 129 | "X-Client-Language": "en" 130 | } 131 | 132 | response = requests.get(url, headers=headers) 133 | 134 | print("Response Status Code:", response.status_code) 135 | print("Response Content:", response.json()) 136 | if response.status_code == 200: 137 | print("User logged in successfully!") 138 | organization_id = response.json()['data']['organizations'][0]['id'] 139 | print("Organization ID:", organization_id) 140 | return organization_id 141 | else: 142 | print("Failed to Login. Error:", response.json()) 143 | 144 | async def main(): 145 | email = await generate_email() 146 | await register_user(email) 147 | client = tempid.Client() 148 | await verify_email(email, client, headless=True) 149 | api_token = await get_api_token(email) 150 | organization_id =await get_organization_id(api_token) 151 | if api_token is not None and organization_id is not None: 152 | print(f"Successfully Initialized.....\nAPI KEY : \033[92m{api_token}\033[0m\nORGANIZATION ID : \033[92m{organization_id}\033[0m") 153 | update_file(api_key=api_token, organization_id=organization_id) 154 | else: print("\033[91mFailed to initialize. Please try again.\033[0m") 155 | 156 | def start_async_tasks(at_once: int = 5): 157 | """Starts multiple instances of an asynchronous main task.""" 158 | threads = [] 159 | 160 | # Launch multiple threads to run the async task concurrently 161 | for _ in range(at_once): 162 | thread = threading.Thread(target=lambda:asyncio.run(main())) 163 | threads.append(thread) 164 | thread.start() 165 | 166 | # Wait for all threads to finish execution 167 | for thread in threads: 168 | thread.join() 169 | 170 | # Signal that all threads have completed their tasks 171 | print("\033[92mAll async tasks have been completed.\033[0m") 172 | 173 | 174 | """For Multiple Thread Execution i.e. Concurrent Execution""" 175 | if __name__ == '__main__': 176 | start_async_tasks() 177 | 178 | """For Single Thread Execution i.e . One By One""" 179 | # if __name__ == '__main__': 180 | # while True: 181 | # asyncio.run(main()) 182 | 183 | 184 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Requests==2.31.0 2 | selenium==4.20.0 3 | webscout==1.4.1 --------------------------------------------------------------------------------