Spaces:
Runtime error
Runtime error
File size: 6,610 Bytes
2ef1d57 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"from langchain.chains import APIChain\n",
"from langchain.prompts.prompt import PromptTemplate\n",
"\n",
"\n",
"from langchain.llms import OpenAI\n",
"\n",
"llm = OpenAI(temperature=0)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"from langchain.chains.api import open_meteo_docs\n",
"chain_new = APIChain.from_llm_and_api_docs(llm, open_meteo_docs.OPEN_METEO_DOCS, verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new APIChain chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mhttps://api.open-meteo.com/v1/forecast?latitude=39.9042&longitude=116.4074&hourly=temperature_2m&temperature_unit=celsius&timezone=auto\u001b[0m\n",
"\u001b[33;1m\u001b[1;3m{\"latitude\":39.875,\"longitude\":116.375,\"generationtime_ms\":0.6901025772094727,\"utc_offset_seconds\":28800,\"timezone\":\"Asia/Shanghai\",\"timezone_abbreviation\":\"CST\",\"elevation\":47.0,\"hourly_units\":{\"time\":\"iso8601\",\"temperature_2m\":\"°C\"},\"hourly\":{\"time\":[\"2023-05-04T00:00\",\"2023-05-04T01:00\",\"2023-05-04T02:00\",\"2023-05-04T03:00\",\"2023-05-04T04:00\",\"2023-05-04T05:00\",\"2023-05-04T06:00\",\"2023-05-04T07:00\",\"2023-05-04T08:00\",\"2023-05-04T09:00\",\"2023-05-04T10:00\",\"2023-05-04T11:00\",\"2023-05-04T12:00\",\"2023-05-04T13:00\",\"2023-05-04T14:00\",\"2023-05-04T15:00\",\"2023-05-04T16:00\",\"2023-05-04T17:00\",\"2023-05-04T18:00\",\"2023-05-04T19:00\",\"2023-05-04T20:00\",\"2023-05-04T21:00\",\"2023-05-04T22:00\",\"2023-05-04T23:00\",\"2023-05-05T00:00\",\"2023-05-05T01:00\",\"2023-05-05T02:00\",\"2023-05-05T03:00\",\"2023-05-05T04:00\",\"2023-05-05T05:00\",\"2023-05-05T06:00\",\"2023-05-05T07:00\",\"2023-05-05T08:00\",\"2023-05-05T09:00\",\"2023-05-05T10:00\",\"2023-05-05T11:00\",\"2023-05-05T12:00\",\"2023-05-05T13:00\",\"2023-05-05T14:00\",\"2023-05-05T15:00\",\"2023-05-05T16:00\",\"2023-05-05T17:00\",\"2023-05-05T18:00\",\"2023-05-05T19:00\",\"2023-05-05T20:00\",\"2023-05-05T21:00\",\"2023-05-05T22:00\",\"2023-05-05T23:00\",\"2023-05-06T00:00\",\"2023-05-06T01:00\",\"2023-05-06T02:00\",\"2023-05-06T03:00\",\"2023-05-06T04:00\",\"2023-05-06T05:00\",\"2023-05-06T06:00\",\"2023-05-06T07:00\",\"2023-05-06T08:00\",\"2023-05-06T09:00\",\"2023-05-06T10:00\",\"2023-05-06T11:00\",\"2023-05-06T12:00\",\"2023-05-06T13:00\",\"2023-05-06T14:00\",\"2023-05-06T15:00\",\"2023-05-06T16:00\",\"2023-05-06T17:00\",\"2023-05-06T18:00\",\"2023-05-06T19:00\",\"2023-05-06T20:00\",\"2023-05-06T21:00\",\"2023-05-06T22:00\",\"2023-05-06T23:00\",\"2023-05-07T00:00\",\"2023-05-07T01:00\",\"2023-05-07T02:00\",\"2023-05-07T03:00\",\"2023-05-07T04:00\",\"2023-05-07T05:00\",\"2023-05-07T06:00\",\"2023-05-07T07:00\",\"2023-05-07T08:00\",\"2023-05-07T09:00\",\"2023-05-07T10:00\",\"2023-05-07T11:00\",\"2023-05-07T12:00\",\"2023-05-07T13:00\",\"2023-05-07T14:00\",\"2023-05-07T15:00\",\"2023-05-07T16:00\",\"2023-05-07T17:00\",\"2023-05-07T18:00\",\"2023-05-07T19:00\",\"2023-05-07T20:00\",\"2023-05-07T21:00\",\"2023-05-07T22:00\",\"2023-05-07T23:00\",\"2023-05-08T00:00\",\"2023-05-08T01:00\",\"2023-05-08T02:00\",\"2023-05-08T03:00\",\"2023-05-08T04:00\",\"2023-05-08T05:00\",\"2023-05-08T06:00\",\"2023-05-08T07:00\",\"2023-05-08T08:00\",\"2023-05-08T09:00\",\"2023-05-08T10:00\",\"2023-05-08T11:00\",\"2023-05-08T12:00\",\"2023-05-08T13:00\",\"2023-05-08T14:00\",\"2023-05-08T15:00\",\"2023-05-08T16:00\",\"2023-05-08T17:00\",\"2023-05-08T18:00\",\"2023-05-08T19:00\",\"2023-05-08T20:00\",\"2023-05-08T21:00\",\"2023-05-08T22:00\",\"2023-05-08T23:00\",\"2023-05-09T00:00\",\"2023-05-09T01:00\",\"2023-05-09T02:00\",\"2023-05-09T03:00\",\"2023-05-09T04:00\",\"2023-05-09T05:00\",\"2023-05-09T06:00\",\"2023-05-09T07:00\",\"2023-05-09T08:00\",\"2023-05-09T09:00\",\"2023-05-09T10:00\",\"2023-05-09T11:00\",\"2023-05-09T12:00\",\"2023-05-09T13:00\",\"2023-05-09T14:00\",\"2023-05-09T15:00\",\"2023-05-09T16:00\",\"2023-05-09T17:00\",\"2023-05-09T18:00\",\"2023-05-09T19:00\",\"2023-05-09T20:00\",\"2023-05-09T21:00\",\"2023-05-09T22:00\",\"2023-05-09T23:00\",\"2023-05-10T00:00\",\"2023-05-10T01:00\",\"2023-05-10T02:00\",\"2023-05-10T03:00\",\"2023-05-10T04:00\",\"2023-05-10T05:00\",\"2023-05-10T06:00\",\"2023-05-10T07:00\",\"2023-05-10T08:00\",\"2023-05-10T09:00\",\"2023-05-10T10:00\",\"2023-05-10T11:00\",\"2023-05-10T12:00\",\"2023-05-10T13:00\",\"2023-05-10T14:00\",\"2023-05-10T15:00\",\"2023-05-10T16:00\",\"2023-05-10T17:00\",\"2023-05-10T18:00\",\"2023-05-10T19:00\",\"2023-05-10T20:00\",\"2023-05-10T21:00\",\"2023-05-10T22:00\",\"2023-05-10T23:00\"],\"temperature_2m\":[18.3,17.9,17.7,17.5,17.4,17.3,16.9,16.8,17.2,18.5,19.2,20.0,21.2,21.7,19.3,18.2,17.9,17.8,17.4,17.1,17.0,16.9,16.8,16.8,16.8,16.9,16.9,17.0,17.2,17.6,18.2,18.8,18.8,19.2,19.4,19.6,20.4,20.6,21.0,21.0,21.1,20.9,20.4,19.6,18.8,18.3,17.9,17.6,17.3,16.8,16.4,16.1,15.9,15.6,15.4,16.2,17.7,19.7,21.2,22.2,22.6,23.2,23.9,24.2,24.2,24.0,23.4,22.5,21.4,20.7,20.3,19.7,19.0,18.7,18.4,17.8,17.1,16.4,16.0,16.7,17.8,20.2,22.5,23.8,24.7,25.2,25.1,25.1,24.9,24.2,23.4,22.3,20.8,19.8,18.7,17.5,16.9,16.5,16.1,15.7,15.4,15.3,15.4,15.7,16.8,18.6,21.0,23.7,25.0,25.9,26.6,26.6,26.3,25.5,24.7,23.6,22.2,21.3,20.6,19.7,19.2,18.8,18.2,17.7,17.1,16.6,16.6,16.8,17.4,18.2,19.2,20.5,21.6,22.7,23.5,23.2,22.4,21.2,20.2,19.0,17.8,17.3,17.1,16.9,16.6,16.3,16.0,15.8,15.8,15.9,16.2,16.5,17.3,18.3,19.6,21.0,21.7,22.2,22.6,22.8,22.8,22.6,22.2,21.6,20.7,19.8,18.7,17.5]}}\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"' The temperature in Beijing for the next 7 days will range from 15.3°C to 26.6°C.'"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chain_new.run('北京气温多少?')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|