import openai
from typing import List, Dict, Any

class ScientificWriter:
    """Generates scientific articles, summaries, and research reports from AI outputs."""
    def __init__(self, api_key: str):
        openai.api_key = api_key

    def write_article(self, title: str, abstract: str, hypotheses: List[Dict[str, Any]], results: List[Dict[str, Any]], bibliography: List[str], style: str = "arxiv") -> str:
        # Compose a prompt for the language model
        prompt = f"""
Write a scientific article in the style of {style}.
Title: {title}
Abstract: {abstract}
Hypotheses: {hypotheses}
Results: {results}
Bibliography: {bibliography}
"""
        response = openai.ChatCompletion.create(
            model="gpt-4",
            messages=[{"role": "system", "content": "You are a scientific research assistant."},
                      {"role": "user", "content": prompt}]
        )
        return response.choices[0].message['content']

    def summarize(self, text: str, style: str = "arxiv") -> str:
        prompt = f"Summarize the following in the style of {style}:\n{text}"
        response = openai.ChatCompletion.create(
            model="gpt-4",
            messages=[{"role": "system", "content": "You are a scientific research assistant."},
                      {"role": "user", "content": prompt}]
        )
        return response.choices[0].message['content']
