metaai-sdk 2.0.0__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.
- metaai_api/__init__.py +20 -0
- metaai_api/api_server.py +256 -0
- metaai_api/client.py +140 -0
- metaai_api/exceptions.py +6 -0
- metaai_api/main.py +534 -0
- metaai_api/utils.py +291 -0
- metaai_api/video_generation.py +679 -0
- metaai_sdk-2.0.0.dist-info/METADATA +846 -0
- metaai_sdk-2.0.0.dist-info/RECORD +12 -0
- metaai_sdk-2.0.0.dist-info/WHEEL +5 -0
- metaai_sdk-2.0.0.dist-info/licenses/LICENSE +28 -0
- metaai_sdk-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,846 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: metaai-sdk
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Feature-rich Python SDK for Meta AI - Chat, Image & Video Generation powered by Llama 3
|
|
5
|
+
Home-page: https://github.com/mir-ashiq/metaai-api
|
|
6
|
+
Author: Meta AI SDK Team
|
|
7
|
+
Author-email: Ashiq Hussain Mir <imseldrith@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/mir-ashiq/metaai-api
|
|
10
|
+
Project-URL: Documentation, https://github.com/mir-ashiq/metaai-api/blob/main/README.md
|
|
11
|
+
Project-URL: Repository, https://github.com/mir-ashiq/metaai-api
|
|
12
|
+
Project-URL: Changelog, https://github.com/mir-ashiq/metaai-api/blob/main/CHANGELOG.md
|
|
13
|
+
Keywords: metaai,meta-ai,llama3,ai,llm,video-generation,chatbot
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Requires-Python: >=3.7
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: requests>=2.31.0
|
|
27
|
+
Requires-Dist: requests-html>=0.10.0
|
|
28
|
+
Requires-Dist: lxml-html-clean>=0.1.1
|
|
29
|
+
Requires-Dist: beautifulsoup4>=4.9.0
|
|
30
|
+
Provides-Extra: api
|
|
31
|
+
Requires-Dist: fastapi<0.96.0,>=0.95.2; extra == "api"
|
|
32
|
+
Requires-Dist: uvicorn[standard]<0.24.0,>=0.22.0; extra == "api"
|
|
33
|
+
Requires-Dist: python-multipart>=0.0.6; extra == "api"
|
|
34
|
+
Requires-Dist: python-dotenv>=1.0.0; extra == "api"
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: check-manifest; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest; extra == "dev"
|
|
38
|
+
Requires-Dist: black; extra == "dev"
|
|
39
|
+
Requires-Dist: flake8; extra == "dev"
|
|
40
|
+
Dynamic: author
|
|
41
|
+
Dynamic: home-page
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
Dynamic: requires-python
|
|
44
|
+
|
|
45
|
+
<div align="center">
|
|
46
|
+
|
|
47
|
+
# 🤖 Meta AI Python SDK
|
|
48
|
+
|
|
49
|
+
[](https://www.python.org/downloads/)
|
|
50
|
+
[](LICENSE)
|
|
51
|
+
[](https://pypi.org/project/metaai-api/)
|
|
52
|
+
[](https://github.com/mir-ashiq/metaai-api)
|
|
53
|
+
|
|
54
|
+
**Unleash the Power of Meta AI with Python** 🚀
|
|
55
|
+
|
|
56
|
+
A modern, feature-rich Python SDK providing seamless access to Meta AI's cutting-edge capabilities:
|
|
57
|
+
Chat with Llama 3, Generate Images, Create AI Videos - All Without API Keys!
|
|
58
|
+
|
|
59
|
+
[🎯 Quick Start](#-quick-start) • [📖 Documentation](#-documentation) • [💡 Examples](#-examples) • [🎬 Video Generation](#-video-generation)
|
|
60
|
+
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## ✨ Why Choose This SDK?
|
|
66
|
+
|
|
67
|
+
<table>
|
|
68
|
+
<tr>
|
|
69
|
+
<td width="33%" align="center">
|
|
70
|
+
|
|
71
|
+
### 🎯 **Zero Configuration**
|
|
72
|
+
|
|
73
|
+
No API keys needed!
|
|
74
|
+
Just install and start coding
|
|
75
|
+
|
|
76
|
+
</td>
|
|
77
|
+
<td width="33%" align="center">
|
|
78
|
+
|
|
79
|
+
### ⚡ **Lightning Fast**
|
|
80
|
+
|
|
81
|
+
Optimized for performance
|
|
82
|
+
Real-time responses
|
|
83
|
+
|
|
84
|
+
</td>
|
|
85
|
+
<td width="33%" align="center">
|
|
86
|
+
|
|
87
|
+
### 🔥 **Feature Complete**
|
|
88
|
+
|
|
89
|
+
Chat • Images • Videos
|
|
90
|
+
All in one SDK
|
|
91
|
+
|
|
92
|
+
</td>
|
|
93
|
+
</tr>
|
|
94
|
+
</table>
|
|
95
|
+
|
|
96
|
+
### 🌟 Core Capabilities
|
|
97
|
+
|
|
98
|
+
| Feature | Description | Status |
|
|
99
|
+
| ---------------------------- | -------------------------------------------- | -------- |
|
|
100
|
+
| 💬 **Intelligent Chat** | Powered by Llama 3 with internet access | ✅ Ready |
|
|
101
|
+
| 🎨 **Image Generation** | Create stunning AI-generated images | ✅ Ready |
|
|
102
|
+
| 🎬 **Video Generation** | Generate videos from text prompts | ✅ Ready |
|
|
103
|
+
| 🌐 **Real-time Data** | Get current information via Bing integration | ✅ Ready |
|
|
104
|
+
| 📚 **Source Citations** | Responses include verifiable sources | ✅ Ready |
|
|
105
|
+
| 🔄 **Streaming Support** | Real-time response streaming | ✅ Ready |
|
|
106
|
+
| 🔐 **Auto Token Management** | Automatic authentication handling | ✅ Ready |
|
|
107
|
+
| 🌍 **Proxy Support** | Route requests through proxies | ✅ Ready |
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## 📦 Installation
|
|
112
|
+
|
|
113
|
+
### SDK Only (Lightweight)
|
|
114
|
+
|
|
115
|
+
For using Meta AI as a Python library:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
pip install metaai-api
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### SDK + API Server
|
|
122
|
+
|
|
123
|
+
For deploying as a REST API service:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
pip install metaai-api[api]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### From Source
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
git clone https://github.com/mir-ashiq/metaai-api.git
|
|
133
|
+
cd metaai-api
|
|
134
|
+
pip install -e . # SDK only
|
|
135
|
+
pip install -e ".[api]" # SDK + API server
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**System Requirements:** Python 3.7+ • Internet Connection • That's it!
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 🚀 Quick Start
|
|
143
|
+
|
|
144
|
+
### Example 1: Ask a Question
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from metaai_api import MetaAI
|
|
148
|
+
|
|
149
|
+
# Initialize the AI
|
|
150
|
+
ai = MetaAI()
|
|
151
|
+
|
|
152
|
+
# Ask anything!
|
|
153
|
+
response = ai.prompt("Who won the NBA championship in 2024?")
|
|
154
|
+
print(response["message"])
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Output:**
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
The Boston Celtics won the 2024 NBA Championship, defeating the Dallas Mavericks
|
|
161
|
+
4-1 in the Finals. Jayson Tatum and Jaylen Brown led the Celtics to their 18th
|
|
162
|
+
championship title, the most in NBA history. The series concluded on June 17, 2024,
|
|
163
|
+
with the Celtics winning Game 5 at TD Garden in Boston.
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Example 2: Get Stock Market Info
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from metaai_api import MetaAI
|
|
170
|
+
|
|
171
|
+
ai = MetaAI()
|
|
172
|
+
response = ai.prompt("What is the current price of Bitcoin?")
|
|
173
|
+
|
|
174
|
+
print(f"💰 {response['message']}")
|
|
175
|
+
print(f"\n📚 Sources: {len(response['sources'])} references found")
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Output:**
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
💰 As of November 22, 2025, Bitcoin (BTC) is trading at approximately $97,845 USD.
|
|
182
|
+
The cryptocurrency has seen a 3.2% increase in the last 24 hours. Bitcoin's market
|
|
183
|
+
capitalization stands at around $1.93 trillion, maintaining its position as the
|
|
184
|
+
largest cryptocurrency by market cap.
|
|
185
|
+
|
|
186
|
+
📚 Sources: 4 references found
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Example 3: Solve Math Problems
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from metaai_api import MetaAI
|
|
193
|
+
|
|
194
|
+
ai = MetaAI()
|
|
195
|
+
|
|
196
|
+
# Complex calculation
|
|
197
|
+
question = "If I invest $10,000 at 7% annual interest compounded monthly for 5 years, how much will I have?"
|
|
198
|
+
response = ai.prompt(question)
|
|
199
|
+
|
|
200
|
+
print(response["message"])
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Output:**
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
With an initial investment of $10,000 at a 7% annual interest rate compounded monthly
|
|
207
|
+
over 5 years, you would have approximately $14,176.25.
|
|
208
|
+
|
|
209
|
+
Here's the breakdown:
|
|
210
|
+
- Principal: $10,000
|
|
211
|
+
- Interest Rate: 7% per year (0.583% per month)
|
|
212
|
+
- Time: 5 years (60 months)
|
|
213
|
+
- Compound Frequency: Monthly
|
|
214
|
+
- Total Interest Earned: $4,176.25
|
|
215
|
+
- Final Amount: $14,176.25
|
|
216
|
+
|
|
217
|
+
This calculation uses the compound interest formula: A = P(1 + r/n)^(nt)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## 💬 Chat Features
|
|
223
|
+
|
|
224
|
+
### Streaming Responses
|
|
225
|
+
|
|
226
|
+
Watch responses appear in real-time, like ChatGPT:
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
from metaai_api import MetaAI
|
|
230
|
+
|
|
231
|
+
ai = MetaAI()
|
|
232
|
+
|
|
233
|
+
print("🤖 AI: ", end="", flush=True)
|
|
234
|
+
for chunk in ai.prompt("Explain quantum computing in simple terms", stream=True):
|
|
235
|
+
print(chunk["message"], end="", flush=True)
|
|
236
|
+
print("\n")
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
**Output:**
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
🤖 AI: Quantum computing is like having a super-powered calculator that can solve
|
|
243
|
+
problems in completely new ways. Instead of regular computer bits that are either
|
|
244
|
+
0 or 1, quantum computers use "qubits" that can be both 0 and 1 at the same time -
|
|
245
|
+
imagine flipping a coin that's both heads and tails until you look at it! This
|
|
246
|
+
special ability allows quantum computers to process massive amounts of information
|
|
247
|
+
simultaneously, making them incredibly fast for specific tasks like drug discovery,
|
|
248
|
+
cryptography, and complex simulations.
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Conversation Context
|
|
252
|
+
|
|
253
|
+
Have natural back-and-forth conversations:
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
from metaai_api import MetaAI
|
|
257
|
+
|
|
258
|
+
ai = MetaAI()
|
|
259
|
+
|
|
260
|
+
# First question
|
|
261
|
+
response1 = ai.prompt("What are the three primary colors?")
|
|
262
|
+
print("Q1:", response1["message"][:100])
|
|
263
|
+
|
|
264
|
+
# Follow-up question (maintains context)
|
|
265
|
+
response2 = ai.prompt("How do you mix them to make purple?")
|
|
266
|
+
print("Q2:", response2["message"][:150])
|
|
267
|
+
|
|
268
|
+
# Start fresh conversation
|
|
269
|
+
response3 = ai.prompt("What's the capital of France?", new_conversation=True)
|
|
270
|
+
print("Q3:", response3["message"][:50])
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Output:**
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
Q1: The three primary colors are Red, Blue, and Yellow. These colors cannot be created by mixing...
|
|
277
|
+
|
|
278
|
+
Q2: To make purple, you mix Red and Blue together. The exact shade of purple depends on the ratio - more red creates a reddish-purple (like magenta)...
|
|
279
|
+
|
|
280
|
+
Q3: The capital of France is Paris, located in the...
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Using Proxies
|
|
284
|
+
|
|
285
|
+
Route your requests through a proxy:
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
from metaai_api import MetaAI
|
|
289
|
+
|
|
290
|
+
# Configure proxy
|
|
291
|
+
proxy = {
|
|
292
|
+
'http': 'http://your-proxy-server:8080',
|
|
293
|
+
'https': 'https://your-proxy-server:8080'
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
ai = MetaAI(proxy=proxy)
|
|
297
|
+
response = ai.prompt("Hello from behind a proxy!")
|
|
298
|
+
print(response["message"])
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## � REST API Server (Optional)
|
|
304
|
+
|
|
305
|
+
Deploy Meta AI as a REST API service that anyone can use! The API server auto-refreshes cookies to keep sessions alive.
|
|
306
|
+
|
|
307
|
+
### Installation
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
pip install metaai-api[api]
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Setup
|
|
314
|
+
|
|
315
|
+
1. **Get your Meta AI cookies** (see [Video Generation](#-video-generation) section)
|
|
316
|
+
2. **Create `.env` file:**
|
|
317
|
+
|
|
318
|
+
```env
|
|
319
|
+
META_AI_DATR=your_datr_cookie
|
|
320
|
+
META_AI_ABRA_SESS=your_abra_sess_cookie
|
|
321
|
+
META_AI_DPR=1
|
|
322
|
+
META_AI_WD=1920x1080
|
|
323
|
+
META_AI_REFRESH_INTERVAL_SECONDS=3600
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
3. **Start the server:**
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
uvicorn metaai_api.api_server:app --host 0.0.0.0 --port 8000
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### API Endpoints
|
|
333
|
+
|
|
334
|
+
| Endpoint | Method | Description |
|
|
335
|
+
| ---------------------- | ------ | -------------------------------------- |
|
|
336
|
+
| `/chat` | POST | Send chat messages |
|
|
337
|
+
| `/video` | POST | Generate video (blocks until complete) |
|
|
338
|
+
| `/video/async` | POST | Start async video generation |
|
|
339
|
+
| `/video/jobs/{job_id}` | GET | Poll async job status |
|
|
340
|
+
| `/healthz` | GET | Health check |
|
|
341
|
+
|
|
342
|
+
### Example Usage
|
|
343
|
+
|
|
344
|
+
```python
|
|
345
|
+
import requests
|
|
346
|
+
|
|
347
|
+
# Chat
|
|
348
|
+
response = requests.post("http://localhost:8000/chat", json={
|
|
349
|
+
"message": "What is the capital of France?",
|
|
350
|
+
"stream": False
|
|
351
|
+
})
|
|
352
|
+
print(response.json())
|
|
353
|
+
|
|
354
|
+
# Async video generation
|
|
355
|
+
job = requests.post("http://localhost:8000/video/async", json={
|
|
356
|
+
"prompt": "Generate a video of a sunset"
|
|
357
|
+
})
|
|
358
|
+
job_id = job.json()["job_id"]
|
|
359
|
+
|
|
360
|
+
# Poll for result
|
|
361
|
+
status = requests.get(f"http://localhost:8000/video/jobs/{job_id}")
|
|
362
|
+
print(status.json())
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Testing
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
python test_api.py
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## �🎬 Video Generation
|
|
374
|
+
|
|
375
|
+
Create AI-generated videos from text descriptions!
|
|
376
|
+
|
|
377
|
+
### Setup: Get Your Cookies
|
|
378
|
+
|
|
379
|
+
1. Visit [meta.ai](https://www.meta.ai) in your browser
|
|
380
|
+
2. Open DevTools (F12) → **Network** tab
|
|
381
|
+
3. Refresh the page
|
|
382
|
+
4. Click any request → **Headers** → Copy **Cookie** value
|
|
383
|
+
5. Extract these values: `datr`, `abra_sess`, `dpr`, `wd`
|
|
384
|
+
|
|
385
|
+
### Example 1: Generate Your First Video
|
|
386
|
+
|
|
387
|
+
```python
|
|
388
|
+
from metaai_api import MetaAI
|
|
389
|
+
|
|
390
|
+
# Your browser cookies
|
|
391
|
+
cookies = {
|
|
392
|
+
"datr": "your_datr_value_here",
|
|
393
|
+
"abra_sess": "your_abra_sess_value_here",
|
|
394
|
+
"dpr": "1.25",
|
|
395
|
+
"wd": "1920x1080"
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
# Initialize with cookies
|
|
399
|
+
ai = MetaAI(cookies=cookies)
|
|
400
|
+
|
|
401
|
+
# Generate a video
|
|
402
|
+
result = ai.generate_video("A majestic lion walking through the African savanna at sunset")
|
|
403
|
+
|
|
404
|
+
if result["success"]:
|
|
405
|
+
print("✅ Video generated successfully!")
|
|
406
|
+
print(f"🎬 Generated {len(result['video_urls'])} videos (Meta AI creates 4 by default)")
|
|
407
|
+
for i, url in enumerate(result['video_urls'], 1):
|
|
408
|
+
print(f" Video {i}: {url}")
|
|
409
|
+
print(f"📝 Prompt: {result['prompt']}")
|
|
410
|
+
print(f"🆔 Conversation ID: {result['conversation_id']}")
|
|
411
|
+
else:
|
|
412
|
+
print("⏳ Video is still processing, try again in a moment")
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
**Output:**
|
|
416
|
+
|
|
417
|
+
```
|
|
418
|
+
[*] Fetching missing tokens (lsd, fb_dtsg) from Meta AI...
|
|
419
|
+
[✓] Fetched lsd: AVrvi8aHxzQ
|
|
420
|
+
[✓] Fetched fb_dtsg: BQAB9uRXmPEYGkC...
|
|
421
|
+
|
|
422
|
+
✅ Sending video generation request...
|
|
423
|
+
✅ Video generation request sent successfully!
|
|
424
|
+
⏳ Waiting 10 seconds before polling...
|
|
425
|
+
🔄 Polling for video URLs (Attempt 1/30)...
|
|
426
|
+
✅ Video URLs found!
|
|
427
|
+
|
|
428
|
+
✅ Video generated successfully!
|
|
429
|
+
🎬 Generated 4 videos (Meta AI creates 4 by default)
|
|
430
|
+
Video 1: https://scontent.xx.fbcdn.net/v/t66.36240-6/video1.mp4?...
|
|
431
|
+
Video 2: https://scontent.xx.fbcdn.net/v/t66.36240-6/video2.mp4?...
|
|
432
|
+
Video 3: https://scontent.xx.fbcdn.net/v/t66.36240-6/video3.mp4?...
|
|
433
|
+
Video 4: https://scontent.xx.fbcdn.net/v/t66.36240-6/video4.mp4?...
|
|
434
|
+
📝 Prompt: A majestic lion walking through the African savanna at sunset
|
|
435
|
+
🆔 Conversation ID: abc123-def456-ghi789
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### Example 2: Generate Multiple Videos
|
|
439
|
+
|
|
440
|
+
```python
|
|
441
|
+
from metaai_api import MetaAI
|
|
442
|
+
import time
|
|
443
|
+
|
|
444
|
+
ai = MetaAI(cookies=cookies)
|
|
445
|
+
|
|
446
|
+
prompts = [
|
|
447
|
+
"A futuristic city with flying cars at night",
|
|
448
|
+
"Ocean waves crashing on a tropical beach",
|
|
449
|
+
"Northern lights dancing over a snowy mountain"
|
|
450
|
+
]
|
|
451
|
+
|
|
452
|
+
videos = []
|
|
453
|
+
for i, prompt in enumerate(prompts, 1):
|
|
454
|
+
print(f"\n🎬 Generating video {i}/{len(prompts)}: {prompt}")
|
|
455
|
+
result = ai.generate_video(prompt, verbose=False)
|
|
456
|
+
|
|
457
|
+
if result["success"]:
|
|
458
|
+
videos.append(result["video_urls"][0])
|
|
459
|
+
print(f"✅ Success! URL: {result['video_urls'][0][:50]}...")
|
|
460
|
+
else:
|
|
461
|
+
print("⏳ Still processing...")
|
|
462
|
+
|
|
463
|
+
time.sleep(5) # Be nice to the API
|
|
464
|
+
|
|
465
|
+
print(f"\n🎉 Generated {len(videos)} videos successfully!")
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
**Output:**
|
|
469
|
+
|
|
470
|
+
```
|
|
471
|
+
🎬 Generating video 1/3: A futuristic city with flying cars at night
|
|
472
|
+
✅ Success! URL: https://scontent.xx.fbcdn.net/v/t66.36240-6/1234...
|
|
473
|
+
|
|
474
|
+
🎬 Generating video 2/3: Ocean waves crashing on a tropical beach
|
|
475
|
+
✅ Success! URL: https://scontent.xx.fbcdn.net/v/t66.36240-6/5678...
|
|
476
|
+
|
|
477
|
+
🎬 Generating video 3/3: Northern lights dancing over a snowy mountain
|
|
478
|
+
✅ Success! URL: https://scontent.xx.fbcdn.net/v/t66.36240-6/9012...
|
|
479
|
+
|
|
480
|
+
🎉 Generated 3 videos successfully!
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### Example 3: Advanced Video Generation
|
|
484
|
+
|
|
485
|
+
```python
|
|
486
|
+
from metaai_api import MetaAI
|
|
487
|
+
|
|
488
|
+
ai = MetaAI(cookies=cookies)
|
|
489
|
+
|
|
490
|
+
# Fine-tune generation parameters
|
|
491
|
+
result = ai.generate_video(
|
|
492
|
+
prompt="A time-lapse of a flower blooming",
|
|
493
|
+
wait_before_poll=15, # Wait 15 seconds before checking
|
|
494
|
+
max_attempts=50, # Try up to 50 times
|
|
495
|
+
wait_seconds=3, # Wait 3 seconds between attempts
|
|
496
|
+
verbose=True # Show detailed progress
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
if result["success"]:
|
|
500
|
+
print(f"\n🎬 Your videos are ready!")
|
|
501
|
+
print(f"🔗 Generated {len(result['video_urls'])} videos:")
|
|
502
|
+
for i, url in enumerate(result['video_urls'], 1):
|
|
503
|
+
print(f" Video {i}: {url}")
|
|
504
|
+
print(f"⏱️ Generated at: {result['timestamp']}")
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
📖 **Full Video Guide:** See [VIDEO_GENERATION_README.md](VIDEO_GENERATION_README.md) for complete documentation!
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
## 🎨 Image Generation
|
|
512
|
+
|
|
513
|
+
Generate AI-powered images (requires Facebook authentication):
|
|
514
|
+
|
|
515
|
+
```python
|
|
516
|
+
from metaai_api import MetaAI
|
|
517
|
+
|
|
518
|
+
# Initialize with Facebook credentials
|
|
519
|
+
ai = MetaAI(fb_email="your_email@example.com", fb_password="your_password")
|
|
520
|
+
|
|
521
|
+
# Generate images
|
|
522
|
+
response = ai.prompt("Generate an image of a cyberpunk cityscape at night with neon lights")
|
|
523
|
+
|
|
524
|
+
# Display results (Meta AI generates 4 images by default)
|
|
525
|
+
print(f"🎨 Generated {len(response['media'])} images:")
|
|
526
|
+
for i, image in enumerate(response['media'], 1):
|
|
527
|
+
print(f" Image {i}: {image['url']}")
|
|
528
|
+
print(f" Prompt: {image['prompt']}")
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
**Output:**
|
|
532
|
+
|
|
533
|
+
```
|
|
534
|
+
🎨 Generated 4 images:
|
|
535
|
+
Image 1: https://scontent.xx.fbcdn.net/o1/v/t0/f1/m247/img1.jpeg
|
|
536
|
+
Prompt: a cyberpunk cityscape at night with neon lights
|
|
537
|
+
|
|
538
|
+
Image 2: https://scontent.xx.fbcdn.net/o1/v/t0/f1/m247/img2.jpeg
|
|
539
|
+
Prompt: a cyberpunk cityscape at night with neon lights
|
|
540
|
+
|
|
541
|
+
Image 3: https://scontent.xx.fbcdn.net/o1/v/t0/f1/m247/img3.jpeg
|
|
542
|
+
Prompt: a cyberpunk cityscape at night with neon lights
|
|
543
|
+
|
|
544
|
+
Image 4: https://scontent.xx.fbcdn.net/o1/v/t0/f1/m247/img4.jpeg
|
|
545
|
+
Prompt: a cyberpunk cityscape at night with neon lights
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
---
|
|
549
|
+
|
|
550
|
+
## 💡 Examples
|
|
551
|
+
|
|
552
|
+
Explore working examples in the `examples/` directory:
|
|
553
|
+
|
|
554
|
+
| File | Description | Features |
|
|
555
|
+
| ---------------------------------------------------------- | ----------------- | --------------------------------- |
|
|
556
|
+
| 📄 **[simple_example.py](examples/simple_example.py)** | Quick start guide | Basic chat + video generation |
|
|
557
|
+
| 📄 **[video_generation.py](examples/video_generation.py)** | Video generation | Multiple examples, error handling |
|
|
558
|
+
| 📄 **[test_example.py](examples/test_example.py)** | Testing suite | Validation and testing |
|
|
559
|
+
|
|
560
|
+
### Run an Example
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
# Clone the repository
|
|
564
|
+
git clone https://github.com/mir-ashiq/metaai-api.git
|
|
565
|
+
cd meta-ai-python
|
|
566
|
+
|
|
567
|
+
# Run simple example
|
|
568
|
+
python examples/simple_example.py
|
|
569
|
+
|
|
570
|
+
# Run video generation examples
|
|
571
|
+
python examples/video_generation.py
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
## 📖 Documentation
|
|
577
|
+
|
|
578
|
+
### 📚 Complete Guides
|
|
579
|
+
|
|
580
|
+
| Document | Description |
|
|
581
|
+
| ----------------------------------------------------------- | --------------------------------------- |
|
|
582
|
+
| 📘 **[Video Generation Guide](VIDEO_GENERATION_README.md)** | Complete video generation documentation |
|
|
583
|
+
| 📙 **[Quick Reference](QUICK_REFERENCE.md)** | Fast lookup for common tasks |
|
|
584
|
+
| 📗 **[Architecture Guide](ARCHITECTURE.md)** | Technical architecture details |
|
|
585
|
+
| 📕 **[Contributing Guide](CONTRIBUTING.md)** | How to contribute to the project |
|
|
586
|
+
| 📔 **[Changelog](CHANGELOG.md)** | Version history and updates |
|
|
587
|
+
| 📓 **[Security Policy](SECURITY.md)** | Security best practices |
|
|
588
|
+
|
|
589
|
+
### 🔧 API Reference
|
|
590
|
+
|
|
591
|
+
#### MetaAI Class
|
|
592
|
+
|
|
593
|
+
```python
|
|
594
|
+
class MetaAI:
|
|
595
|
+
def __init__(
|
|
596
|
+
self,
|
|
597
|
+
fb_email: Optional[str] = None,
|
|
598
|
+
fb_password: Optional[str] = None,
|
|
599
|
+
cookies: Optional[dict] = None,
|
|
600
|
+
proxy: Optional[dict] = None
|
|
601
|
+
)
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
**Methods:**
|
|
605
|
+
|
|
606
|
+
- **`prompt(message, stream=False, new_conversation=False)`**
|
|
607
|
+
|
|
608
|
+
- Send a chat message
|
|
609
|
+
- Returns: `dict` with `message`, `sources`, and `media`
|
|
610
|
+
|
|
611
|
+
- **`generate_video(prompt, wait_before_poll=10, max_attempts=30, wait_seconds=5, verbose=True)`**
|
|
612
|
+
- Generate a video from text
|
|
613
|
+
- Returns: `dict` with `success`, `video_urls`, `conversation_id`, `prompt`, `timestamp`
|
|
614
|
+
|
|
615
|
+
#### VideoGenerator Class
|
|
616
|
+
|
|
617
|
+
```python
|
|
618
|
+
from metaai_api import VideoGenerator
|
|
619
|
+
|
|
620
|
+
# Direct video generation
|
|
621
|
+
generator = VideoGenerator(cookies_str="your_cookies_as_string")
|
|
622
|
+
result = generator.generate_video("your prompt here")
|
|
623
|
+
|
|
624
|
+
# One-liner generation
|
|
625
|
+
result = VideoGenerator.quick_generate(
|
|
626
|
+
cookies_str="your_cookies",
|
|
627
|
+
prompt="your prompt"
|
|
628
|
+
)
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
---
|
|
632
|
+
|
|
633
|
+
## 🎯 Use Cases
|
|
634
|
+
|
|
635
|
+
### 1. **Research Assistant**
|
|
636
|
+
|
|
637
|
+
```python
|
|
638
|
+
ai = MetaAI()
|
|
639
|
+
research = ai.prompt("Summarize recent breakthroughs in fusion energy")
|
|
640
|
+
print(research["message"])
|
|
641
|
+
# Get cited sources
|
|
642
|
+
for source in research["sources"]:
|
|
643
|
+
print(f"📌 {source['title']}: {source['link']}")
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
### 2. **Content Creation**
|
|
647
|
+
|
|
648
|
+
```python
|
|
649
|
+
ai = MetaAI(cookies=cookies)
|
|
650
|
+
|
|
651
|
+
# Generate video content
|
|
652
|
+
promo_video = ai.generate_video("Product showcase with smooth camera movements")
|
|
653
|
+
|
|
654
|
+
# Generate images
|
|
655
|
+
thumbnails = ai.prompt("Generate a YouTube thumbnail for a tech review video")
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
### 3. **Educational Tool**
|
|
659
|
+
|
|
660
|
+
```python
|
|
661
|
+
ai = MetaAI()
|
|
662
|
+
|
|
663
|
+
# Explain complex topics
|
|
664
|
+
explanation = ai.prompt("Explain blockchain technology to a 10-year-old")
|
|
665
|
+
|
|
666
|
+
# Get homework help
|
|
667
|
+
solution = ai.prompt("Solve: 2x + 5 = 13, show steps")
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
### 4. **Real-time Information**
|
|
671
|
+
|
|
672
|
+
```python
|
|
673
|
+
ai = MetaAI()
|
|
674
|
+
|
|
675
|
+
# Current events
|
|
676
|
+
news = ai.prompt("What are the top technology news today?")
|
|
677
|
+
|
|
678
|
+
# Sports scores
|
|
679
|
+
scores = ai.prompt("Latest Premier League scores")
|
|
680
|
+
|
|
681
|
+
# Market data
|
|
682
|
+
stocks = ai.prompt("Current S&P 500 index value")
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
---
|
|
686
|
+
|
|
687
|
+
## 🛠️ Advanced Configuration
|
|
688
|
+
|
|
689
|
+
### Environment Variables
|
|
690
|
+
|
|
691
|
+
Store credentials securely:
|
|
692
|
+
|
|
693
|
+
```bash
|
|
694
|
+
# .env file
|
|
695
|
+
META_AI_DATR=your_datr_value
|
|
696
|
+
META_AI_ABRA_SESS=your_abra_sess_value
|
|
697
|
+
META_AI_DPR=1.25
|
|
698
|
+
META_AI_WD=1920x1080
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
Load in Python:
|
|
702
|
+
|
|
703
|
+
```python
|
|
704
|
+
import os
|
|
705
|
+
from dotenv import load_dotenv
|
|
706
|
+
from metaai_api import MetaAI
|
|
707
|
+
|
|
708
|
+
load_dotenv()
|
|
709
|
+
|
|
710
|
+
cookies = {
|
|
711
|
+
"datr": os.getenv("META_AI_DATR"),
|
|
712
|
+
"abra_sess": os.getenv("META_AI_ABRA_SESS"),
|
|
713
|
+
"dpr": os.getenv("META_AI_DPR"),
|
|
714
|
+
"wd": os.getenv("META_AI_WD")
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
ai = MetaAI(cookies=cookies)
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
### Error Handling
|
|
721
|
+
|
|
722
|
+
```python
|
|
723
|
+
from metaai_api import MetaAI
|
|
724
|
+
|
|
725
|
+
ai = MetaAI(cookies=cookies)
|
|
726
|
+
|
|
727
|
+
try:
|
|
728
|
+
result = ai.generate_video("Your prompt")
|
|
729
|
+
|
|
730
|
+
if result["success"]:
|
|
731
|
+
print(f"✅ Video: {result['video_urls'][0]}")
|
|
732
|
+
else:
|
|
733
|
+
print("⏳ Video still processing, try again later")
|
|
734
|
+
|
|
735
|
+
except ValueError as e:
|
|
736
|
+
print(f"❌ Configuration error: {e}")
|
|
737
|
+
except ConnectionError as e:
|
|
738
|
+
print(f"❌ Network error: {e}")
|
|
739
|
+
except Exception as e:
|
|
740
|
+
print(f"❌ Unexpected error: {e}")
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
---
|
|
744
|
+
|
|
745
|
+
## 🌟 Project Structure
|
|
746
|
+
|
|
747
|
+
```
|
|
748
|
+
meta-ai-python/
|
|
749
|
+
│
|
|
750
|
+
├── 📁 src/metaai_api/ # Core package
|
|
751
|
+
│ ├── __init__.py # Package initialization
|
|
752
|
+
│ ├── main.py # MetaAI class
|
|
753
|
+
│ ├── video_generation.py # Video generation
|
|
754
|
+
│ ├── client.py # Client utilities
|
|
755
|
+
│ ├── utils.py # Helper functions
|
|
756
|
+
│ └── exceptions.py # Custom exceptions
|
|
757
|
+
│
|
|
758
|
+
├── 📁 examples/ # Usage examples
|
|
759
|
+
│ ├── simple_example.py # Quick start
|
|
760
|
+
│ ├── video_generation.py # Video examples
|
|
761
|
+
│ └── test_example.py # Testing
|
|
762
|
+
│
|
|
763
|
+
├── 📁 .github/ # GitHub configuration
|
|
764
|
+
│ ├── workflows/ # CI/CD pipelines
|
|
765
|
+
│ └── README.md
|
|
766
|
+
│
|
|
767
|
+
├── 📄 README.md # This file
|
|
768
|
+
├── 📄 VIDEO_GENERATION_README.md
|
|
769
|
+
├── 📄 QUICK_REFERENCE.md
|
|
770
|
+
├── 📄 ARCHITECTURE.md
|
|
771
|
+
├── 📄 CONTRIBUTING.md
|
|
772
|
+
├── 📄 CHANGELOG.md
|
|
773
|
+
├── 📄 SECURITY.md
|
|
774
|
+
├── 📄 LICENSE # MIT License
|
|
775
|
+
├── 📄 setup.py # Package setup
|
|
776
|
+
├── 📄 pyproject.toml # Project metadata
|
|
777
|
+
└── 📄 requirements.txt # Dependencies
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
---
|
|
781
|
+
|
|
782
|
+
## 🤝 Contributing
|
|
783
|
+
|
|
784
|
+
We welcome contributions! Here's how you can help:
|
|
785
|
+
|
|
786
|
+
1. **🐛 Report Bugs** - [Open an issue](https://github.com/mir-ashiq/metaai-api/issues)
|
|
787
|
+
2. **💡 Suggest Features** - Share your ideas
|
|
788
|
+
3. **📝 Improve Docs** - Help us document better
|
|
789
|
+
4. **🔧 Submit PRs** - Fix bugs or add features
|
|
790
|
+
|
|
791
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
|
|
792
|
+
|
|
793
|
+
---
|
|
794
|
+
|
|
795
|
+
## 📜 License
|
|
796
|
+
|
|
797
|
+
This project is licensed under the **MIT License** - see [LICENSE](LICENSE) for details.
|
|
798
|
+
|
|
799
|
+
### ⚖️ Disclaimer
|
|
800
|
+
|
|
801
|
+
This project is an **independent implementation** and is **not officially affiliated** with Meta Platforms, Inc. or any of its affiliates.
|
|
802
|
+
|
|
803
|
+
- ✅ Educational and development purposes
|
|
804
|
+
- ✅ Use responsibly and ethically
|
|
805
|
+
- ✅ Comply with Meta's Terms of Service
|
|
806
|
+
- ✅ Respect usage limits and policies
|
|
807
|
+
|
|
808
|
+
**Llama 3 License:** Visit [llama.com/llama3/license](https://www.llama.com/llama3/license/) for Llama 3 usage terms.
|
|
809
|
+
|
|
810
|
+
---
|
|
811
|
+
|
|
812
|
+
## 🙏 Acknowledgments
|
|
813
|
+
|
|
814
|
+
- **Meta AI** - For providing the AI capabilities
|
|
815
|
+
- **Llama 3** - The powerful language model
|
|
816
|
+
- **Open Source Community** - For inspiration and support
|
|
817
|
+
|
|
818
|
+
---
|
|
819
|
+
|
|
820
|
+
## 📞 Support & Community
|
|
821
|
+
|
|
822
|
+
- 💬 **Questions?** [GitHub Discussions](https://github.com/mir-ashiq/metaai-api/discussions)
|
|
823
|
+
- 🐛 **Bug Reports** [GitHub Issues](https://github.com/mir-ashiq/metaai-api/issues)
|
|
824
|
+
- 📧 **Contact** contact@meta-ai-sdk.dev
|
|
825
|
+
- ⭐ **Star us** on [GitHub](https://github.com/mir-ashiq/metaai-api)
|
|
826
|
+
|
|
827
|
+
---
|
|
828
|
+
|
|
829
|
+
## 🚀 Quick Links
|
|
830
|
+
|
|
831
|
+
<div align="center">
|
|
832
|
+
|
|
833
|
+
| Resource | Link |
|
|
834
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
835
|
+
| 📦 **PyPI Package** | [pypi.org/project/metaai_api](https://pypi.org/project/metaai_api/) |
|
|
836
|
+
| 🐙 **GitHub Repository** | [github.com/mir-ashiq/meta-ai-python](https://github.com/mir-ashiq/metaai-api) |
|
|
837
|
+
| 📖 **Full Documentation** | [Video Guide](VIDEO_GENERATION_README.md) • [Quick Ref](QUICK_REFERENCE.md) |
|
|
838
|
+
| 💬 **Get Help** | [Issues](https://github.com/mir-ashiq/metaai-api/issues) • [Discussions](https://github.com/mir-ashiq/metaai-api/discussions) |
|
|
839
|
+
|
|
840
|
+
---
|
|
841
|
+
|
|
842
|
+
<sub>**Meta AI Python SDK v2.0.0** | Made with ❤️ by [mir-ashiq](https://github.com/mir-ashiq) | MIT License</sub>
|
|
843
|
+
|
|
844
|
+
**⭐ Star this repo if you find it useful!**
|
|
845
|
+
|
|
846
|
+
</div>
|