Skip to main content

A package for interacting with the Dify Service-API

Reason this release was yanked:

Yanked due to incompatible Python version requirement; minimum Python version was too low to support newer features.

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 blocking response_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 streaming response_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


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.1.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dify_oapi-0.0.1-py3-none-any.whl (82.6 kB view details)

Uploaded Python 3

File details

Details for the file dify_oapi-0.0.1.tar.gz.

File metadata

  • Download URL: dify_oapi-0.0.1.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.9

File hashes

Hashes for dify_oapi-0.0.1.tar.gz
Algorithm Hash digest
SHA256 219014a54f5d14a4ddb8bce10120c7c92fb86b08078e91f771bce9f9c297212d
MD5 51fef078362f7d072dafde6bf8d80e1f
BLAKE2b-256 cc9ae3f9999385586573e2322e962a209927e9ecdc1c25788cd084c86a208ed5

See more details on using hashes here.

File details

Details for the file dify_oapi-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: dify_oapi-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 82.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.9

File hashes

Hashes for dify_oapi-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40f5041bd33ec4f12642ff98070ad839428dae65772bc61acbd7a5205a27a9c3
MD5 f6763adffbecb77806aacf1457f6777c
BLAKE2b-256 9f9e3a884eab89a97f2fdacaad8360ac1738121b06a08fdb4f61039ea927bb70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page