import requests
import json
from typing import List, Dict, Any, Generator
from .base_provider import BaseProvider

class PollinationsAI(BaseProvider):
    def create_completion(
        self,
        model: str,
        messages: List[Dict[str, str]],
        stream: bool = False,
        **kwargs: Any
    ) -> Generator[str, None, None] | str:
        url = "https://text.pollinations.ai/"
        
        # Simplified for basic usage
        data = {
            "messages": messages,
            "model": model,
            "stream": stream
        }
        
        response = requests.post(url, json=data, stream=stream)
        response.raise_for_status()
        
        if stream:
            def generate():
                for line in response.iter_lines():
                    if line:
                        yield line.decode('utf-8')
            return generate()
        else:
            return response.text
