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.6.tar.gz
(3.6 kB
view details)
Built Distribution
File details
Details for the file dify-client-0.1.6.tar.gz
.
File metadata
- Download URL: dify-client-0.1.6.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf5e02fd6d357b3497458d91bb5ee235e3ecfe9a9202e46307aa0e979b06c2e3 |
|
MD5 | 9eb7c14e92c2a929c6feeb88f07c8404 |
|
BLAKE2b-256 | 53d8dfa347b97d642134e50a824df68e932ca2081877b4c4464aa591a73f7ad5 |
File details
Details for the file dify_client-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: dify_client-0.1.6-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 978dff7f80500224d77b66a857f50737ec81e08447ac3e58edc4ec732a1ae5d1 |
|
MD5 | 787b295f84e030b0cbdf40c0c1fcea1f |
|
BLAKE2b-256 | 68e350601cbb8b95d6e8f9a5e12161fbc27fa3d23de84734590c41b1db69972c |