Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import openai
- openai.api_key = os.getenv("OPENAI_API_KEY")
- SYSTEM_PROMPT="""You are a consumer-facing application called [Weather_API]. Your purpose is to take user input and respond with structured JSON data.
- It's absolutely crucial that you follow these instructions. Every response should strictly adhere to a JSON format.
- If the prompt doesn't make sense, is invalid, unclear, or outside the range of your knowledge or capabilities, respond with an error JSON like this: { \\\"error\\\": \\\"[JSON Error]\\\" }.
- Do not engage in general conversation, creative writing or go beyond the scope of the user's prompt. Stick to the instruction and always respond in the defined format.
- Use the following JSON output as example for the respond:
- {
- "morning":{
- "temperature": "2°C",
- "weather": "gentle mists",
- "wind": "breeze"
- },
- "afternoon": {
- "temperature": "33°C",
- "weather": "clouds",
- "wind": "light wind"
- },
- "evening": {
- "temperature": "27°C",
- "weather": "cloudy",
- "wind": "storm"
- },
- "night": {
- "temperature": "14°C",
- "weather": "partly cloudy",
- "wind": "tornado"
- },
- }
- """
- USER_PROMPT= """Morning:
- Temperatures will start off crisp at 12°C, with gentle mists covering the banks of the Vistula River.
- There will be an occasional chirp of a bird, signifying the day's awakening.
- A soft northwesterly breeze will rustle the trees.
- Afternoon:
- As midday approaches, expect the sun to break through, lifting the temperatures to a comfortable 23°C.
- Puffy cumulus clouds will dot the sky, casting fleeting shadows across Warsaw's historical streets and buildings.
- A light breeze will be felt, offering a nice respite from the mild warmth.
- Evening:
- Sunset will paint the sky in hues of purple and pink. The temperature is predicted to drop to 17°C by 9:00 PM.
- It's a perfect time to enjoy a quiet evening stroll in Łazienki Park or a meal at an outdoor cafe.
- There will be a 20% chance of a brief drizzle later in the night.
- Night:
- Nightfall will see a partly cloudy sky with the gentle glow of the moon illuminating the cityscape. The wind will calm, leaving a serene atmosphere.
- Overnight lows will drop to 14°C. It will be a good night to leave the windows slightly ajar and let in the fresh cool air.
- """
- response = openai.ChatCompletion.create(
- model="gpt-3.5-turbo",
- messages=[
- {
- "role": "system",
- "content": f"{SYSTEM_PROMPT}"
- },
- {
- "role": "user",
- "content": f"{USER_PROMPT}"
- }
- ],
- temperature=0.3,
- max_tokens=563,
- top_p=1,
- frequency_penalty=0,
- presence_penalty=0
- )
- print(response.choices[0].message.content)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement