Skip to main content

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

Metadata

Release files for mymagicpencil-langchain 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mymagicpencil-langchain 1.0.6
File Size Uploaded
mymagicpencil_langchain-1.0.6.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mymagicpencil-langchain 1.0.6
File Interpreter ABI Platform
mymagicpencil_langchain-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / mymagicpencil_langchain-1.0.6.tar.gz

Download URL mymagicpencil_langchain-1.0.6.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
19d5cff4d824016f510736d32bd7afc61710432ac2b2fce45cd307e7bd613edd
BLAKE2b-256 checksum
How to use checksums
a354411317b84d23ad58ff8627e55dd27ebff9eac6650af9722f4001ff7b4141
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.5

Release files / mymagicpencil_langchain-1.0.6-py3-none-any.whl

Download URL mymagicpencil_langchain-1.0.6-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0012533b82c1d2803d8ee63d5cace1c8a486474cce13a1a0749c48b641e78896
BLAKE2b-256 checksum
How to use checksums
ea1962567e8bbb52db187b09227cd0cc4ca1f8643a5883043ae350d498a8e916
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.5

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page