Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ logs
.env
scripts
.vscode
**/.env

# Polymind learned facts and tools
knowledge/facts/**
Expand Down
37 changes: 37 additions & 0 deletions examples/media-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ source venv/bin/activate # On Windows: venv\Scripts\activate.bat
pip install -r requirements.txt
```

### Environment Configuration

**Option 1: Use the setup script (recommended):**
```bash
python setup_env.py
```

**Option 2: Manual setup:**
1. **Copy the environment template:**
```bash
cp env.example .env
```

2. **Edit `.env` file with your API keys:**
```bash
# Edit .env file with your actual API keys
nano .env # or use your preferred editor
```

3. **Required API keys:**
- `OPENAI_API_KEY`: For DALL-E image generation
- `REPLICATE_API_TOKEN`: For various AI models

**Note:** The `.env` file is automatically ignored by git to keep your keys secure.

## File Structure

```
Expand All @@ -46,6 +71,9 @@ media-gen/
│ └── dummy_video_gen.py # Dummy video generation tool
├── tests/ # Test suite
│ └── test_dummy_media_gen.py # Comprehensive tests

├── env.example # Environment variables template
├── setup_env.py # Environment setup script
├── example_usage.py # Usage examples
├── requirements.txt # Dependencies
├── setup_env.sh # Linux/macOS setup script
Expand Down Expand Up @@ -112,6 +140,15 @@ class MyVideoGen(VideoGenerationTool):

```python
from tools import DummyImageGen, DummyVideoGen
from dotenv import load_dotenv
import os

# Load environment variables
load_dotenv()

# Check configuration status
print(f"OpenAI API Key: {'✓ Available' if os.getenv('OPENAI_API_KEY') else '✗ Missing'}")
print(f"Replicate API Token: {'✓ Available' if os.getenv('REPLICATE_API_TOKEN') else '✗ Missing'}")

# Initialize tools
image_gen = DummyImageGen()
Expand Down
14 changes: 14 additions & 0 deletions examples/media-gen/env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Media Generation Tools Environment Variables
# Copy this file to .env and fill in your actual API keys

# OpenAI API Configuration
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_ORG_ID=your_openai_org_id_here # Optional

# Replicate API Configuration
REPLICATE_API_TOKEN=your_replicate_api_token_here

# Configuration
DEFAULT_IMAGE_MODEL=dall-e-3
DEFAULT_VIDEO_MODEL=stable-video-diffusion
LOG_LEVEL=INFO
38 changes: 37 additions & 1 deletion examples/media-gen/example_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,53 @@
Example usage of the media generation tools.

This script demonstrates how to use the DummyImageGen and DummyVideoGen tools
with the new parameter specifications.
with the new parameter specifications and environment variable configuration.
"""

import os

from dotenv import load_dotenv
from tools import DummyImageGen, DummyVideoGen


def check_config_status():
"""Check and display configuration status."""
print("Configuration Status:")
print("=" * 40)

# Load environment variables
load_dotenv()

# Check API keys
openai_key = os.getenv("OPENAI_API_KEY")
replicate_token = os.getenv("REPLICATE_API_TOKEN")

print(f"OpenAI API Key: {'✓ Available' if openai_key else '✗ Missing'}")
print(f"Replicate API Token: "
f"{'✓ Available' if replicate_token else '✗ Missing'}")

# Show configuration
default_image = os.getenv('DEFAULT_IMAGE_MODEL', 'dall-e-3')
default_video = os.getenv('DEFAULT_VIDEO_MODEL', 'stable-video-diffusion')
log_level = os.getenv('LOG_LEVEL', 'INFO')

print(f"\nDefault Image Model: {default_image}")
print(f"Default Video Model: {default_video}")
print(f"Log Level: {log_level}")

if not openai_key or not replicate_token:
print("\nMissing API keys. Please check your .env file.")


def main():
"""Demonstrate the media generation tools."""
print("Media Generation Tools Example")
print("=" * 40)

# Check configuration status
print("\nConfiguration Status:")
check_config_status()

# Initialize tools
image_gen = DummyImageGen()
video_gen = DummyVideoGen()
Expand Down
1 change: 1 addition & 0 deletions examples/media-gen/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ polymind

# Development dependencies
pytest # For running tests
python-dotenv # For environment variable management

# Additional dependencies that Polymind requires
anthropic # For Claude integration
Expand Down
46 changes: 46 additions & 0 deletions examples/media-gen/setup_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
"""
Setup script for media generation tools environment.

This script helps users set up their .env file with the required API keys.
"""
import shutil
from pathlib import Path


def setup_environment():
"""Set up the environment configuration."""
print("Media Generation Tools Environment Setup")
print("=" * 40)

# Check if .env already exists
env_file = Path(".env")
example_file = Path("env.example")

if env_file.exists():
print("✓ .env file already exists")
response = input("Do you want to overwrite it? (y/N): ").lower()
if response != 'y':
print("Setup cancelled.")
return

# Copy example file to .env
if example_file.exists():
shutil.copy(example_file, env_file)
print("✓ Created .env file from template")
else:
print("✗ env.example file not found")
return

print("\nNext steps:")
print("1. Edit the .env file with your actual API keys")
print("2. Run 'python example_usage.py' to test the setup")
print("\nRequired API keys:")
print("- OPENAI_API_KEY: For DALL-E image generation")
print("- REPLICATE_API_TOKEN: For various AI models")

print("\n✓ Environment setup completed!")


if __name__ == "__main__":
setup_environment()
3 changes: 2 additions & 1 deletion examples/media-gen/tools/dummy_image_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def run(self, input: dict) -> dict:
"aspect_ratio": aspect_ratio,
"output_format": output_format,
"seed": "12345",
"status": "generated (dummy)"
"status": "generated (dummy)",
"note": "This is a dummy implementation. Real tools would use API keys from .env"
}
}

Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ milvus = ["pymilvus"]
line-length = 120

[tool.isort]
skip = ["__init__.py"]
profile = "black"
line_length = 120
skip = ["__init__.py", "venv", "*/venv/*", "*/__pycache__/*", "*/site-packages/*"]
known_first_party = ["polymind"]
known_third_party = ["dotenv", "pathlib", "shutil"]

[tool.flake8]
max-line-length = 120
Expand Down
3 changes: 1 addition & 2 deletions tests/polymind/core_tools/test_llm_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import pytest

from polymind.core.message import Message
from polymind.core_tools.llm_tool import (OpenAIChatTool,
OpenAICodeGenerationTool)
from polymind.core_tools.llm_tool import OpenAIChatTool, OpenAICodeGenerationTool


class TestOpenAIChatTool:
Expand Down
Loading