A simple one page Express app using Anthropic's Tool feature to get the weather using OpenWeather Map. All necessary code is in the app.ts
file.
Once you've forked the repository, install all dependencies using:
npm install
Get necessary API keys from Anthropic and OpenWeather.
Create a .env
file with the following:
ANTHROPIC_API_KEY=
OPENWEATHER_API_KEY=
To start the application:
npm start
Make requests:
curl -X POST -H "Content-Type: application/json" -d '{"message": "What is the weather in SF?"}'
The location is currently hardcoded to be SF, in order to have the application be more flexible you can use the function.ts file as a reference to build out a dynamic location <> weather app (hint, pull out the city, county, and other necessary information to pass to the relevant functions).
While function.ts
file is not being used, it is a cleaner way to separate out the tool code and serves as an example of how you can extend this application.
Currently, there isn't much documentation for the feature on Typescript. You can check out some writing about Tool here:
- an example tool.ts
- Documentation - still pretty Python specific