Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified weather example #196

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ PDL programs can contain calls to REST APIs with Python code. Consider a simple
--8<-- "./examples/tutorial/calling_apis.pdl"
```

In this program, we first prompt the user to enter a query about the weather in some location (assigned to variable `QUERY`). The next block is a call to a granite model with few-shot examples to extract the location, which we assign to variable `LOCATION`. The next block makes an API call with Python. Here the `LOCATION` is appended to the `url`. The result is a JSON object, which may be hard to interpret for a human user. So we make a final call to an LLM to interpret the JSON in terms of weather. Notice that many blocks have `contribute` set to `[]` to hide intermediate results.
In this program, we first define a query about the weather in some location (assigned to variable `QUERY`). The next block is a call to a granite model with few-shot examples to extract the location, which we assign to variable `LOCATION`. The next block makes an API call with Python (mocked in this example). Here the `LOCATION` is appended to the `url`. The result is a JSON object, which may be hard to interpret for a human user. So we make a final call to an LLM to interpret the JSON in terms of weather. Notice that many blocks have `contribute` set to `[]` to hide intermediate results.


## Data Block
Expand Down
12 changes: 5 additions & 7 deletions examples/demo/3-weather.pdl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
description: Using a weather API and LLM to make a small weather app
text:
- read:
def: QUERY
message: "Ask a query: "
contribute: []
- def: QUERY
text: "What is the weather in Madrid?\n"
- model: replicate/ibm-granite/granite-3.0-8b-instruct
input: |
Extract the location from the question.
Expand All @@ -21,12 +19,12 @@ text:
- lang: python
code: |
import requests
response = requests.get('https://api.weatherapi.com/v1/current.json?key=cf601276764642cb96224947230712&q=${ LOCATION }')
result = response.content
#response = requests.get('https://api.weatherapi.com/v1/current.json?key==XYZ=${ LOCATION }')
#Mock response:
result = '{"location": {"name": "Madrid", "region": "Madrid", "country": "Spain", "lat": 40.4, "lon": -3.6833, "tz_id": "Europe/Madrid", "localtime_epoch": 1732543839, "localtime": "2024-11-25 15:10"}, "current": {"last_updated_epoch": 1732543200, "last_updated": "2024-11-25 15:00", "temp_c": 14.4, "temp_f": 57.9, "is_day": 1, "condition": {"text": "Partly cloudy", "icon": "//cdn.weatherapi.com/weather/64x64/day/116.png", "code": 1003}, "wind_mph": 13.2, "wind_kph": 21.2, "wind_degree": 265, "wind_dir": "W", "pressure_mb": 1017.0, "pressure_in": 30.03, "precip_mm": 0.01, "precip_in": 0.0, "humidity": 77, "cloud": 75, "feelslike_c": 12.8, "feelslike_f": 55.1, "windchill_c": 13.0, "windchill_f": 55.4, "heatindex_c": 14.5, "heatindex_f": 58.2, "dewpoint_c": 7.3, "dewpoint_f": 45.2, "vis_km": 10.0, "vis_miles": 6.0, "uv": 1.4, "gust_mph": 15.2, "gust_kph": 24.4}}'
def: WEATHER
parser: json
contribute: []

- model: replicate/ibm-granite/granite-3.0-8b-instruct
input: |
Explain the weather from the following JSON:
Expand Down
12 changes: 5 additions & 7 deletions examples/tutorial/calling_apis.pdl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
description: Using a weather API and LLM to make a small weather app
text:
- read:
def: QUERY
message: "Ask a query: "
contribute: []
- def: QUERY
text: "What is the weather in Madrid?\n"
- model: replicate/ibm-granite/granite-3.0-8b-instruct
input: |
Extract the location from the question.
Expand All @@ -21,12 +19,12 @@ text:
- lang: python
code: |
import requests
response = requests.get('https://api.weatherapi.com/v1/current.json?key=cf601276764642cb96224947230712&q=${ LOCATION }')
result = response.content
#response = requests.get('https://api.weatherapi.com/v1/current.json?key==XYZ=${ LOCATION }')
#Mock response:
result = '{"location": {"name": "Madrid", "region": "Madrid", "country": "Spain", "lat": 40.4, "lon": -3.6833, "tz_id": "Europe/Madrid", "localtime_epoch": 1732543839, "localtime": "2024-11-25 15:10"}, "current": {"last_updated_epoch": 1732543200, "last_updated": "2024-11-25 15:00", "temp_c": 14.4, "temp_f": 57.9, "is_day": 1, "condition": {"text": "Partly cloudy", "icon": "//cdn.weatherapi.com/weather/64x64/day/116.png", "code": 1003}, "wind_mph": 13.2, "wind_kph": 21.2, "wind_degree": 265, "wind_dir": "W", "pressure_mb": 1017.0, "pressure_in": 30.03, "precip_mm": 0.01, "precip_in": 0.0, "humidity": 77, "cloud": 75, "feelslike_c": 12.8, "feelslike_f": 55.1, "windchill_c": 13.0, "windchill_f": 55.4, "heatindex_c": 14.5, "heatindex_f": 58.2, "dewpoint_c": 7.3, "dewpoint_f": 45.2, "vis_km": 10.0, "vis_miles": 6.0, "uv": 1.4, "gust_mph": 15.2, "gust_kph": 24.4}}'
def: WEATHER
parser: json
contribute: []

- model: replicate/ibm-granite/granite-3.0-8b-instruct
input: |
Explain the weather from the following JSON:
Expand Down
12 changes: 5 additions & 7 deletions examples/weather/weather.pdl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
description: Using a weather API and LLM to make a small weather app
text:
- read:
def: QUERY
message: "Ask a query: "
contribute: []
- def: QUERY
text: "What is the weather in Madrid?\n"
- model: replicate/ibm-granite/granite-3.0-8b-instruct
input: |
Extract the location from the question.
Expand All @@ -21,12 +19,12 @@ text:
- lang: python
code: |
import requests
response = requests.get('https://api.weatherapi.com/v1/current.json?key=cf601276764642cb96224947230712&q=${ LOCATION }')
result = response.content
#response = requests.get('https://api.weatherapi.com/v1/current.json?key==XYZ=${ LOCATION }')
#Mock response:
result = '{"location": {"name": "Madrid", "region": "Madrid", "country": "Spain", "lat": 40.4, "lon": -3.6833, "tz_id": "Europe/Madrid", "localtime_epoch": 1732543839, "localtime": "2024-11-25 15:10"}, "current": {"last_updated_epoch": 1732543200, "last_updated": "2024-11-25 15:00", "temp_c": 14.4, "temp_f": 57.9, "is_day": 1, "condition": {"text": "Partly cloudy", "icon": "//cdn.weatherapi.com/weather/64x64/day/116.png", "code": 1003}, "wind_mph": 13.2, "wind_kph": 21.2, "wind_degree": 265, "wind_dir": "W", "pressure_mb": 1017.0, "pressure_in": 30.03, "precip_mm": 0.01, "precip_in": 0.0, "humidity": 77, "cloud": 75, "feelslike_c": 12.8, "feelslike_f": 55.1, "windchill_c": 13.0, "windchill_f": 55.4, "heatindex_c": 14.5, "heatindex_f": 58.2, "dewpoint_c": 7.3, "dewpoint_f": 45.2, "vis_km": 10.0, "vis_miles": 6.0, "uv": 1.4, "gust_mph": 15.2, "gust_kph": 24.4}}'
def: WEATHER
parser: json
contribute: []

- model: replicate/ibm-granite/granite-3.0-8b-instruct
input: |
Explain the weather from the following JSON:
Expand Down