langchain-deepai


Namelangchain-deepai JSON
Version 0.0.6 PyPI version JSON
download
home_pageNone
SummaryLangChain integration for DeepAI API with chat, images, and speech capabilities
upload_time2025-07-28 15:24:30
maintainerNone
docs_urlNone
authorAIMLStudent
requires_python>=3.8
licenseMIT
keywords langchain deepai ai chat image-generation text-to-speech speech-to-text machine-learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LangChain DeepAI Integration

[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A comprehensive LangChain integration for the DeepAI API, providing seamless access to chat completions, image generation, text-to-speech, and speech-to-text capabilities.

## Features

- **🗨️ Chat Completions**: Multiple specialized models for different use cases
- **🎨 Image Generation**: Text-to-image with various artistic styles
- **🔊 Text-to-Speech**: High-quality speech synthesis
- **🎤 Speech-to-Text**: Accurate audio transcription
- **⚡ LangChain Compatible**: Full integration with LangChain ecosystem
- **🔄 Async Support**: Both sync and async operations
- **📚 Well Documented**: Comprehensive docstrings and examples

## Installation

```bash
pip install langchain-deepai
```

For image processing capabilities:
```bash
pip install langchain-deepai[image]
```

For development:
```bash
pip install langchain-deepai[dev]
```

## Quick Start

### 1. Set up your API key

```bash
export DEEPAI_API_KEY="your-deepai-api-key"
```

Or pass it directly:

```python
from langchain_deepai import ChatDeepAI

chat = ChatDeepAI(api_key="your-deepai-api-key")
```

### 2. Basic Chat Example

```python
from langchain_deepai import ChatDeepAI
from langchain_core.messages import HumanMessage

# Initialize chat model
chat = ChatDeepAI(
    model="standard",
    chat_style="chatgpt-alternative"
)

# Send a message
messages = [HumanMessage(content="Hello! How are you today?")]
response = chat.invoke(messages)
print(response.content)
```

### 3. Specialized Models

```python
from langchain_deepai import DeepAIMath, DeepAICode

# Math-focused model
math_chat = DeepAIMath()
response = math_chat.invoke([HumanMessage(content="Solve: 2x + 5 = 15")])

# Code-focused model  
code_chat = DeepAICode()
response = code_chat.invoke([HumanMessage(content="Write a Python sorting function")])
```

### 4. Image Generation

```python
from langchain_deepai import ImageDeepAI, generate_image

# Using the class
image_gen = ImageDeepAI()
result = image_gen.generate(
    prompt="A beautiful sunset over mountains",
    model="text2img",
    width=512,
    height=512
)

# Save the image
with open("sunset.jpg", "wb") as f:
    f.write(result["image_data"])

# Using the convenience function
result = generate_image(
    prompt="A cyberpunk cityscape at night",
    model="cyberpunk-generator"
)
```

### 5. Text-to-Speech

```python
from langchain_deepai import TextToSpeechDeepAI

tts = TextToSpeechDeepAI()
result = tts.synthesize(
    text="Hello, this is a test of text-to-speech synthesis.",
    voice="default"
)

# Save audio file
with open("speech.wav", "wb") as f:
    f.write(result["audio_data"])
```

### 6. Speech-to-Text

```python
from langchain_deepai import SpeechToTextDeepAI

stt = SpeechToTextDeepAI()
result = stt.transcribe("audio_file.wav")
print(result["text"])
```

## Available Models and Styles

### Chat Models

- **standard**: General purpose conversational AI
- **math**: Mathematics and problem-solving specialized
- **online**: Web-aware model with current information
- **code**: Programming and development focused

### Chat Styles

- **chatgpt-alternative**: Default conversational style
- **ai-code**: Programming focused
- **mathematics**: Mathematical reasoning
- **professional**: Business communication
- **creative**: Creative and imaginative
- **casual**: Relaxed and informal
- **goku**: Enthusiastic character style
- **gojo_9**: Confident character style

### Image Models

- **text2img**: Standard text-to-image generation
- **fantasy-world-generator**: Fantasy themed
- **cyberpunk-generator**: Cyberpunk aesthetic
- **renaissance-painting-generator**: Renaissance art style
- **abstract-painting-generator**: Abstract art
- **impressionism-painting-generator**: Impressionist style

## Advanced Usage

### Custom Chat Styles

```python
from langchain_deepai import ChatDeepAI

# Professional business communication
business_chat = ChatDeepAI(
    model="standard",
    chat_style="professional"
)

# Creative writing assistant
creative_chat = ChatDeepAI(
    model="standard", 
    chat_style="creative"
)
```

### Session Management

```python
chat = ChatDeepAI()
chat.set_session_id("user-123")

# All messages in this session will maintain context
response1 = chat.invoke([HumanMessage(content="My name is Alice")])
response2 = chat.invoke([HumanMessage(content="What's my name?")])
```

### Error Handling

```python
from langchain_deepai import ChatDeepAI
import logging

# Enable logging
logging.basicConfig(level=logging.INFO)

try:
    chat = ChatDeepAI(api_key="invalid-key")
    response = chat.invoke([HumanMessage(content="Hello")])
except Exception as e:
    print(f"Error: {e}")
```

### Batch Processing

```python
from langchain_deepai import ImageDeepAI

image_gen = ImageDeepAI()

prompts = [
    "A serene lake at sunrise",
    "A bustling city street at night", 
    "A peaceful forest in autumn"
]

results = image_gen.generate_multiple(prompts, model="text2img")
```

## Integration with LangChain

### Chains

```python
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain_deepai import ChatDeepAI

# Create a chain
prompt = PromptTemplate(
    input_variables=["topic"],
    template="Write a short story about {topic}"
)

chain = LLMChain(
    llm=ChatDeepAI(chat_style="creative"),
    prompt=prompt
)

result = chain.run(topic="time travel")
```

### Agents

```python
from langchain.agents import initialize_agent, Tool
from langchain_deepai import ChatDeepAI, ImageDeepAI

def generate_image_tool(prompt: str) -> str:
    image_gen = ImageDeepAI()
    result = image_gen.generate(prompt)
    return f"Image generated and saved. URL: {result['image_url']}"

tools = [
    Tool(
        name="ImageGenerator",
        func=generate_image_tool,
        description="Generate images from text descriptions"
    )
]

agent = initialize_agent(
    tools=tools,
    llm=ChatDeepAI(),
    agent="zero-shot-react-description"
)
```

## API Reference

### ChatDeepAI

Main chat model class with full LangChain compatibility.

**Parameters:**
- `model_name`: Model to use ("standard", "math", "online", "code")
- `chat_style`: Conversation style 
- `api_key`: DeepAI API key
- `max_tokens`: Maximum tokens to generate
- `temperature`: Response randomness
- `session_id`: Session identifier for context

### Specialized Models

- **DeepAIMath**: Mathematics-focused chat model
- **DeepAICode**: Programming-focused chat model  
- **DeepAIOnline**: Web-aware chat model
- **DeepAIProfessional**: Business communication model
- **DeepAICreative**: Creative writing model
- **DeepAICasual**: Casual conversation model

### ImageDeepAI

Image generation with multiple artistic styles.

**Methods:**
- `generate()`: Generate single image
- `generate_multiple()`: Generate multiple images
- `generate_and_save()`: Generate and save to file

### TextToSpeechDeepAI

High-quality text-to-speech synthesis.

**Methods:**
- `synthesize()`: Convert text to speech
- `synthesize_and_save()`: Convert and save audio
- `synthesize_multiple()`: Batch TTS processing

### SpeechToTextDeepAI

Accurate speech-to-text transcription.

**Methods:**
- `transcribe()`: Transcribe audio to text
- `transcribe_multiple()`: Batch STT processing

## Contributing

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

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Support

For support and questions:
- Check the [documentation](https://langchain-deepai.readthedocs.io)
- Open an [issue](https://github.com/your-org/langchain-deepai/issues)
- DeepAI API documentation: [https://deepai.org/docs](https://deepai.org/docs)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "langchain-deepai",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "langchain, deepai, ai, chat, image-generation, text-to-speech, speech-to-text, machine-learning",
    "author": "AIMLStudent",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/42/c6/2de747661511b70166bc44002b1ee0bbb7f5db680c3d223a5c3c8d00fbce/langchain_deepai-0.0.6.tar.gz",
    "platform": null,
    "description": "# LangChain DeepAI Integration\r\n\r\n[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n\r\nA comprehensive LangChain integration for the DeepAI API, providing seamless access to chat completions, image generation, text-to-speech, and speech-to-text capabilities.\r\n\r\n## Features\r\n\r\n- **\ud83d\udde8\ufe0f Chat Completions**: Multiple specialized models for different use cases\r\n- **\ud83c\udfa8 Image Generation**: Text-to-image with various artistic styles\r\n- **\ud83d\udd0a Text-to-Speech**: High-quality speech synthesis\r\n- **\ud83c\udfa4 Speech-to-Text**: Accurate audio transcription\r\n- **\u26a1 LangChain Compatible**: Full integration with LangChain ecosystem\r\n- **\ud83d\udd04 Async Support**: Both sync and async operations\r\n- **\ud83d\udcda Well Documented**: Comprehensive docstrings and examples\r\n\r\n## Installation\r\n\r\n```bash\r\npip install langchain-deepai\r\n```\r\n\r\nFor image processing capabilities:\r\n```bash\r\npip install langchain-deepai[image]\r\n```\r\n\r\nFor development:\r\n```bash\r\npip install langchain-deepai[dev]\r\n```\r\n\r\n## Quick Start\r\n\r\n### 1. Set up your API key\r\n\r\n```bash\r\nexport DEEPAI_API_KEY=\"your-deepai-api-key\"\r\n```\r\n\r\nOr pass it directly:\r\n\r\n```python\r\nfrom langchain_deepai import ChatDeepAI\r\n\r\nchat = ChatDeepAI(api_key=\"your-deepai-api-key\")\r\n```\r\n\r\n### 2. Basic Chat Example\r\n\r\n```python\r\nfrom langchain_deepai import ChatDeepAI\r\nfrom langchain_core.messages import HumanMessage\r\n\r\n# Initialize chat model\r\nchat = ChatDeepAI(\r\n    model=\"standard\",\r\n    chat_style=\"chatgpt-alternative\"\r\n)\r\n\r\n# Send a message\r\nmessages = [HumanMessage(content=\"Hello! How are you today?\")]\r\nresponse = chat.invoke(messages)\r\nprint(response.content)\r\n```\r\n\r\n### 3. Specialized Models\r\n\r\n```python\r\nfrom langchain_deepai import DeepAIMath, DeepAICode\r\n\r\n# Math-focused model\r\nmath_chat = DeepAIMath()\r\nresponse = math_chat.invoke([HumanMessage(content=\"Solve: 2x + 5 = 15\")])\r\n\r\n# Code-focused model  \r\ncode_chat = DeepAICode()\r\nresponse = code_chat.invoke([HumanMessage(content=\"Write a Python sorting function\")])\r\n```\r\n\r\n### 4. Image Generation\r\n\r\n```python\r\nfrom langchain_deepai import ImageDeepAI, generate_image\r\n\r\n# Using the class\r\nimage_gen = ImageDeepAI()\r\nresult = image_gen.generate(\r\n    prompt=\"A beautiful sunset over mountains\",\r\n    model=\"text2img\",\r\n    width=512,\r\n    height=512\r\n)\r\n\r\n# Save the image\r\nwith open(\"sunset.jpg\", \"wb\") as f:\r\n    f.write(result[\"image_data\"])\r\n\r\n# Using the convenience function\r\nresult = generate_image(\r\n    prompt=\"A cyberpunk cityscape at night\",\r\n    model=\"cyberpunk-generator\"\r\n)\r\n```\r\n\r\n### 5. Text-to-Speech\r\n\r\n```python\r\nfrom langchain_deepai import TextToSpeechDeepAI\r\n\r\ntts = TextToSpeechDeepAI()\r\nresult = tts.synthesize(\r\n    text=\"Hello, this is a test of text-to-speech synthesis.\",\r\n    voice=\"default\"\r\n)\r\n\r\n# Save audio file\r\nwith open(\"speech.wav\", \"wb\") as f:\r\n    f.write(result[\"audio_data\"])\r\n```\r\n\r\n### 6. Speech-to-Text\r\n\r\n```python\r\nfrom langchain_deepai import SpeechToTextDeepAI\r\n\r\nstt = SpeechToTextDeepAI()\r\nresult = stt.transcribe(\"audio_file.wav\")\r\nprint(result[\"text\"])\r\n```\r\n\r\n## Available Models and Styles\r\n\r\n### Chat Models\r\n\r\n- **standard**: General purpose conversational AI\r\n- **math**: Mathematics and problem-solving specialized\r\n- **online**: Web-aware model with current information\r\n- **code**: Programming and development focused\r\n\r\n### Chat Styles\r\n\r\n- **chatgpt-alternative**: Default conversational style\r\n- **ai-code**: Programming focused\r\n- **mathematics**: Mathematical reasoning\r\n- **professional**: Business communication\r\n- **creative**: Creative and imaginative\r\n- **casual**: Relaxed and informal\r\n- **goku**: Enthusiastic character style\r\n- **gojo_9**: Confident character style\r\n\r\n### Image Models\r\n\r\n- **text2img**: Standard text-to-image generation\r\n- **fantasy-world-generator**: Fantasy themed\r\n- **cyberpunk-generator**: Cyberpunk aesthetic\r\n- **renaissance-painting-generator**: Renaissance art style\r\n- **abstract-painting-generator**: Abstract art\r\n- **impressionism-painting-generator**: Impressionist style\r\n\r\n## Advanced Usage\r\n\r\n### Custom Chat Styles\r\n\r\n```python\r\nfrom langchain_deepai import ChatDeepAI\r\n\r\n# Professional business communication\r\nbusiness_chat = ChatDeepAI(\r\n    model=\"standard\",\r\n    chat_style=\"professional\"\r\n)\r\n\r\n# Creative writing assistant\r\ncreative_chat = ChatDeepAI(\r\n    model=\"standard\", \r\n    chat_style=\"creative\"\r\n)\r\n```\r\n\r\n### Session Management\r\n\r\n```python\r\nchat = ChatDeepAI()\r\nchat.set_session_id(\"user-123\")\r\n\r\n# All messages in this session will maintain context\r\nresponse1 = chat.invoke([HumanMessage(content=\"My name is Alice\")])\r\nresponse2 = chat.invoke([HumanMessage(content=\"What's my name?\")])\r\n```\r\n\r\n### Error Handling\r\n\r\n```python\r\nfrom langchain_deepai import ChatDeepAI\r\nimport logging\r\n\r\n# Enable logging\r\nlogging.basicConfig(level=logging.INFO)\r\n\r\ntry:\r\n    chat = ChatDeepAI(api_key=\"invalid-key\")\r\n    response = chat.invoke([HumanMessage(content=\"Hello\")])\r\nexcept Exception as e:\r\n    print(f\"Error: {e}\")\r\n```\r\n\r\n### Batch Processing\r\n\r\n```python\r\nfrom langchain_deepai import ImageDeepAI\r\n\r\nimage_gen = ImageDeepAI()\r\n\r\nprompts = [\r\n    \"A serene lake at sunrise\",\r\n    \"A bustling city street at night\", \r\n    \"A peaceful forest in autumn\"\r\n]\r\n\r\nresults = image_gen.generate_multiple(prompts, model=\"text2img\")\r\n```\r\n\r\n## Integration with LangChain\r\n\r\n### Chains\r\n\r\n```python\r\nfrom langchain.chains import LLMChain\r\nfrom langchain.prompts import PromptTemplate\r\nfrom langchain_deepai import ChatDeepAI\r\n\r\n# Create a chain\r\nprompt = PromptTemplate(\r\n    input_variables=[\"topic\"],\r\n    template=\"Write a short story about {topic}\"\r\n)\r\n\r\nchain = LLMChain(\r\n    llm=ChatDeepAI(chat_style=\"creative\"),\r\n    prompt=prompt\r\n)\r\n\r\nresult = chain.run(topic=\"time travel\")\r\n```\r\n\r\n### Agents\r\n\r\n```python\r\nfrom langchain.agents import initialize_agent, Tool\r\nfrom langchain_deepai import ChatDeepAI, ImageDeepAI\r\n\r\ndef generate_image_tool(prompt: str) -> str:\r\n    image_gen = ImageDeepAI()\r\n    result = image_gen.generate(prompt)\r\n    return f\"Image generated and saved. URL: {result['image_url']}\"\r\n\r\ntools = [\r\n    Tool(\r\n        name=\"ImageGenerator\",\r\n        func=generate_image_tool,\r\n        description=\"Generate images from text descriptions\"\r\n    )\r\n]\r\n\r\nagent = initialize_agent(\r\n    tools=tools,\r\n    llm=ChatDeepAI(),\r\n    agent=\"zero-shot-react-description\"\r\n)\r\n```\r\n\r\n## API Reference\r\n\r\n### ChatDeepAI\r\n\r\nMain chat model class with full LangChain compatibility.\r\n\r\n**Parameters:**\r\n- `model_name`: Model to use (\"standard\", \"math\", \"online\", \"code\")\r\n- `chat_style`: Conversation style \r\n- `api_key`: DeepAI API key\r\n- `max_tokens`: Maximum tokens to generate\r\n- `temperature`: Response randomness\r\n- `session_id`: Session identifier for context\r\n\r\n### Specialized Models\r\n\r\n- **DeepAIMath**: Mathematics-focused chat model\r\n- **DeepAICode**: Programming-focused chat model  \r\n- **DeepAIOnline**: Web-aware chat model\r\n- **DeepAIProfessional**: Business communication model\r\n- **DeepAICreative**: Creative writing model\r\n- **DeepAICasual**: Casual conversation model\r\n\r\n### ImageDeepAI\r\n\r\nImage generation with multiple artistic styles.\r\n\r\n**Methods:**\r\n- `generate()`: Generate single image\r\n- `generate_multiple()`: Generate multiple images\r\n- `generate_and_save()`: Generate and save to file\r\n\r\n### TextToSpeechDeepAI\r\n\r\nHigh-quality text-to-speech synthesis.\r\n\r\n**Methods:**\r\n- `synthesize()`: Convert text to speech\r\n- `synthesize_and_save()`: Convert and save audio\r\n- `synthesize_multiple()`: Batch TTS processing\r\n\r\n### SpeechToTextDeepAI\r\n\r\nAccurate speech-to-text transcription.\r\n\r\n**Methods:**\r\n- `transcribe()`: Transcribe audio to text\r\n- `transcribe_multiple()`: Batch STT processing\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a Pull Request.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n\r\n## Support\r\n\r\nFor support and questions:\r\n- Check the [documentation](https://langchain-deepai.readthedocs.io)\r\n- Open an [issue](https://github.com/your-org/langchain-deepai/issues)\r\n- DeepAI API documentation: [https://deepai.org/docs](https://deepai.org/docs)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "LangChain integration for DeepAI API with chat, images, and speech capabilities",
    "version": "0.0.6",
    "project_urls": {
        "Bug Tracker": "https://github.com/your-org/langchain-deepai/issues",
        "Documentation": "https://langchain-deepai.readthedocs.io",
        "Homepage": "https://github.com/your-org/langchain-deepai",
        "Repository": "https://github.com/your-org/langchain-deepai"
    },
    "split_keywords": [
        "langchain",
        " deepai",
        " ai",
        " chat",
        " image-generation",
        " text-to-speech",
        " speech-to-text",
        " machine-learning"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "80f73ae45bb490ca1a6d03c74a25296260103cbd63c51f848efc6fe42bde90a9",
                "md5": "e0945c6173c28a59871a38a9732e8fbb",
                "sha256": "ca3c44671425888a88fc93f23b8230b3659843b64607acd3b49795372ddf2ec8"
            },
            "downloads": -1,
            "filename": "langchain_deepai-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e0945c6173c28a59871a38a9732e8fbb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 36023,
            "upload_time": "2025-07-28T15:24:29",
            "upload_time_iso_8601": "2025-07-28T15:24:29.066567Z",
            "url": "https://files.pythonhosted.org/packages/80/f7/3ae45bb490ca1a6d03c74a25296260103cbd63c51f848efc6fe42bde90a9/langchain_deepai-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "42c62de747661511b70166bc44002b1ee0bbb7f5db680c3d223a5c3c8d00fbce",
                "md5": "1b47df0fd22a5d0b11c19d8683bca3cb",
                "sha256": "b7f1ae61efc99b30e298ced124e76bf93c89b5185916c328a2a29fd05ac72522"
            },
            "downloads": -1,
            "filename": "langchain_deepai-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "1b47df0fd22a5d0b11c19d8683bca3cb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 35736,
            "upload_time": "2025-07-28T15:24:30",
            "upload_time_iso_8601": "2025-07-28T15:24:30.191290Z",
            "url": "https://files.pythonhosted.org/packages/42/c6/2de747661511b70166bc44002b1ee0bbb7f5db680c3d223a5c3c8d00fbce/langchain_deepai-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-28 15:24:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "your-org",
    "github_project": "langchain-deepai",
    "github_not_found": true,
    "lcname": "langchain-deepai"
}
        
Elapsed time: 1.61384s