A package for interacting with the Dify Service-API
Project description
dify-oapi
A Dify App Service-API Client, using for build a webapp by request Service-API
Usage
First, install dify-oapi python sdk package:
pip install dify-oapi
Write your code with sdk:
- chat generate with
blockingresponse_mode
from dify_oapi.api.chat.v1.model.chat_request import ChatRequest
from dify_oapi.api.chat.v1.model.chat_request_body import ChatRequestBody
from dify_oapi.api.chat.v1.model.chat_request_file import ChatRequestFile
from dify_oapi.client import Client
from dify_oapi.core.model.request_option import RequestOption
def main():
client = Client.builder().domain("https://api.dify.ai").build()
req_file = (
ChatRequestFile.builder()
.type("image")
.transfer_method("remote_url")
.url("https://cloud.dify.ai/logo/logo-site.png")
.build()
)
req_body = (
ChatRequestBody.builder()
.inputs({})
.query("What are the specs of the iPhone 13 Pro Max?")
.response_mode("blocking")
.conversation_id("")
.user("abc-123")
.files([req_file])
.build()
)
req = ChatRequest.builder().request_body(req_body).build()
req_option = RequestOption.builder().api_key("<your-api-key>").build()
response = client.chat.v1.chat.chat(req, req_option, False)
# response = await client.chat.v1.chat.achat(req, req_option, False)
print(response.success)
print(response.code)
print(response.msg)
print(response.answer)
if __name__ == "__main__":
main()
- chat generate with
streamingresponse_mode
from dify_oapi.api.chat.v1.model.chat_request import ChatRequest
from dify_oapi.api.chat.v1.model.chat_request_body import ChatRequestBody
from dify_oapi.api.chat.v1.model.chat_request_file import ChatRequestFile
from dify_oapi.client import Client
from dify_oapi.core.model.request_option import RequestOption
def main():
client = Client.builder().domain("https://api.dify.ai").build()
req_file = (
ChatRequestFile.builder()
.type("image")
.transfer_method("remote_url")
.url("https://cloud.dify.ai/logo/logo-site.png")
.build()
)
req_body = (
ChatRequestBody.builder()
.inputs({})
.query("What are the specs of the iPhone 13 Pro Max?")
.response_mode("streaming")
.conversation_id("")
.user("abc-123")
.files([req_file])
.build()
)
req = ChatRequest.builder().request_body(req_body).build()
req_option = RequestOption.builder().api_key("<your-api-key>").build()
response = client.chat.v1.chat.chat(req, req_option, True)
# response = await client.chat.v1.chat.achat(req, req_option, True)
for chunk in response:
print(chunk)
if __name__ == "__main__":
main()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dify_oapi-0.0.15.tar.gz
(35.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dify_oapi-0.0.15.tar.gz.
File metadata
- Download URL: dify_oapi-0.0.15.tar.gz
- Upload date:
- Size: 35.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.15 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5285f42cee6a3b02d6691aeb2ccf3fe7e2559c0fd04d9c2e1257a87b7db0297b
|
|
| MD5 |
5fd0f53e9b2c66c907d8b11a8d769100
|
|
| BLAKE2b-256 |
609b7a520b29097e24d4d4f0f04045f7695f2cb3562801c9b321b5e42195fcaa
|
File details
Details for the file dify_oapi-0.0.15-py3-none-any.whl.
File metadata
- Download URL: dify_oapi-0.0.15-py3-none-any.whl
- Upload date:
- Size: 91.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.15 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84dc2b1659249d69427e57df43ea2ad098a83a7bb786de85d56094b3fa261697
|
|
| MD5 |
b9700d128f8002addd9516d1888e5dd8
|
|
| BLAKE2b-256 |
a764c93e378a11c2d317a39da1880d2cd771f0fcb31da0c4978a9ed0ed6627bf
|