Skip to content

Commit

Permalink
Updated readme, set gpt to default off, cleaned up helper
Browse files Browse the repository at this point in the history
ryansurf committed May 30, 2024
1 parent 1db9e49 commit 20969fc
Showing 6 changed files with 40 additions and 33 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ Wave Period: 9.8
| decimal / dec | Specify decimal points in output |
| color / c | Choose color of wave art. Ex: `color=light_blue` |
| json / j | Output the data in JSON format. Must be the only argument |
| gpt / g | Activates the GPT surf report. Change the `GPT_PROMPT` variable in `.env` to customize responses. Default = off |

**Examples**
* Arguments are seperated by commas.
@@ -112,6 +113,7 @@ Change `.env.example` to `.env`
| `EMAIL_RECEIVER` | The email that will receive the report (your personal email) |
| `COMMAND` | The command that will be ran and shown in the email. Default = `localhost:8000` |
| `SUBJECT` | The email's subject. Default = Surf Report |
| `GPT_PROMPT` | Given the surf data (height, swell direction, etc.), you can tell the GPT what kind of report you would like. For example: `With this data, recommend what size board I should ride.` |


**Email Server**
4 changes: 3 additions & 1 deletion src/api.py
Original file line number Diff line number Diff line change
@@ -182,14 +182,16 @@ def gather_data(lat, long, ocean):
json_forecast = helper.forecast_to_json(spot_forecast, ocean["decimal"])

data_dict = {
"Lat": lat,
"Long": long,
"Location": ocean["city"],
"Height": ocean_data[0],
"Direction": ocean_data[1],
"Period": ocean_data[2],
"UV Index": uv_index,
"Forecast": json_forecast,
}
return ocean_data, uv_index, data_dict
return data_dict


def seperate_args_and_get_location(args):
13 changes: 4 additions & 9 deletions src/cli.py
Original file line number Diff line number Diff line change
@@ -9,13 +9,11 @@

from src import api, helper, settings


# Load environment variables from .env file
env = settings.GPTSettings()
gpt_prompt = env.GPT_PROMPT



def run(lat=0, long=0):
"""
Main function
@@ -27,11 +25,11 @@ def run(lat=0, long=0):
location = api.seperate_args_and_get_location(args)

set_location = helper.set_location(location)
coordinates, city = set_location[0], set_location[1]
city = set_location[0]

# Check if lat and long are set to defaults(no argumentes passed in main())
if lat == 0 and long == 0:
lat, long = set_location[2], set_location[3]
lat, long = set_location[1], set_location[2]

# Sets ocean = dictionary with
arguments = helper.arguments_dictionary(lat, long, city, args)
@@ -41,14 +39,11 @@ def run(lat=0, long=0):
lat = float(lat)
long = float(long)
# Makes calls to the apis(ocean, UV) and returns the values
data = api.gather_data(lat, long, arguments)
ocean_data = data[0]
# uv_index = data[1]
data_dict = data[2]
data_dict = api.gather_data(lat, long, arguments)

# Non-JSON output
if arguments["json_output"] == 0:
helper.print_outputs(lat, long, coordinates, ocean_data, arguments, data_dict, gpt_prompt)
helper.print_outputs(city, data_dict, arguments, gpt_prompt)
return data_dict
# JSON Output
else:
9 changes: 5 additions & 4 deletions src/gpt.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
"""
GPT Functions stored here
"""

from g4f.client import Client


def simple_gpt(surf_summary, gpt_prompt):
"""
Surf summary is a report of todays data, ex: The surf is 4 feet with a 10 second period...
GPT Prompt is what kind of report the user wants, loaded in from the environment vars
Surf summary is a report of todays data, ex: The surf is 4
feet with a 10 second period... GPT Prompt is what kind of
report the user wants, loaded in from the environment vars
"""
client = Client()
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": surf_summary + gpt_prompt}],
language="en" # Specify English language. For some reason, mine was in Japanese. Should create setting to configure this
)
return response.choices[0].message.content

34 changes: 19 additions & 15 deletions src/helper.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ def arguments_dictionary(lat, long, city, args):
"decimal": extract_decimal(args),
"forecast_days": get_forecast_days(args),
"color": get_color(args),
"gpt": 1
"gpt": 0,
}
return arguments

@@ -166,8 +166,8 @@ def set_output_values(args, ocean):
ocean["unit"] = "metric"
if "json" in args or "j" in args:
ocean["json_output"] = 1
if "hide_gpt" in args or "hgpt" in args:
ocean["gpt"] = 0
if "gpt" in args or "g" in args:
ocean["gpt"] = 1
return ocean


@@ -180,16 +180,16 @@ def json_output(data_dict):
return data_dict


def print_outputs(lat, long, coordinates, ocean_data, arguments, data_dict, gpt_prompt):
def print_outputs(city, data_dict, arguments, gpt_prompt):
"""
Basically the main printing function,
calls all the other printing functions
"""
print("\n")
if coordinates == "No data":
if city == "No data":
print("No location found")
if ocean_data == "No data":
print(coordinates)
if data_dict["Height"] == "No data":
print(data_dict["Lat"], data_dict["Long"])
print("No ocean data at this location.")
else:
print_location(arguments["city"], arguments["show_city"])
@@ -201,7 +201,10 @@ def print_outputs(lat, long, coordinates, ocean_data, arguments, data_dict, gpt_
print_output(arguments)
print("\n")
forecast = api.forecast(
lat, long, arguments["decimal"], arguments["forecast_days"]
data_dict["Lat"],
data_dict["Long"],
arguments["decimal"],
arguments["forecast_days"],
)
print_forecast(arguments, forecast)
if arguments["gpt"] == 1:
@@ -213,9 +216,9 @@ def set_location(location):
"""
Sets locations variables
"""
coordinates, city = location["coordinates"], location["city"]
city = location["city"]
lat, long = location["lat"], location["long"]
return coordinates, city, lat, long
return city, lat, long


def forecast_to_json(data, decimal):
@@ -237,17 +240,18 @@ def forecast_to_json(data, decimal):

return forecasts


def surf_summary(surf_data):
"""
Outputs a simple summary of the surf data.
Useful for the GPT
"""
location = surf_data['Location']
height = surf_data['Height']
direction = surf_data['Direction']
period = surf_data['Period']
location = surf_data["Location"]
height = surf_data["Height"]
direction = surf_data["Direction"]
period = surf_data["Period"]
report = f"""
Today at {location}, the surf height is {height}, the direction of the
Today at {location}, the surf height is {height}, the direction of the
swell is {direction} degrees and the swell period is {period} seconds.
"""
return report
11 changes: 7 additions & 4 deletions src/settings.py
Original file line number Diff line number Diff line change
@@ -51,7 +51,10 @@ class GPTSettings(CommonSettings):
Class for defining server env settings.
"""

GPT_PROMPT: str = Field(default="""
With this surf data, give me a short estimate on how the surf might be at the specified location
with the given data. Recommend another nearby spot to surf at if you think it may be better.
""")
GPT_PROMPT: str = Field(
default="""
With this surf data, give me a short estimate on how the surf
might be at the specified location with the given data.
Recommend another nearby spot to surf at if you think it may be better.
"""
)

0 comments on commit 20969fc

Please sign in to comment.