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.2.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.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mymagicpencil_langchain-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 d414d2e7e348ac6ea54c288c78f71c72ffbc2924bc5b7e4823c38d47a4345ab7
MD5 8ee3c023d8d93b424fb77540e3a4dc7b
BLAKE2b-256 73ee2ca32a80256d126d2f5a219f766fc719349f0e418f64deaf35e468344e22

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mymagicpencil_langchain-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 788fb9d1f8eaf9e7bf74b45be36a0138ec542ae671794ad1d1848a7d52af44ec
MD5 7612649891cf089f943fdd28b17f5fb8
BLAKE2b-256 074eeaefa90aef0687b681a02eb1b0fb04ee938fd9e2e77a4bce33c1a73bdf79

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