# Agent M1

> **Warning**
>
> Please test this agent on your own use-cases. It was tested and measured by only the official benchmarks in the GitHub repository [FlyMyAI/bench_M1](https://github.com/FlyMyAI/bench_M1).

## Overview

FlyMy.AI Media Agent 1 (M1) is a unified multimodal media agent that provides access to dozens of high-performance media models through a single API endpoint. The agent combines open-source innovations with proprietary models to deliver instant media generation capabilities, including real-time image generation, face-preserving editing, and video creation. M1 aims to simplify the integration of modern AI models for developers.

## Key Capabilities

For detailed benchmark results and comparisons with other models, please visit our [benchmark results page](https://github.com/FlyMyAI/bench_M1#flymyai-benchmarks).

### Image Generation
Agent M1 performance in image generation tasks:
- Single object generation: 99%
- Multiple object composition: 97%
- Object counting: 70%
- Color understanding: 86%
- Positional awareness: 51%
- Color attribute handling: 58%

### Face Identity Preservation
Agent M1 performance in face transformations:
- Overall identity preservation: 91.7%
- Emotion transformations: 97.7%
- Age transformation: 91.5%
- Hair style modifications: 89.9%
- Accessory additions: 93%

### World Knowledge Understanding
Agent M1 performance across domains:
- Cultural knowledge: 79.1%
- Temporal understanding: 92.6%
- Spatial reasoning: 87.6%
- Biological concepts: 83.8%
- Physical principles: 91%
- Chemical knowledge: 84.1%

## Usage

### Basic Usage

```python
import requests
import json

# Initialize the API client
API_URL = "https://api.flymyai.com/v1/agent-m1"
headers = {
    "Authorization": f"Bearer {YOUR_API_KEY}",
    "Content-Type": "application/json"
}

# Generate an image
def generate_image(prompt):
    payload = {
        "prompt": prompt,
        "num_images": 1
    }
    response = requests.post(
        f"{API_URL}/generate",
        headers=headers,
        json=payload
    )
    return response.json()

# Transform a face
def transform_face(image_path, transformation):
    with open(image_path, 'rb') as image_file:
        files = {'image': image_file}
        payload = {
            "transformation": transformation
        }
        response = requests.post(
            f"{API_URL}/transform",
            headers={"Authorization": f"Bearer {YOUR_API_KEY}"},
            files=files,
            data=payload
        )
    return response.json()

# Get world knowledge response
def ask_question(question):
    payload = {
        "question": question
    }
    response = requests.post(
        f"{API_URL}/ask",
        headers=headers,
        json=payload
    )
    return response.json()

# Example usage
image_response = generate_image("A serene landscape with mountains and a lake")
face_response = transform_face("path_to_image.jpg", "Add a smile")
knowledge_response = ask_question("What causes the seasons to change?")
```

### Advanced Usage

```python
# Complex image generation with multiple objects
advanced_payload = {
    "prompt": "A red car parked next to a blue house with a white picket fence",
    "num_images": 1,
    "style": "photorealistic",
    "negative_prompt": "blurry, distorted",
    "parameters": {
        "guidance_scale": 7.5,
        "num_inference_steps": 50
    }
}
response = requests.post(
    f"{API_URL}/generate",
    headers=headers,
    json=advanced_payload
)

# Face transformation with specific attributes
face_payload = {
    "transformation": "Make the person look 20 years older",
    "preserve_identity": True,
    "style": "natural",
    "parameters": {
        "strength": 0.8,
        "preserve_expression": True
    }
}
with open("path_to_image.jpg", 'rb') as image_file:
    files = {'image': image_file}
    response = requests.post(
        f"{API_URL}/transform",
        headers={"Authorization": f"Bearer {YOUR_API_KEY}"},
        files=files,
        data=face_payload
    )
```

## Best Practices

1. **Prompt Engineering**
   - Be specific and detailed in your prompts
   - Use clear descriptions of objects and their relationships
   - Specify colors and positions when important

2. **Face Transformations**
   - Provide clear transformation instructions
   - Use natural language descriptions
   - Consider using the preserve_identity parameter for critical applications

3. **World Knowledge Queries**
   - Frame questions clearly and specifically
   - Provide context when necessary
   - Use follow-up questions for complex topics

## Limitations

- Performance may vary based on specific use cases
- Complex scenes with many objects may require multiple attempts
- Face transformations work best with clear, front-facing images
- World knowledge responses are based on training data cutoff

## Python SDK Usage

### Using Synchronous Client

```python
from flymyai import m1_client

client = m1_client(apikey="fly-secret-key")
result = client.generate("An Iron Man")
print(result.data.text, result.data.file_url)
```

FlymyAI M1 client also stores request history for later generation context:

```python
from flymyai import m1_client

client = m1_client(apikey="fly-secret-key")

result = client.generate("An Iron Man")
print(result.data.text, result.data.file_url)

result = client.generate("Add him Captain America's shield")
print(result.data.text, result.data.file_url)
```

#### Passing image

```python
from pathlib import Path
from flymyai import m1_client

client = m1_client(apikey="fly-secret-key")
result = client.generate("An Iron Man", image=Path("./image.png"))
print(result.data.text, result.data.file_url)
```

### Using Asynchronous Client

```python
import asyncio
from flymyai import async_m1_client


async def main():
    client = async_m1_client(apikey="fly-secret-key")
    result = await client.generate("An Iron Man")
    print(result.data.text, result.data.file_url)


asyncio.run(main())
```

#### Passing image

```python
import asyncio
from pathlib import Path
from flymyai import async_m1_client


async def main():
    client = async_m1_client(apikey="fly-secret-key")
    result = await client.generate("An Iron Man", image=Path("./image.png"))
    print(result.data.text, result.data.file_url)


asyncio.run(main())
```

## Support

For technical support or to report issues, please visit our [GitHub repository](https://github.com/FlyMyAI/bench_M1) or contact our support team.
