Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Strvm committed Apr 18, 2024
1 parent 2cdb717 commit bfe79a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# 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.

With this you can easily prompt the AI with a message and get a response, directly from your Python code. **NO API KEY REQUIRED**

**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**:

Expand Down
9 changes: 8 additions & 1 deletion src/meta_ai_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]:
Expand Down

0 comments on commit bfe79a3

Please sign in to comment.