File size: 3,333 Bytes
a38b3f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import logging
import openai
import os
from dotenv import load_dotenv
from swarm import Swarm, Agent

# Load environment variables from the .env file
load_dotenv()

# Configure logging
logging.basicConfig(level=logging.INFO)

# Load OpenAI API key from environment variables
openai.api_key = os.getenv("OPENAI_API_KEY")
if not openai.api_key:
    raise ValueError("OpenAI API key is missing from the environment.")

# Initialize the Swarm instance (not used for this test)
swarm_system = Swarm()

# Mock agent functions
def mock_nasa_agent():
    return {'title': 'Jupiter and Saturn aligned'}

def mock_moon_agent():
    return {'moon_phase': 'New Moon'}

def mock_tides_agent():
    return [{'v': 2.1}]

def generate_aries_prediction():
    """Generate horoscope prediction for Aries."""
    try:
        # Call mock agents
        planetary_data = mock_nasa_agent()
        moon_data = mock_moon_agent()
        tide_data = mock_tides_agent()

        # Extract necessary data
        planetary_title = planetary_data.get('title', 'Unknown planetary influence')
        moon_phase = moon_data.get('moon_phase', 'Unknown phase')
        tide_level = tide_data[0].get('v', 'N/A') if isinstance(tide_data, list) else "N/A"

        # Build the prompt for OpenAI API
        prompt = (
            f"Generate a detailed horoscope for Aries:\n"
            f"- Moon phase: {moon_phase}\n"
            f"- Planetary alignment: {planetary_title}\n"
            f"- Tide level: {tide_level} meters\n\n"
            f"Include:\n"
            f"1. Current Prediction\n"
            f"2. Future Prediction\n"
            f"3. Personalized Advice\n"
        )

        # Call the OpenAI API to generate predictions
        response = openai.Completion.create(
            model="text-davinci-003",  # Use text-davinci-003
            prompt=prompt,
            max_tokens=300,
            temperature=0.7
        )

        # Parse the predictions (adjust this based on the model's output)
        predictions = response.choices[0].text.strip().split("\n\n")  
        current_prediction = predictions[0] if predictions else "No current prediction available."
        future_prediction = predictions[1] if len(predictions) > 1 else "No future prediction available."

        # Save horoscope to a file
        os.makedirs("/app/reports", exist_ok=True)
        with open("/app/reports/aries_horoscope.txt", "w") as file:
            file.write("Aries 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 Aries prediction: {str(e)}")
        return {"error": str(e)}

# Define the Aries agent (not used for this test)
aries_agent = Agent(
    name="AriesAgent",
    instructions="Generate horoscope predictions for Aries using planetary, moon, and tide data.",
    functions=[generate_aries_prediction]
)

# Test the Aries Agent directly
if __name__ == "__main__":
    logging.info("Testing Aries Agent...")

    # Call the Aries agent's function directly
    result = generate_aries_prediction()
    print(result)