import logging import openai import os from dotenv import load_dotenv # Importing to load environment variables from swarm import Agent, Swarm # Load environment variables from .env file load_dotenv() # Load environment variables from the .env file # Configure logging logging.basicConfig(level=logging.INFO) # Load OpenAI API key openai.api_key = os.getenv("OPENAI_API_KEY") # Check if the API key was loaded successfully if not openai.api_key: raise ValueError("OpenAI API key is missing from the environment.") def generate_taurus_prediction(): swarm = Swarm() # Correct way to create a Swarm instance try: # Fetch data from agents planetary_data = swarm.call("NASAAgent") moon_phase_data = swarm.call("MoonAgent") tide_data = swarm.call("TidesAgent") # Extract relevant information current_planetary_title = planetary_data.get('title', 'Unknown planetary influence') current_moon_phase = moon_phase_data.get('moon_phase', 'Unknown phase') current_tide_level = tide_data[0].get('v', 'N/A') if isinstance(tide_data, list) else "N/A" # Build the prompt for OpenAI prompt = ( f"Generate a detailed horoscope report for Taurus using the following data:\n" f"- Current Moon phase: {current_moon_phase}\n" f"- Planetary alignment: {current_planetary_title}\n" f"- Tide level: {current_tide_level} meters\n\n" f"Include the following sections:\n" f"1. **Current Prediction**: How the current planetary and moon data affect Taurus today.\n" f"2. **Future Prediction**: Forecast what Taurus might experience tomorrow.\n" f"3. **Recommendations**: Personalized advice for Taurus focusing on emotional, personal, and professional life.\n" f"The tone should be inspirational and motivational." ) # Call OpenAI to generate predictions response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[{"role": "user", "content": prompt}], max_tokens=300, temperature=0.7 ) predictions = response.choices[0].message['content'].strip().split("\n\n") current_prediction = predictions[0] if len(predictions) > 0 else "No current prediction available." future_prediction = predictions[1] if len(predictions) > 1 else "No future prediction available." # Save horoscope to a file with open("taurus_horoscope.txt", "w") as file: file.write("Taurus Horoscope Report\n") file.write("=========================\n") file.write(f"Current Prediction:\n{current_prediction}\n\n") file.write(f"Future Prediction:\n{future_prediction}\n") return {"current_prediction": current_prediction, "future_prediction": future_prediction} except Exception as e: logging.error(f"Error generating Taurus prediction: {str(e)}") return {"error": f"Unable to generate prediction: {str(e)}"} taurus_agent = Agent( name="TaurusAgent", instructions="Generate detailed horoscope reports for Taurus using OpenAI.", functions=[generate_taurus_prediction] )