Metadata-Version: 2.4
Name: mymagicpencil-langchain
Version: 1.0.1
Summary: LangChain tool for generating My Magic Pencil live visual lessons
Home-page: https://github.com/mymagicpencil/langchain-python
Author: My Magic Pencil
Author-email: dev@mymagicpencil.com
License: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: langchain-core>=0.1.0
Requires-Dist: requests>=2.25.0
Requires-Dist: pydantic>=2.0.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# My Magic Pencil – LangChain Integration

LangChain tool for generating **My Magic Pencil** live visual lessons (drawing + voice) from text prompts.

## Installation

```bash
pip install mymagicpencil-langchain
```

## Environment Variables

| Variable                | Description                    | Required |
| ----------------------- | ------------------------------ | -------- |
| `MYMAGICPENCIL_API_KEY` | Your My Magic Pencil API key   | Yes      |

## Quick Start

```python
import os
from mymagicpencil_langchain import GenerateVisualLessonTool

os.environ["MYMAGICPENCIL_API_KEY"] = "your-api-key"

tool = GenerateVisualLessonTool()
result = tool.run("Explain how photosynthesis works")
print(result)
```

Or pass the API key directly:

```python
tool = GenerateVisualLessonTool(api_key="your-api-key")
result = tool.run("Explain Newton's laws of motion")
print(result)
```

## Parameters

The `GenerateVisualLessonTool` accepts the following parameters when invoked:

| Parameter        | Type   | Default     | Description                                      |
| ---------------- | ------ | ----------- | ------------------------------------------------ |
| `prompt`         | `str`  | *(required)*| The topic or concept to explain visually          |
| `language`       | `str`  | `"en"`      | Language code (e.g., `"en"`, `"es"`, `"fr"`)     |
| `theme`          | `str`  | `"dark"`    | Visual theme: `"dark"` or `"light"`              |
| `voice_enabled`  | `bool` | `True`      | Whether to include TTS voice output              |
| `voice_tone`     | `int`  | `50`        | Voice tone from 0 to 100                         |
| `output_type`    | `str`  | `"embed"`   | Output type: `"embed"` or `"mp4"`                |
| `drawing_style`  | `str`  | `"default"` | Visual drawing style                             |
| `thinking_level` | `str`  | `"low"`     | Level of AI reasoning exposed                    |
| `age_group`      | `str`  | `"adult"`   | Target age group                                 |

## Usage with LangChain Agents

```python
import os
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from mymagicpencil_langchain import GenerateVisualLessonTool

os.environ["MYMAGICPENCIL_API_KEY"] = "your-mmp-api-key"
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"

llm = ChatOpenAI(model="gpt-4", temperature=0)
tools = [GenerateVisualLessonTool()]

agent = initialize_agent(
    tools,
    llm,
    agent=AgentType.OPENAI_FUNCTIONS,
    verbose=True,
)

response = agent.run("Create a visual lesson explaining how black holes form")
print(response)
```

## API Reference

### `GenerateVisualLessonTool`

- **Class:** `mymagicpencil_langchain.GenerateVisualLessonTool`
- **Inherits:** `langchain_core.tools.BaseTool`
- **Constructor Args:**
  - `api_key` *(Optional[str])*: API key. Falls back to `MYMAGICPENCIL_API_KEY` env var.
- **Methods:**
  - `_run(prompt, ...)` → `str`: Calls the My Magic Pencil API and returns a result string with the embed URL and session ID.

### `GenerateVisualLessonInput`

- **Class:** `mymagicpencil_langchain.tool.GenerateVisualLessonInput`
- **Inherits:** `pydantic.BaseModel`
- **Purpose:** Pydantic schema used for LangChain argument validation.

## License

MIT
