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.6.tar.gz (4.4 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.6-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mymagicpencil_langchain-1.0.6.tar.gz
  • Upload date:
  • Size: 4.4 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.6.tar.gz
Algorithm Hash digest
SHA256 19d5cff4d824016f510736d32bd7afc61710432ac2b2fce45cd307e7bd613edd
MD5 e37c3a2a372edb5087c960c484ee5393
BLAKE2b-256 a354411317b84d23ad58ff8627e55dd27ebff9eac6650af9722f4001ff7b4141

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mymagicpencil_langchain-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0012533b82c1d2803d8ee63d5cace1c8a486474cce13a1a0749c48b641e78896
MD5 94844896571dc5a36bfe36e4a2c3aafe
BLAKE2b-256 ea1962567e8bbb52db187b09227cd0cc4ca1f8643a5883043ae350d498a8e916

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