diff --git a/.gitignore b/.gitignore index 9c014f5..eab15b5 100644 --- a/.gitignore +++ b/.gitignore @@ -164,6 +164,7 @@ logs .env scripts .vscode +**/.env # Polymind learned facts and tools knowledge/facts/** diff --git a/examples/media-gen/README.md b/examples/media-gen/README.md index 55ee1ad..ee627f1 100644 --- a/examples/media-gen/README.md +++ b/examples/media-gen/README.md @@ -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 ``` @@ -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 @@ -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() diff --git a/examples/media-gen/env.example b/examples/media-gen/env.example new file mode 100644 index 0000000..f067572 --- /dev/null +++ b/examples/media-gen/env.example @@ -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 \ No newline at end of file diff --git a/examples/media-gen/example_usage.py b/examples/media-gen/example_usage.py index a1fc443..c5a0e14 100644 --- a/examples/media-gen/example_usage.py +++ b/examples/media-gen/example_usage.py @@ -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() diff --git a/examples/media-gen/requirements.txt b/examples/media-gen/requirements.txt index f5babf8..639886c 100644 --- a/examples/media-gen/requirements.txt +++ b/examples/media-gen/requirements.txt @@ -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 diff --git a/examples/media-gen/setup_env.py b/examples/media-gen/setup_env.py new file mode 100644 index 0000000..2fdae48 --- /dev/null +++ b/examples/media-gen/setup_env.py @@ -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() \ No newline at end of file diff --git a/examples/media-gen/tools/dummy_image_gen.py b/examples/media-gen/tools/dummy_image_gen.py index b370126..05f902f 100644 --- a/examples/media-gen/tools/dummy_image_gen.py +++ b/examples/media-gen/tools/dummy_image_gen.py @@ -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" } } diff --git a/pyproject.toml b/pyproject.toml index b31da67..b87d7aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/tests/polymind/core_tools/test_llm_tools.py b/tests/polymind/core_tools/test_llm_tools.py index f22a1a7..360f617 100644 --- a/tests/polymind/core_tools/test_llm_tools.py +++ b/tests/polymind/core_tools/test_llm_tools.py @@ -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: