dify-oapi


Namedify-oapi JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/QiMington/dify-oapi
SummaryA package for interacting with the Dify Service-API
upload_time2024-12-06 02:57:23
maintainerNone
docs_urlNone
authorQiMington
requires_python>=3.10
licenseMIT
keywords dify nlp ai language-processing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```python
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

```python
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()
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/QiMington/dify-oapi",
    "name": "dify-oapi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "dify, nlp, ai, language-processing",
    "author": "QiMington",
    "author_email": "qimington@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d0/a0/a84535773d4a88b1de3f528f0d8af2f67170b332cc8d4b0579fb4e5308c2/dify_oapi-0.0.3.tar.gz",
    "platform": null,
    "description": "# dify-oapi\n\nA Dify App Service-API Client, using for build a webapp by request Service-API\n\n## Usage\n\nFirst, install `dify-oapi` python sdk package:\n\n```\npip install dify-oapi\n```\n\nWrite your code with sdk:\n\n- chat generate with `blocking` response_mode\n\n```python\nfrom dify_oapi.api.chat.v1.model.chat_request import ChatRequest\nfrom dify_oapi.api.chat.v1.model.chat_request_body import ChatRequestBody\nfrom dify_oapi.api.chat.v1.model.chat_request_file import ChatRequestFile\nfrom dify_oapi.client import Client\nfrom dify_oapi.core.model.request_option import RequestOption\n\ndef main():\n    client = Client.builder().domain(\"https://api.dify.ai\").build()\n    req_file = (\n        ChatRequestFile.builder()\n        .type(\"image\")\n        .transfer_method(\"remote_url\")\n        .url(\"https://cloud.dify.ai/logo/logo-site.png\")\n        .build()\n    )\n    req_body = (\n        ChatRequestBody.builder()\n        .inputs({})\n        .query(\"What are the specs of the iPhone 13 Pro Max?\")\n        .response_mode(\"blocking\")\n        .conversation_id(\"\")\n        .user(\"abc-123\")\n        .files([req_file])\n        .build()\n    )\n    req = ChatRequest.builder().request_body(req_body).build()\n    req_option = RequestOption.builder().api_key(\"<your-api-key>\").build()\n    response = client.chat.v1.chat.chat(req, req_option, False)\n    # response = await client.chat.v1.chat.achat(req, req_option, False)\n    print(response.success)\n    print(response.code)\n    print(response.msg)\n    print(response.answer)\n\n\nif __name__ == \"__main__\":\n    main()\n\n```\n\n- chat generate with `streaming` response_mode\n\n```python\nfrom dify_oapi.api.chat.v1.model.chat_request import ChatRequest\nfrom dify_oapi.api.chat.v1.model.chat_request_body import ChatRequestBody\nfrom dify_oapi.api.chat.v1.model.chat_request_file import ChatRequestFile\nfrom dify_oapi.client import Client\nfrom dify_oapi.core.model.request_option import RequestOption\n\ndef main():\n    client = Client.builder().domain(\"https://api.dify.ai\").build()\n    req_file = (\n        ChatRequestFile.builder()\n        .type(\"image\")\n        .transfer_method(\"remote_url\")\n        .url(\"https://cloud.dify.ai/logo/logo-site.png\")\n        .build()\n    )\n    req_body = (\n        ChatRequestBody.builder()\n        .inputs({})\n        .query(\"What are the specs of the iPhone 13 Pro Max?\")\n        .response_mode(\"streaming\")\n        .conversation_id(\"\")\n        .user(\"abc-123\")\n        .files([req_file])\n        .build()\n    )\n    req = ChatRequest.builder().request_body(req_body).build()\n    req_option = RequestOption.builder().api_key(\"<your-api-key>\").build()\n    response = client.chat.v1.chat.chat(req, req_option, True)\n    # response = await client.chat.v1.chat.achat(req, req_option, True)\n    for chunk in response:\n        print(chunk)\n\n\nif __name__ == \"__main__\":\n    main()\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A package for interacting with the Dify Service-API",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/QiMington/dify-oapi",
        "Source": "https://github.com/QiMington/dify-oapi"
    },
    "split_keywords": [
        "dify",
        " nlp",
        " ai",
        " language-processing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "98ce91a113d461e9e345318a3af7d0cabc0bc341e59e2e7accd43d78d732d2a7",
                "md5": "26a1e93c44b8b8a11fd8beaae300576e",
                "sha256": "04b546d6496dbdbfb2f7cda483bfdd444cffeb2f6fff851367810a716a837e2c"
            },
            "downloads": -1,
            "filename": "dify_oapi-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "26a1e93c44b8b8a11fd8beaae300576e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 84928,
            "upload_time": "2024-12-06T02:57:21",
            "upload_time_iso_8601": "2024-12-06T02:57:21.477255Z",
            "url": "https://files.pythonhosted.org/packages/98/ce/91a113d461e9e345318a3af7d0cabc0bc341e59e2e7accd43d78d732d2a7/dify_oapi-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d0a0a84535773d4a88b1de3f528f0d8af2f67170b332cc8d4b0579fb4e5308c2",
                "md5": "f522dc12e60ab96a92e0631f07d180b6",
                "sha256": "9cf4bf35a563109dd1a7702744f9d3f2fcc8aded83493675178ae8e968e835ae"
            },
            "downloads": -1,
            "filename": "dify_oapi-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "f522dc12e60ab96a92e0631f07d180b6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 29526,
            "upload_time": "2024-12-06T02:57:23",
            "upload_time_iso_8601": "2024-12-06T02:57:23.336324Z",
            "url": "https://files.pythonhosted.org/packages/d0/a0/a84535773d4a88b1de3f528f0d8af2f67170b332cc8d4b0579fb4e5308c2/dify_oapi-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-06 02:57:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "QiMington",
    "github_project": "dify-oapi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "dify-oapi"
}
        
Elapsed time: 1.19438s