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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dify-client-0.1.8.tar.gz
Algorithm Hash digest
SHA256 26991ed094ac3e945fe407dd7470744eef9daf914d7602a0f7c9340cf3a1ef06
MD5 c4f6e3057ea3354f996dfc3b5565f52e
BLAKE2b-256 343a909bab5184671ce2311453fdfc7ce5462eb422e5e0d234724ea6dbed7128

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dify_client-0.1.8-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.11

File hashes

Hashes for dify_client-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e4de0b5266ae03ab9bb638b9781623a7cc580b42c81d220fcf704672b5c1dbf3
MD5 ddaf8d817a029dc1c6eec3e7665a109d
BLAKE2b-256 de8d24356f58a570221b3b905c57a4fb7ccbea384bcd31b5c51c7c3981129d42

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