Skip to main content

A package for interacting with the Dify Service-API

Project description

dify-client

A Dify App Service-API Client, using for build a webapp by request Service-API

Usage

First, install dify-client python sdk package:

pip install dify-client

Write your code with sdk:

  • completion generate with blocking response_mode
import json
from dify_client import CompletionClient

api_key = "your_api_key"

# Initialize CompletionClient
completion_client = CompletionClient(api_key)

# Create Completion Message using CompletionClient
completion_response = completion_client.create_completion_message(inputs={}, query="Hello", response_mode="blocking", user="user_id")
completion_response.raise_for_status()

result = completion_response.text
result = json.loads(result)

print(result.get('answer'))
  • chat generate with streaming response_mode
import json
from dify_client import ChatClient

api_key = "your_api_key"

# Initialize ChatClient
chat_client = ChatClient(api_key)

# Create Chat Message using ChatClient
chat_response = chat_client.create_chat_message(inputs={}, query="Hello", user="user_id", response_mode="streaming")
chat_response.raise_for_status()

for line in chat_response.iter_lines(decode_unicode=True):
    line = line.split('data:', 1)[-1]
    if line.strip():
        line = json.loads(line.strip())
        print(line.get('answer'))
  • Others
import json
from dify_client import ChatClient

api_key = "your_api_key"

# Initialize Client
client = ChatClient(api_key)

# Get App parameters
parameters = client.get_application_parameters(user="user_id")
parameters.raise_for_status()
parameters = json.loads(parameters.text)

print('[parameters]')
print(parameters)

# Get Conversation List (only for chat)
conversations = client.get_conversations(user="user_id")
conversations.raise_for_status()
conversations = json.loads(conversations.text)

print('[conversations]')
print(conversations)

# Get Message List (only for chat)
messages = client.get_conversation_messages(user="user_id", conversation_id="conversation_id")
messages.raise_for_status()
messages = json.loads(messages.text)

print('[messages]')
print(messages)

# Rename Conversation (only for chat)
rename_conversation_response = client.rename_conversation(conversation_id="conversation_id", name="new_name", user="user_id")
rename_conversation_response.raise_for_status()
rename_conversation_result = json.loads(rename_conversation_response.text)

print('[rename result]')
print(rename_conversation_result)

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-client-0.1.7.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

dify_client-0.1.7-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file dify-client-0.1.7.tar.gz.

File metadata

  • Download URL: dify-client-0.1.7.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for dify-client-0.1.7.tar.gz
Algorithm Hash digest
SHA256 aadccc8a8b3337947925e240b21e5b69dabb5968cdca18bb7efeb95d4269469f
MD5 eb7cd649d285034cafb50ad1ffb4aea1
BLAKE2b-256 0a368bf2c3fa95d41a33383d7205184aafc029bb54ab5dd15012e2c3f3e519af

See more details on using hashes here.

File details

Details for the file dify_client-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: dify_client-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for dify_client-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bb69d04cd4f8244c930364cb1fc23021037b6fa2c745951da8bae0c3318c2227
MD5 65c22efe7c73288582da98168ea6bc0a
BLAKE2b-256 d2d99b7d72bb9f632c78d157b73e62ed7375aa758c0c6c4d5908225f0ca10f9c

See more details on using hashes here.

Supported by

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