Last active
March 20, 2025 11:07
-
-
Save OhkuboSGMS/0dae818563d04616b4cadf9149ecc7d4 to your computer and use it in GitHub Desktop.
run self-hosted dify from client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pprint import pprint | |
| import requests | |
| api_key = "xxx" | |
| base_url = "http://dify.local/v1" | |
| def _send_request( | |
| api_key, | |
| base_url, | |
| endpoint, | |
| method, | |
| inputs, | |
| response_mode="blocking", | |
| user=None, | |
| ): | |
| headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} | |
| data = { | |
| "inputs": inputs, | |
| "user": user, | |
| "response_mode": response_mode, | |
| } | |
| url = f"{base_url}{endpoint}" | |
| response = requests.request(method, url, json=data, headers=headers) | |
| return response | |
| completion_response = _send_request( | |
| api_key, | |
| base_url, | |
| endpoint="/workflows/run", | |
| method="POST", | |
| inputs={ | |
| "query": "家庭用ゲームに関するニュース", | |
| "n_pickup": 5, | |
| }, | |
| response_mode="blocking", | |
| user="user_id", | |
| ) | |
| completion_response.raise_for_status() | |
| result = completion_response.json() | |
| pprint(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment