Skip to content

HansonJames/langchain_universal_tools

Folders and files

NameName
Last commit message
Last commit date
Jan 4, 2025
Jan 2, 2025
Jan 1, 2025
Dec 20, 2024
Jan 4, 2025
Jan 4, 2025
Jan 2, 2025
Dec 20, 2024
Dec 20, 2024
Jan 4, 2025
Jan 2, 2025
Jan 2, 2025
Jan 4, 2025
Jan 2, 2025

Repository files navigation

Universal LangChain Tools

A collection of universal tools based on LangChain for various tasks.

中文文档

Features

1. Universal Email Tool

  • Send emails with various formats (plain text, HTML)
  • Support attachments
  • Read and summarize emails
  • Multiple email service providers support (QQ, 163, Aliyun)

2. Universal Mind Map Tool

  • Generate mind maps from any topic automatically
  • Support multiple mind map formats (FreeMind, OPML, XMind, MindManager)
  • Intelligent content analysis and organization
  • Easy to use with simple API

3. Universal PPT Tool

  • Generate professional presentations automatically
  • High-quality images generated by DALL-E 3
  • Real-time market data integration
  • Professional content organization
  • Support custom pages and themes

Installation

git clone https://github.com/HansonJames/langchain_universal_tools.git
cd langchain_universal_tools
pip install -r requirements.txt

Configuration

Create a .env file with the following content:

# OpenAI and SerpAPI settings
OPENAI_API_KEY=your_openai_api_key
SERPAPI_API_KEY=your_serpapi_api_key

# Email service settings
EMAIL_USE=QQ  # QQ, 163, or ALIYUN
EMAIL_CONFIGS={
    "QQ": {
        "smtp_host": "smtp.qq.com",
        "smtp_port": 465,
        "imap_host": "imap.qq.com",
        "username": "your_qq_email",
        "password": "your_email_password"
    }
}

Usage

Email Tool

from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
from universal_email_tool import UniversalEmailTool, UniversalEmailToolReading

# Initialize tools
tools = [UniversalEmailTool(), UniversalEmailToolReading()]

# Initialize the language model
llm = ChatOpenAI(
    temperature=0,
    model_name="gpt-4o"
)

# Create the agent
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# Send email
result = agent_executor.invoke({
    "input": "Send an email to example@qq.com with subject 'Test' and content 'Hello'"
})

# Read emails
result = agent_executor.invoke({
    "input": "Read and summarize my recent 3 emails"
})

Mind Map Tool

from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
from xmind_tool import UniversalMindMapTool, UniversalMindMapToolReading

# Initialize tools
tools = [UniversalMindMapTool(), UniversalMindMapToolReading()]

# Initialize the language model
llm = ChatOpenAI(
    temperature=0,
    model_name="gpt-4o"
)

# Create the agent
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# Generate mind map
topic = "Programming Languages Comparison"
result = agent_executor.invoke({
    "input": f"Please generate a mind map about '{topic}'."
})

PPT Tool

from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain.tools import StructuredTool
from universal_ppt_tool import PPTGenerator

# Initialize tools
ppt_generator = PPTGenerator()
tools = [
    StructuredTool.from_function(
        func=ppt_generator.generate_with_logging,
        name="generate_ppt",
        description="Generate PPT tool",
    )
]

# Initialize the language model
llm = ChatOpenAI(
    model_name="gpt-4o",
    temperature=0
)

# Create the agent
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# Generate PPT
topic = "2025 Business Opportunities"
result = agent_executor.invoke({
    "input": f"""Please generate a {topic} PPT with 3 pages. Requirements:
    1. Comprehensive and forward-looking content
    2. Include latest market data and trends
    3. Focus on future business directions
    4. Professional and beautiful images
    """
})

Output Formats

Email Tool

  • Plain text emails
  • HTML formatted emails
  • Support for attachments
  • Email reading and summarization

Mind Map Tool

  • FreeMind (.mm)
  • OPML (.opml)
  • XMind (.xmind)

All mind map files are saved in the output/mindmap directory.

PPT Tool

  • PowerPoint (.pptx)
  • Professional layouts
  • DALL-E generated images
  • Data-driven content

All PPT files are saved in the output/ppt directory.

Requirements

  • Python 3.8+
  • OpenAI API key
  • SerpAPI key (for mind map generation)
  • Email service account
  • Required Python packages (see requirements.txt)

License

Apache License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

LangChain Tools Collection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published