Spaces:
Sleeping
Sleeping
File size: 6,012 Bytes
05c5ed5 | 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | import { DBEdge, DBNode } from "app-types/workflow";
import { generateUUID } from "lib/utils";
const INPUT_ID = generateUUID();
const OUTPUT_ID = generateUUID();
const NOTE_ID = generateUUID();
const HTTP_ID = generateUUID();
const LLM_ID = generateUUID();
export const getWeatherNodes: Partial<DBNode>[] = [
{
id: INPUT_ID,
kind: "input",
name: "INPUT",
description: "Collect story requirements and preferences from user",
uiConfig: {
position: { x: 0, y: 0 },
type: "default",
},
nodeConfig: {
kind: "input",
outputSchema: {
type: "object",
properties: {
region: { type: "string" },
},
required: ["region"],
},
},
},
{
id: HTTP_ID,
kind: "http",
name: "WEATHER API",
description: "Get weather data from the API",
uiConfig: {
position: { x: 720, y: 0 },
type: "default",
},
nodeConfig: {
kind: "http",
outputSchema: {
type: "object",
properties: {
response: {
type: "object",
properties: {
status: { type: "number" },
statusText: { type: "string" },
ok: { type: "boolean" },
headers: { type: "object" },
body: { type: "string" },
duration: { type: "number" },
size: { type: "number" },
},
},
},
},
method: "GET",
headers: [],
query: [
{ key: "current", value: "temperature_2m" },
{ key: "hourly", value: "temperature_2m" },
{ key: "timezone", value: "auto" },
{ key: "daily", value: "sunrise,sunset" },
{
key: "latitude",
value: { nodeId: LLM_ID, path: ["answer", "latitude"] },
},
{
key: "longitude",
value: { nodeId: LLM_ID, path: ["answer", "longitude"] },
},
],
timeout: 30000,
url: "https://api.open-meteo.com/v1/forecast",
},
},
{
id: LLM_ID,
kind: "llm",
name: "LLM",
description: "Get latitude and longitude from the LLM",
uiConfig: {
position: { x: 360, y: 0 },
type: "default",
},
nodeConfig: {
kind: "llm",
outputSchema: {
type: "object",
properties: {
answer: {
type: "object",
properties: {
latitude: {
type: "number",
description: "Geographical latitude of the location",
},
longitude: {
type: "number",
description: "Geographical longitude of the location",
},
},
},
},
},
messages: [
{
role: "user",
content: {
type: "doc",
content: [
{
type: "paragraph",
content: [
{
type: "text",
text: "What are the latitude and longitude of ",
},
{
type: "mention",
attrs: {
id: "e8d2314a-f81b-41e3-91ff-f235486a62f3",
label: `{"nodeId":"${INPUT_ID}","path":["region"]}`,
},
},
],
},
],
},
},
],
model: { provider: "openai", model: "4o" },
},
},
{
id: NOTE_ID,
kind: "note",
name: "NOTE",
description: `# 🌦️ Regional Weather Lookup Workflow
This workflow retrieves weather information for a specified region by chaining together an LLM for geocoding and an HTTP request to a public weather API.
### ➡️ Execution Pipeline
1. **Input Region**: A user provides a region name (e.g., "Seoul" or "Tokyo").
2. **Find Coordinates (LLM)**: The LLM converts the text-based region name into geographical latitude and longitude coordinates.
3. **Fetch Weather API (HTTP)**: The workflow uses these coordinates to call the Open-Meteo weather API and request the current forecast.
4. **Return Weather Data (Output)**: The raw JSON response from the weather API is passed on as the final result of the workflow.
---
### 🔬 Node Output Examples
Here are examples of the output structure for the key nodes in this workflow.
#### 📍 **Find Coordinates (LLM) Output**
This node outputs the latitude and longitude in a structured object.
\`\`\`json
{
"answer": {
"latitude": 37.5665,
"longitude": 126.9780
}
}
\`\`\`
#### ☁️ **Fetch Weather API (HTTP) Output**
This node returns the full HTTP response. The actual weather data is located inside the \`body\` field as a JSON string.
\`\`\`json
{
"response": {
"status": 200,
"ok": true,
"body": "{\"latitude\":37.56,\"longitude\":126.97,\"current\":{\"time\":\"2023-10-27T12:00\",\"temperature_2m\":15.4},\"daily\":{\"sunrise\":[\"2023-10-27T06:45\"],\"sunset\":[\"2023-10-27T17:40\"]}}",
"duration": 150
}
}
\`\`\`
`,
uiConfig: {
position: {
x: -569.8790292584229,
y: -731.5434457770423,
},
type: "default",
},
nodeConfig: {
kind: "note",
outputSchema: { type: "object", properties: {} },
},
},
{
id: OUTPUT_ID,
kind: "output",
name: "OUTPUT",
description: "Output the weather data",
uiConfig: {
position: { x: 1080, y: 0 },
type: "default",
},
nodeConfig: {
kind: "output",
outputSchema: { type: "object", properties: {} },
outputData: [
{
key: "result",
source: { nodeId: HTTP_ID, path: ["response", "body"] },
},
],
},
},
];
export const getWeatherEdges: Partial<DBEdge>[] = [
{
source: INPUT_ID,
target: LLM_ID,
uiConfig: {},
},
{
source: LLM_ID,
target: HTTP_ID,
uiConfig: {},
},
{
source: HTTP_ID,
target: OUTPUT_ID,
uiConfig: {},
},
];
|