# Create and wrap the OpenAI client with Anannas AI's base URL
client = OpenAI(
    api_key=os.environ["ANANNAS_API_KEY"],
    base_url="https://api.anannas.ai/v1"
)
client = track_openai(client)

@track
def summarize_text(text: str):
    response = client.chat.completions.create(
        model="openai/gpt-4o",
        messages=[
            {"role": "system", "content": "You create concise summaries of text content."},
            {"role": "user", "content": f"Please summarize this text:\n{text}"}
        ]
    )
    return response.choices[0].message.content

@track
def analyze_sentiment(summary: str):
    response = client.chat.completions.create(
        model="openai/gpt-4o-mini",
        messages=[
            {"role": "system", "content": "You perform sentiment analysis on text."},
            {"role": "user", "content": f"What is the sentiment of this summary:\n{summary}"}
        ]
    )
    return response.choices[0].message.content

@track(project_name="anannas-integration-demo")
def analyze_text(text: str):
    # First LLM call: Summarize the text
    summary = summarize_text(text)
    
    # Second LLM call: Analyze the sentiment of the summary
    sentiment = analyze_sentiment(summary)
    
    return {
        "summary": summary,
        "sentiment": sentiment
    }