Download README.md from JW55/SurfSense: direct link, hf CLI and curl.
- Browser
- Download file 13.3 kB
-
https://huggingface.co/spaces/JW55/SurfSense/resolve/main/README.md
- Command line
-
hf download hf://spaces/JW55/SurfSense/README.md
-
curl -L -o README.md https://huggingface.co/spaces/JW55/SurfSense/resolve/main/README.md
A newer version of the Gradio SDK is available: 6.31.0
title: SurfSense
emoji: π
colorFrom: blue
colorTo: indigo
sdk: gradio
sdk_version: 6.19.0
app_file: app_gradio.py
pinned: false
π SurfSense - AI Surf Trip Planning Assistant
A terminal-based conversational AI assistant that helps surfers plan trips by analyzing surf forecasts, evaluating conditions against skill levels, and creating optimized multi-day itineraries. Powered by Azure OpenAI GPT-4o-mini with function-calling, delegating to deterministic sub-agents for data aggregation, condition assessment, and trip planning.
π Features
- π€ Azure OpenAI Orchestrator: GPT-4o-mini with function-calling manages dialogue and delegates to specialized sub-agents
- π Dynamic Spot Research: Tavily-powered web search + LLM extraction β ask about any surf spot worldwide, no pre-built database needed
- π¬ Terminal Chat Interface: Natural conversation β no slash commands needed, just describe your trip
- π Multi-Source Forecasts: Integrates Stormglass (paid) and Open-Meteo (free, no API key) for wave, swell, wind, and tide data
- π Skill-Level Safety: Deterministic scoring evaluates conditions against beginner/intermediate/advanced thresholds
- π Trip Optimization: Greedy multi-day itinerary planning with travel-time penalties (Haversine) and spot diversity
- ποΈ Contextual Data: Parking, accessibility, reviews, and safety information for surf spots
π Prerequisites
- Python 3.10+
- Azure OpenAI API access (GPT-4o-mini deployment with function-calling support)
- Tavily API key (free tier: 1,000 searches/month β get one at tavily.com)
- macOS, Linux, or Windows
π Quick Start
1. Clone and Setup
git clone <repository-url>
cd SurfSense
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
2. Install Dependencies
make install
# Or manually:
pip install -r requirements.txt
3. Configure
cp .env.example .env
# Edit .env with your credentials:
# AZURE_OPENAI_ENDPOINT=https://<your-resource>.openai.azure.com/
# AZURE_OPENAI_API_KEY=<your-key>
# AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o
# TAVILY_API_KEY=tvly-<your-key>
4. Verify API Connections
make check-api
# Or:
pytest tests/test_api_connections.py -v
This pings every external service (Azure OpenAI / OpenAI, Tavily, Stormglass, Open-Meteo, NOAA) and confirms your API keys are valid. Fix any failures before starting the app.
5. Start Chatting!
make run
# Or:
python -m app
π¬ Example Conversation
============================================================
π SurfSense - AI Surf Trip Planning Assistant
============================================================
Version: 0.1.0
π Configuration Summary:
Azure OpenAI Deployment: gpt-4o
β
Ready! Type 'quit' or 'exit' to leave.
------------------------------------------------------------
π§ You: How's Caparica looking this weekend? I'm an intermediate surfer.
π€ SurfSense: Let me research that spot and check the forecast...
π Costa da Caparica, Portugal (beach break, sand bottom)
Skill level: BeginnerβIntermediate friendly
Saturday: 3-4ft waves, light E wind (offshore), 12s period
Rating: β
Ideal for intermediate β clean conditions all morning
Sunday: 2-3ft, NW wind picking up by noon
Rating: β οΈ Suitable until 11am, then conditions deteriorate
Best window: Saturday 7amβ12pm (score: 82/100)
Hazards: rip currents near the northern end
Parking: free lots along the coast road
π§ You: quit
π Goodbye!
π Project Structure
SurfSense/
βββ app/
β βββ __init__.py # Package info and version
β βββ __main__.py # Terminal chat entry point
β βββ agents/
β β βββ orchestrator.py # LLM-powered orchestrator (function-calling)
β β βββ research_agent.py # Dynamic spot research (Tavily + LLM)
β β βββ forecast_data_agent.py # Data aggregation sub-agent
β β βββ condition_agent.py # Condition assessment sub-agent
β β βββ trip_planning_agent.py # Trip planning sub-agent
β βββ core/
β β βββ llm_service.py # Azure OpenAI + fallback providers
β β βββ logger.py # Structured logging with redaction
β βββ forecasting/
β β βββ models.py # Unified forecast data models (Pydantic)
β β βββ openmeteo_client.py # Open-Meteo API (free, no key)
β β βββ stormglass_client.py # Stormglass API (paid, 10 req/day free)
β β βββ noaa_client.py # NOAA Marine Weather (US only)
β βββ contextual/
β β βββ parking.py # Parking data provider
β β βββ accessibility.py # Accessibility data provider
β β βββ reviews.py # Reviews data provider
β β βββ safety.py # Safety/hazard data provider
β βββ planning/
β β βββ condition_assessor.py # Deterministic condition scoring
β β βββ window_finder.py # Surf window identification
β β βββ trip_planner.py # Multi-day itinerary optimization
β β βββ travel_utils.py # Haversine distance calculations
β βββ knowledge/
β βββ spot_database.py # Legacy spot database (deprecated)
βββ config/
β βββ settings.py # Type-safe Pydantic configuration
βββ data/
β βββ spots.json # Legacy spot metadata (deprecated)
βββ tests/ # Unit tests for sub-agents
βββ requirements.txt # Python dependencies
βββ .env.example # Configuration template
βββ Makefile # Common commands
βββ README.md
βοΈ Configuration
All settings are in .env (copy from .env.example):
Azure OpenAI (Required)
| Variable | Default | Description |
|---|---|---|
AZURE_OPENAI_ENDPOINT |
(empty) | Azure OpenAI endpoint URL |
AZURE_OPENAI_API_KEY |
(empty) | Azure OpenAI API key |
AZURE_OPENAI_DEPLOYMENT_NAME |
gpt-4o |
Azure deployment name |
AZURE_OPENAI_API_VERSION |
2024-10-21 |
API version |
AZURE_OPENAI_TEMPERATURE |
0.7 |
Sampling temperature (0.0β2.0) |
AZURE_OPENAI_MAX_TOKENS |
2000 |
Max tokens in LLM response |
Tavily Search (Required)
| Variable | Default | Description |
|---|---|---|
TAVILY_API_KEY |
(empty) | Tavily API key (get free key) |
TAVILY_SEARCH_DEPTH |
basic |
Search depth: basic (fast) or advanced (thorough) |
TAVILY_MAX_RESULTS |
5 |
Number of search results per query (1β10) |
Forecast API (Optional)
| Variable | Default | Description |
|---|---|---|
FORECAST_API_KEY |
(empty) | Stormglass API key. Open-Meteo is used as free fallback |
Skill Thresholds
| Variable | Default | Description |
|---|---|---|
BEGINNER_MAX_WAVE_HEIGHT |
1.5 |
Max wave height (m) for beginner |
BEGINNER_MAX_WIND_SPEED |
15 |
Max wind speed (kph) for beginner |
INTERMEDIATE_MAX_WAVE_HEIGHT |
2.5 |
Max wave height (m) for intermediate |
INTERMEDIATE_MAX_WIND_SPEED |
20 |
Max wind speed (kph) for intermediate |
ADVANCED_MAX_WAVE_HEIGHT |
5.0 |
Max wave height (m) for advanced |
ADVANCED_MAX_WIND_SPEED |
30 |
Max wind speed (kph) for advanced |
π οΈ Development
Make Commands
make help # Show all available commands
make install # Install dependencies
make run # Start the chat application
make test # Run test suite
make check-api # Verify all API connections
make clean # Remove cache files
Chat Commands
| Command | Description |
|---|---|
/reset |
Clear conversation history and cached data |
/help |
Show available commands |
quit / exit |
Exit the application |
ποΈ Architecture
SurfSense follows a single-orchestrator, multi-agent pattern:
User (Terminal)
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Orchestrator (LLM-powered) β
β Azure OpenAI GPT-4o-mini with function-calling β
β β’ Manages dialogue and preference elicitation β
β β’ Selects which sub-agent tool to call β
β β’ Synthesises sub-agent outputs into responses β
ββββ¬βββββββββββ¬βββββββββββββββ¬βββββββββββββββ¬βββββββ
β β β β
βΌ βΌ βΌ βΌ
ββββββββββ βββββββββββββββ ββββββββββββββββ ββββββββββββββββ
βResearchβ β Forecast & β β Condition β β Trip β
β Agent β β Data β β Assessment β β Planning β
β β β Aggregation β β Agent β β Agent β
βresearchβ β Agent β β β β β
β_spot β β β β β’ assess_ β β β’ find_surf_ β
β β β β’ fetch_ β β conditions β β windows β
βTavily +β β forecast β β β’ check_ β β β’ plan_ β
βLLM β β β’ fetch_ β β safety β β itinerary β
βextract β β context β β β’ get_skill_β β β’ rank_spots β
β β β β’ get_spot_ β β thresholdsβ β β
β β β metadata β β β β β
ββββββββββ βββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β β β β
βΌ βΌ βΌ βΌ
Tavily External APIs config/settings.py Haversine +
Web Search (Open-Meteo, (SkillLevel greedy
Stormglass) Thresholds) optimisation
Data Flow
When a user mentions any surf spot, the orchestrator follows this sequence:
research_spotβ Tavily web search + LLM extraction β structured spot data (coordinates, break type, hazards, skill levels)fetch_forecastβ uses coordinates from step 1 β hourly wave/wind/swell dataassess_conditionsβ scores each hour against the user's skill levelfind_surf_windows/plan_itineraryβ identifies best times and builds schedules
Design Principles
- Single LLM point: Only the orchestrator calls Azure OpenAI β predictable token costs, no non-determinism in safety scoring
- Dynamic knowledge: No hardcoded spot database β the ResearchAgent discovers spot information at conversation time via web search
- Function-calling as delegation: GPT-4o-mini decides which tools to invoke; tool results feed back into the conversation
- Deterministic sub-agents: Python classes with scoring formulas, API calls, and optimization algorithms β no LLM calls (except ResearchAgent's extraction step)
π§ͺ Testing
# Run all tests
make test
# Or with pytest directly
pytest tests/ -v
Verify API Connections
Before your first run (or after changing .env), check that every external
service is reachable and your keys are valid:
make check-api
This runs one lightweight ping per API:
| Test | Service | Key required? |
|---|---|---|
TestLLMConnection |
Azure OpenAI / OpenAI | β |
TestTavilyConnection |
Tavily web search | β |
TestStormglassConnection |
Stormglass forecast | Optional |
TestOpenMeteoConnection |
Open-Meteo forecast | β Free |
TestNOAAConnection |
NOAA weather | β Free |
π Troubleshooting
Azure OpenAI Connection Error?
Run make check-api to pinpoint which service is failing.
Verify your credentials in .env:
# Test your Azure OpenAI setup
python -c "from openai import AzureOpenAI; print('OK')"
Ensure your deployment supports function-calling (GPT-4o-mini recommended).
Import Errors?
# Ensure venv is activated and dependencies installed
source .venv/bin/activate
pip install -r requirements.txt
Forecast Data Unavailable?
Open-Meteo (free, no API key) is used as the default forecast source. If it's down, configure Stormglass as a fallback:
# In .env:
FORECAST_API_KEY=<your-stormglass-key>
Built with β€οΈ for the surfing community π