Skip to main content

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

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

mymagicpencil_langchain-1.0.3.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mymagicpencil_langchain-1.0.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file mymagicpencil_langchain-1.0.3.tar.gz.

File metadata

  • Download URL: mymagicpencil_langchain-1.0.3.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

Hashes for mymagicpencil_langchain-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0c0fae4b4c83185d9de4ef1a5667c1b963e66eb0948a48f659c480cbe0f1ee70
MD5 9da90a265539ddbf2fd361123f3aaf83
BLAKE2b-256 e3b6d371bb0c12de1752641be3f7bd0cb0cf5f416620a3374250d84d7a13eb0a

See more details on using hashes here.

File details

Details for the file mymagicpencil_langchain-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mymagicpencil_langchain-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 95fb0e3d1f044f5a7fdd5c79d2dc1f4d4a755e3e538c44b5f1938e91e19196de
MD5 477aa59fe30f6938242e8a9004b5a05d
BLAKE2b-256 fccd97abf71e1d32d30e4e811346d7c007849e47d4f4a375fb8a0020487d582a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page