Skip to content

Weather Assistant CLI using GitHub Copilot SDK and Open-Meteo to fetch real-time weather for user-queried cities.

License

Notifications You must be signed in to change notification settings

wlsf82/weather-assistant-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weather Assistant CLI (Copilot SDK + Open‑Meteo)

Simple command‑line assistant that uses the GitHub Copilot SDK and a custom tool (get_weather) to fetch real‑time weather for a city via the Open‑Meteo public API.

Requirements

  • Node.js 18+ (uses global fetch) or any version that supports --import loader flags.
  • npm.

Setup

npm install

Authentication

To run the assistant with the Copilot SDK, set either GH_TOKEN or GITHUB_TOKEN in your environment. See the official docs: https://docs.github.com/pt/copilot/how-tos/set-up/install-copilot-cli#authenticating-with-copilot-cli

macOS/Linux

export GH_TOKEN=your_token_here   # or
export GITHUB_TOKEN=your_token_here

Note: The quick standalone check script does not require authentication because it calls Open‑Meteo directly.

Run

Start the assistant (interactive CLI)

npm start
  • Example: type “What’s the weather in Paris?” then press Enter.
  • Type exit to quit.

Guardrail: If you ask about non‑weather topics (e.g., jokes, finance, cooking), the assistant will refuse with a short message and will not engage.

Sample interactive session

$ npm start
> weather-assistant-cli@1.0.0 start
> tsx src/index.ts

🌤️  Weather Assistant (type 'exit' to quit)
   Try: 'What's the weather in Paris?'

You: 'What's the weather in Paris?
Assistant: The weather in Paris is 4.7°C (feels like 2.9°C), overcast, with a wind speed of 8.1 m/s.

You: What about New York?
Assistant: The weather in New York is -9.4°C (feels like -15.2°C), overcast, with a wind speed of 8.6 m/s.

You: Compare Tokyo vs Lisbon temperatures.
Assistant: Tokyo is currently 3°C (feels like 1°C, clear sky), while Lisbon is 11.7°C (feels like 10.2°C, slight rain). Lisbon is warmer than Tokyo.

You: exit

Note: Values above are examples; actual results depend on current conditions.

Quick standalone check (no Copilot session required)

npx tsx src/scripts/check-weather.ts "Paris"

Testing

Unit tests

npm run test:unit

Integration tests (hit real APIs)

npm run test:integration

Run all tests

npm test

Project Structure

src/index.ts                 # CLI assistant + Copilot session and tool
src/lib/guardrail.ts         # Guardrail for weather-related prompts
src/lib/weather.ts           # Shared helpers: geocoding, current weather, mapping
src/scripts/check-weather.ts # Quick verification script without Copilot
test/unit/*.ts               # Unit tests (Sinon stubs for fetch)
test/integration/*.ts        # Integration tests (real Open‑Meteo calls)

Notes

  • Temperature is returned in °C.
  • Uses Open‑Meteo’s free, keyless endpoints for geocoding and current weather.
  • The get_weather tool exposes city as a parameter and returns a normalized payload: city, temperature, feels_like, condition, wind_speed_mps, source.
  • The CLI includes a lightweight guardrail to only respond to weather‑related prompts.

License

MIT.

About

Weather Assistant CLI using GitHub Copilot SDK and Open-Meteo to fetch real-time weather for user-queried cities.

Topics

Resources

License

Stars

Watchers

Forks