Skip to content

Commit 2471ef7

Browse files
authored
modified weather example (#196)
Signed-off-by: Mandana Vaziri <[email protected]>
1 parent 3f62823 commit 2471ef7

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

docs/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ PDL programs can contain calls to REST APIs with Python code. Consider a simple
328328
--8<-- "./examples/tutorial/calling_apis.pdl"
329329
```
330330

331-
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.
331+
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.
332332

333333

334334
## Data Block

examples/demo/3-weather.pdl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
description: Using a weather API and LLM to make a small weather app
22
text:
3-
- read:
4-
def: QUERY
5-
message: "Ask a query: "
6-
contribute: []
3+
- def: QUERY
4+
text: "What is the weather in Madrid?\n"
75
- model: replicate/ibm-granite/granite-3.0-8b-instruct
86
input: |
97
Extract the location from the question.
@@ -21,12 +19,12 @@ text:
2119
- lang: python
2220
code: |
2321
import requests
24-
response = requests.get('https://api.weatherapi.com/v1/current.json?key=cf601276764642cb96224947230712&q=${ LOCATION }')
25-
result = response.content
22+
#response = requests.get('https://api.weatherapi.com/v1/current.json?key==XYZ=${ LOCATION }')
23+
#Mock response:
24+
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}}'
2625
def: WEATHER
2726
parser: json
2827
contribute: []
29-
3028
- model: replicate/ibm-granite/granite-3.0-8b-instruct
3129
input: |
3230
Explain the weather from the following JSON:

examples/tutorial/calling_apis.pdl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
description: Using a weather API and LLM to make a small weather app
22
text:
3-
- read:
4-
def: QUERY
5-
message: "Ask a query: "
6-
contribute: []
3+
- def: QUERY
4+
text: "What is the weather in Madrid?\n"
75
- model: replicate/ibm-granite/granite-3.0-8b-instruct
86
input: |
97
Extract the location from the question.
@@ -21,12 +19,12 @@ text:
2119
- lang: python
2220
code: |
2321
import requests
24-
response = requests.get('https://api.weatherapi.com/v1/current.json?key=cf601276764642cb96224947230712&q=${ LOCATION }')
25-
result = response.content
22+
#response = requests.get('https://api.weatherapi.com/v1/current.json?key==XYZ=${ LOCATION }')
23+
#Mock response:
24+
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}}'
2625
def: WEATHER
2726
parser: json
2827
contribute: []
29-
3028
- model: replicate/ibm-granite/granite-3.0-8b-instruct
3129
input: |
3230
Explain the weather from the following JSON:

examples/weather/weather.pdl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
description: Using a weather API and LLM to make a small weather app
22
text:
3-
- read:
4-
def: QUERY
5-
message: "Ask a query: "
6-
contribute: []
3+
- def: QUERY
4+
text: "What is the weather in Madrid?\n"
75
- model: replicate/ibm-granite/granite-3.0-8b-instruct
86
input: |
97
Extract the location from the question.
@@ -21,12 +19,12 @@ text:
2119
- lang: python
2220
code: |
2321
import requests
24-
response = requests.get('https://api.weatherapi.com/v1/current.json?key=cf601276764642cb96224947230712&q=${ LOCATION }')
25-
result = response.content
22+
#response = requests.get('https://api.weatherapi.com/v1/current.json?key==XYZ=${ LOCATION }')
23+
#Mock response:
24+
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}}'
2625
def: WEATHER
2726
parser: json
2827
contribute: []
29-
3028
- model: replicate/ibm-granite/granite-3.0-8b-instruct
3129
input: |
3230
Explain the weather from the following JSON:

0 commit comments

Comments
 (0)