From bfe79a31d8737abbde129337396f4d43422fddc1 Mon Sep 17 00:00:00 2001 From: Romeo Phillips Date: Thu, 18 Apr 2024 14:34:29 -0700 Subject: [PATCH] readme --- README.md | 4 +++- src/meta_ai_api/main.py | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a6cf005..970facd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MetaAI +# MetaAI API Wrapper MetaAI is a Python library designed to interact with Meta's AI APIs. It encapsulates the complexities of authentication and communication with the APIs, providing a straightforward interface for sending queries and receiving responses. @@ -6,6 +6,8 @@ With this you can easily prompt the AI with a message and get a response, direct **Meta AI is connected to the internet, so you will be able to get the latest real-time responses from the AI.** (powered by Bing) +Meta AI is running Llama 3 LLM. + ## Usage 1. **Download**: diff --git a/src/meta_ai_api/main.py b/src/meta_ai_api/main.py index 3b194c0..6fa4ad3 100644 --- a/src/meta_ai_api/main.py +++ b/src/meta_ai_api/main.py @@ -49,7 +49,7 @@ def get_cookies(self): ) return {"_js_datr": _js_datr, "abra_csrf": abra_csrf} - def prompt(self, message: str): + def prompt(self, message: str, attempts: int = 0): url = "https://graph.meta.ai/graphql?locale=user" payload = f"av=0&access_token={self.access_token}&__user=0&__a=1&__req=p&__hs=19831.HYP%3Aabra_pkg.2.1..0.0&dpr=1&__ccg=UNKNOWN&__s=%3A0ryskm%3Aewvpqb&__comet_req=46&lsd=AVrLt4uZ-4k&__spin_b=trunk&__jssesw=1&fb_api_caller_class=RelayModern&fb_api_req_friendly_name=useAbraSendMessageMutation&variables=%7B%22message%22%3A%7B%22sensitive_string_value%22%3A%22{message}%22%7D%2C%22externalConversationId%22%3A%22dae20bda-6450-4ce7-880c-1db1b3ae7da3%22%2C%22offlineThreadingId%22%3A%227186784311738402039%22%2C%22suggestedPromptIndex%22%3Anull%2C%22flashVideoRecapInput%22%3A%7B%22images%22%3A%5B%5D%7D%2C%22flashPreviewInput%22%3Anull%2C%22promptPrefix%22%3Anull%2C%22entrypoint%22%3A%22ABRA__CHAT__TEXT%22%2C%22icebreaker_type%22%3A%22TEXT%22%2C%22__relay_internal__pv__AbraDebugDevOnlyrelayprovider%22%3Afalse%2C%22__relay_internal__pv__WebPixelRatiorelayprovider%22%3A1%7D&server_timestamps=true&doc_id=7783822248314888" @@ -67,6 +67,13 @@ def prompt(self, message: str): json_line = json.loads(line) if "errors" not in json_line.keys(): last_streamed_response = json_line + + if last_streamed_response is None: + if attempts > 3: + raise Exception( + "Was not able to query Meta AI. Either patched or MetaAI is having issues." + ) + return self.prompt(message=message, attempts=attempts + 1) for content in last_streamed_response["data"]["node"]["bot_response_message"][ "composed_text" ]["content"]: