|
18 | 18 | from facebook_business.adobjects.adaccount import AdAccount |
19 | 19 | from facebook_business.exceptions import FacebookRequestError |
20 | 20 | import google_ai |
| 21 | +import json |
21 | 22 |
|
22 | 23 | load_dotenv(dotenv_path=".env") |
23 | 24 |
|
@@ -1296,6 +1297,51 @@ def digital_repair_assistance_endpoint(): |
1296 | 1297 | return jsonify({"status": "success", "message": message}) |
1297 | 1298 |
|
1298 | 1299 |
|
| 1300 | +@app.route('/api/v1/generic/assistance', methods=['POST']) |
| 1301 | +@require_api_key |
| 1302 | +def generic_assistance_endpoint(): |
| 1303 | + data = request.get_json() |
| 1304 | + system_message = data.get('system_message') |
| 1305 | + prompt = data.get('prompt') |
| 1306 | + if not all([system_message, prompt]): |
| 1307 | + return jsonify({"error": _("system_message and prompt are required")}), 400 |
| 1308 | + message = google_ai.generic_ai_service(system_message, prompt) |
| 1309 | + return jsonify({"status": "success", "message": message}) |
| 1310 | + |
| 1311 | + |
| 1312 | +@app.route('/api/v1/langflow/execute', methods=['POST']) |
| 1313 | +@require_api_key |
| 1314 | +def execute_langflow_endpoint(): |
| 1315 | + data = request.get_json() |
| 1316 | + flow_name = data.get('flow_name', 'sample_flow') |
| 1317 | + prompt = data.get('prompt') |
| 1318 | + if not prompt: |
| 1319 | + return jsonify({"error": _("Prompt is required")}), 400 |
| 1320 | + |
| 1321 | + # In a real scenario, we would use langflow's run_flow or similar |
| 1322 | + # For this task, we'll simulate the execution or load the flow config |
| 1323 | + try: |
| 1324 | + flow_path = os.path.join('langflow_flows', f'{flow_name}.json') |
| 1325 | + if not os.path.exists(flow_path): |
| 1326 | + return jsonify({"error": _("Flow not found")}), 404 |
| 1327 | + |
| 1328 | + with open(flow_path, 'r') as f: |
| 1329 | + flow_config = json.load(f) |
| 1330 | + |
| 1331 | + # Simulate execution using LangChain (as Langflow is built on LangChain) |
| 1332 | + message = google_ai.generic_ai_service(f"Executing Langflow: {flow_config.get('name')}", prompt) |
| 1333 | + return jsonify({ |
| 1334 | + "status": "success", |
| 1335 | + "message": message, |
| 1336 | + "flow_info": { |
| 1337 | + "name": flow_config.get('name'), |
| 1338 | + "description": flow_config.get('description') |
| 1339 | + } |
| 1340 | + }) |
| 1341 | + except Exception as e: |
| 1342 | + return jsonify({"error": str(e)}), 500 |
| 1343 | + |
| 1344 | + |
1299 | 1345 | @app.route('/api/v1/translate', methods=['POST']) |
1300 | 1346 | @require_api_key |
1301 | 1347 | def translate_endpoint(): |
|
0 commit comments