-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMCPTool.METAR.pas
More file actions
75 lines (68 loc) · 2.25 KB
/
MCPTool.METAR.pas
File metadata and controls
75 lines (68 loc) · 2.25 KB
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
(*
MCP Tool: METAR
This unit implements a tool that retrieves METAR weather information for a given station.
Sample response:
{
"content": [
{
"type": "text",
"text": "PARIS-CHARLES DE GAULLE\nLFPG 231130Z 24010KT 210V270 9999 FEW030 18/11 Q1022 NOSIG"
}
],
"isError": false
}
*)
unit MCPTool.METAR;
uses
System.Net, System.Encoding,
Networking.MCP;
type
TMETARTool = class (TMCPTool)
class function Description : String; override;
begin
Result := 'Get a METAR from a station ID';
end;
class function InputSchema : JSONVariant; override;
begin
Result := JSON.Serialize(
record
'type' := 'object';
properties := record
station_id := record
'type' := 'string';
"description" := "ICAO code for the weather station (e.g., LFPG, KJFK)";
end;
end;
required := [ "station_id" ];
end
);
end;
class function Call(params : JSONVariant) : JSONVariant; override;
begin
var dataMetar, dataStation : String;
var stationParam := URLEncodedEncoder.Encode(params.station_id);
var status := HttpQuery.GetData('https://aviationweather.gov/api/data/metar?ids=' + stationParam, dataMetar);
case status of
200 : begin
// prefix with station name to allow the model to correct hallucinations
HttpQuery.GetData('https://aviationweather.gov/api/data/stationinfo?ids=' + stationParam, dataStation);
dataMetar := JSON.Parse(dataStation)[0].site + #10 + dataMetar;
end;
204 : begin
// used for no data by the API, which in our case means invalid station id
dataMetar := 'Invalid station ' + stationParam;
end;
else
dataMetar := 'Request failed with status ' + status.ToString;
end;
Result := JSON.Serialize(record
content := [
record
'type' := 'text';
text := dataMetar;
end
];
isError := False;
end);
end;
end;