LangChain tool for generating My Magic Pencil live visual lessons
Project description
My Magic Pencil – LangChain Integration
LangChain tool for generating My Magic Pencil live visual lessons (drawing + voice) from text prompts.
Installation
pip install mymagicpencil-langchain
Environment Variables
| Variable | Description | Required |
|---|---|---|
MYMAGICPENCIL_API_KEY |
Your My Magic Pencil API key | Yes |
Quick Start
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:
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
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 toMYMAGICPENCIL_API_KEYenv 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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mymagicpencil_langchain-1.0.1.tar.gz.
File metadata
- Download URL: mymagicpencil_langchain-1.0.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1a46d4c284205e4aa9f807c16da629e7fad9d6aaeb6902d273569f14f279cc3
|
|
| MD5 |
d4088ef1c61104a9ed6391e151c45b1c
|
|
| BLAKE2b-256 |
4cfd43dcff315dfa6091736fcb50d58770b1cd57d6969115f35a52fd9ca16a59
|
File details
Details for the file mymagicpencil_langchain-1.0.1-py3-none-any.whl.
File metadata
- Download URL: mymagicpencil_langchain-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edb994e136196a03e472424d6d814abb704bc143cef15b9aceaa299b42ddbd66
|
|
| MD5 |
658044be1d9ce9604981d1d65a7f253c
|
|
| BLAKE2b-256 |
09b875d69adc5d408f81817b95318a1f2701d715d5fda99284f640ef3347de6e
|