Refactor Python SDK and Construct dify_oapi to Improve Development Efficiency #6528

Closed
opened 2026-02-21 18:16:08 -05:00 by yindo · 4 comments
Owner

Originally created by @QiMington on GitHub (Nov 4, 2024).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

Is this request related to a challenge you are facing?

When I want to call the dify backend app from other backends, I find it difficult to know the types of request parameters and response parameters according to the original code logic, which makes it difficult to construct an interface request.

What is the feature you'd like to see?

The feature I would like to see is the corresponding request object and request body object being built through a builder, and the corresponding response data can be automatically structured into an object through pydantic.

How will this feature improve your workflow / experience?

After this, constructing request objects and reading response objects will become very easy and simple. The code hints from the editor will help me quickly build and read, thereby improving my development efficiency.

Can you help with this feature?

Yes, I have basically implemented this feature and am willing to submit my code.

2. Additional context or comments

A simple demo


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("app-xxx").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()

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @QiMington on GitHub (Nov 4, 2024). ### Self Checks - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### 1. Is this request related to a challenge you're experiencing? Tell me about your story. # Is this request related to a challenge you are facing? When I want to call the dify backend app from other backends, I find it difficult to know the types of request parameters and response parameters according to the original code logic, which makes it difficult to construct an interface request. # What is the feature you'd like to see? The feature I would like to see is the corresponding request object and request body object being built through a builder, and the corresponding response data can be automatically structured into an object through pydantic. # How will this feature improve your workflow / experience? After this, constructing request objects and reading response objects will become very easy and simple. The code hints from the editor will help me quickly build and read, thereby improving my development efficiency. # Can you help with this feature? Yes, I have basically implemented this feature and am willing to submit my code. ### 2. Additional context or comments A simple demo ```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("app-xxx").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() ``` ### 3. Can you help us with this feature? - [X] I am interested in contributing to this feature.
yindo added the 💪 enhancement label 2026-02-21 18:16:08 -05:00
yindo closed this issue 2026-02-21 18:16:08 -05:00
Author
Owner

@crazywoola commented on GitHub (Nov 4, 2024):

Please feel free to submit the SDK

@crazywoola commented on GitHub (Nov 4, 2024): Please feel free to submit the SDK
Author
Owner

@dosubot[bot] commented on GitHub (Dec 5, 2024):

Hi, @QiMington. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • You suggested a refactor of the Python SDK to enhance development efficiency by introducing dify_oapi.
  • The refactor involves using a builder pattern and Pydantic for automatic structuring.
  • You have implemented the feature and are ready to submit the code.
  • @crazywoola has encouraged you to submit the SDK.

Next Steps

  • Please let us know if this issue is still relevant to the latest version of the Dify repository by commenting here.
  • If there is no further activity, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Dec 5, 2024): Hi, @QiMington. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog. I'm marking this issue as stale. **Issue Summary** - You suggested a refactor of the Python SDK to enhance development efficiency by introducing `dify_oapi`. - The refactor involves using a builder pattern and Pydantic for automatic structuring. - You have implemented the feature and are ready to submit the code. - @crazywoola has encouraged you to submit the SDK. **Next Steps** - Please let us know if this issue is still relevant to the latest version of the Dify repository by commenting here. - If there is no further activity, this issue will be automatically closed in 15 days. Thank you for your understanding and contribution!
Author
Owner

@QiMington commented on GitHub (Dec 5, 2024):

Hi, @QiMington. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • You suggested a refactor of the Python SDK to enhance development efficiency by introducing dify_oapi.
  • The refactor involves using a builder pattern and Pydantic for automatic structuring.
  • You have implemented the feature and are ready to submit the code.
  • @crazywoola has encouraged you to submit the SDK.

Next Steps

  • Please let us know if this issue is still relevant to the latest version of the Dify repository by commenting here.
  • If there is no further activity, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

Yes, it is still compitable to v0.13.1.

@QiMington commented on GitHub (Dec 5, 2024): > Hi, @QiMington. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog. I'm marking this issue as stale. > > **Issue Summary** > > * You suggested a refactor of the Python SDK to enhance development efficiency by introducing `dify_oapi`. > * The refactor involves using a builder pattern and Pydantic for automatic structuring. > * You have implemented the feature and are ready to submit the code. > * @crazywoola has encouraged you to submit the SDK. > > **Next Steps** > > * Please let us know if this issue is still relevant to the latest version of the Dify repository by commenting here. > * If there is no further activity, this issue will be automatically closed in 15 days. > > Thank you for your understanding and contribution! Yes, it is still compitable to v0.13.1.
Author
Owner

@dosubot[bot] commented on GitHub (Dec 5, 2024):

@takatost, the user has confirmed that the refactor of the Python SDK to enhance development efficiency is still compatible with v0.13.1 and is ready for submission. Could you please assist them with this issue?

@dosubot[bot] commented on GitHub (Dec 5, 2024): @takatost, the user has confirmed that the refactor of the Python SDK to enhance development efficiency is still compatible with v0.13.1 and is ready for submission. Could you please assist them with this issue?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6528