Skip to content

Commit af479bc

Browse files
committed
fix(flowise): minor cleanup and finalize of integration hook
1 parent cb5a16a commit af479bc

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

examples/pipelines/integrations/flowise_pipeline.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
22
title: FlowiseAI Integration
3-
author: Claude
4-
author_url: https://anthropic.com
3+
author: Eric Zavesky
4+
author_url: https://github.com/ezavesky
55
git_url: https://github.com/open-webui/pipelines/
6-
description: Access FlowiseAI endpoints with customizable flows
6+
description: Access FlowiseAI endpoints via chat integration
77
required_open_webui_version: 0.4.3
88
requirements: requests,flowise>=1.0.4
99
version: 0.4.3
@@ -85,6 +85,33 @@ def __init__(self):
8585
self.flows = {}
8686
self.update_flows()
8787

88+
def get_flow_details(self, flow_id: str) -> Optional[dict]:
89+
"""
90+
Fetch flow details from the FlowiseAI API
91+
92+
Args:
93+
flow_id (str): The ID of the flow to fetch
94+
95+
Returns:
96+
Optional[dict]: Flow details if successful, None if failed
97+
"""
98+
try:
99+
api_url = f"{self.valves.FLOWISE_BASE_URL.rstrip('/')}/api/v1/chatflows/{flow_id}"
100+
headers = {"Authorization": f"Bearer {self.valves.FLOWISE_API_KEY}"}
101+
102+
response = requests.get(api_url, headers=headers)
103+
104+
if response.status_code == 200:
105+
data = response.json()
106+
return data
107+
else:
108+
logger.error(f"Error fetching flow details: Status {response.status_code}")
109+
return None
110+
111+
except Exception as e:
112+
logger.error(f"Error fetching flow details: {str(e)}")
113+
return None
114+
88115
def update_flows(self):
89116
"""Update the flows dictionary based on the current valve settings"""
90117
self.flows = {}
@@ -98,9 +125,18 @@ def update_flows(self):
98125
flow_name = getattr(self.valves, f"FLOW_{i}_NAME", None)
99126

100127
if enabled and flow_id and flow_name:
101-
self.flows[flow_name.lower()] = flow_id
128+
# Fetch flow details from API
129+
flow_details = self.get_flow_details(flow_id)
130+
api_name = flow_details.get('name', 'Unknown') if flow_details else 'Unknown'
131+
132+
# Store both names in the flows dictionary
133+
self.flows[flow_name.lower()] = {
134+
'id': flow_id,
135+
'brief_name': flow_name,
136+
'api_name': api_name
137+
}
102138

103-
logger.info(f"Updated flows: {list(self.flows.keys())}")
139+
logger.info(f"Updated flows: {[{k: v['api_name']} for k, v in self.flows.items()]}")
104140

105141
async def on_startup(self):
106142
"""Called when the server is started"""
@@ -202,8 +238,8 @@ def pipe(
202238
else:
203239
return no_flows_msg
204240

205-
flows_list = "\n".join([f"- {flow}" for flow in available_flows])
206-
help_msg = f"Please specify a flow using the format: flow_name: your query\n\nAvailable flows:\n{flows_list}"
241+
flows_list = "\n".join([f"- flow_name: {flow} (description:{self.flows[flow]['api_name']})" for flow in available_flows])
242+
help_msg = f"Please specify a flow using the format: <flow_name>: <your query>\n\nAvailable flows:\n{flows_list}"
207243

208244
if flow_name is None:
209245
help_msg = "No flow specified. " + help_msg
@@ -217,7 +253,7 @@ def pipe(
217253
return help_msg
218254

219255
# Get the flow ID from the map
220-
flow_id = self.flows[flow_name]
256+
flow_id = self.flows[flow_name]['id']
221257

222258
if streaming:
223259
yield from self.stream_retrieve(flow_id, flow_name, query, dt_start)

0 commit comments

Comments
 (0)