mlchain-client
A Mlchain App Service-API Client, using for build a webapp by request Service-API
Usage
First, install mlchain-client python sdk package:
pip install mlchain-client
Write your code with sdk:
- completion generate with
blockingresponse_mode
from mlchain_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": "What's the weather like today?"},
response_mode="blocking", user="user_id")
completion_response.raise_for_status()
result = completion_response.json()
print(result.get('answer'))
- completion using vision model, like gpt-4-vision
from mlchain_client import CompletionClient
api_key = "your_api_key"
# Initialize CompletionClient
completion_client = CompletionClient(api_key)
files = [{
"type": "image",
"transfer_method": "remote_url",
"url": "your_image_url"
}]
# files = [{
# "type": "image",
# "transfer_method": "local_file",
# "upload_file_id": "your_file_id"
# }]
# Create Completion Message using CompletionClient
completion_response = completion_client.create_completion_message(inputs={"query": "Describe the picture."},
response_mode="blocking", user="user_id", files=files)
completion_response.raise_for_status()
result = completion_response.json()
print(result.get('answer'))
- chat generate with
streamingresponse_mode
import json
from mlchain_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'))
- chat using vision model, like gpt-4-vision
from mlchain_client import ChatClient
api_key = "your_api_key"
# Initialize ChatClient
chat_client = ChatClient(api_key)
files = [{
"type": "image",
"transfer_method": "remote_url",
"url": "your_image_url"
}]
# files = [{
# "type": "image",
# "transfer_method": "local_file",
# "upload_file_id": "your_file_id"
# }]
# Create Chat Message using ChatClient
chat_response = chat_client.create_chat_message(inputs={}, query="Describe the picture.", user="user_id",
response_mode="blocking", files=files)
chat_response.raise_for_status()
result = chat_response.json()
print(result.get("answer"))
- upload file when using vision model
from mlchain_client import MlchainClient
api_key = "your_api_key"
# Initialize Client
mlchain_client = MlchainClient(api_key)
file_path = "your_image_file_path"
file_name = "panda.jpeg"
mime_type = "image/jpeg"
with open(file_path, "rb") as file:
files = {
"file": (file_name, file, mime_type)
}
response = mlchain_client.file_upload("user_id", files)
result = response.json()
print(f'upload_file_id: {result.get("id")}')
- Others
from mlchain_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()
print('[parameters]')
print(parameters.json())
# Get Conversation List (only for chat)
conversations = client.get_conversations(user="user_id")
conversations.raise_for_status()
print('[conversations]')
print(conversations.json())
# Get Message List (only for chat)
messages = client.get_conversation_messages(user="user_id", conversation_id="conversation_id")
messages.raise_for_status()
print('[messages]')
print(messages.json())
# 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()
print('[rename result]')
print(rename_conversation_response.json())
Metadata
Release files for mlchain-client 0.1.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mlchain_client-0.1.12.tar.gz | 7.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mlchain_client-0.1.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.0 kB
Release files / mlchain_client-0.1.12.tar.gz
| Download URL | mlchain_client-0.1.12.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b3bd41eebf8f99a19507f537ed8b57b00023a6dda7f0097f956f9b5681c564db
|
|
BLAKE2b-256 checksum How to use checksums |
b0e6f627d2655d8bf5f764f17f49fa1b75172628de1cc784697d31e234e1a8c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / mlchain_client-0.1.12-py3-none-any.whl
| Download URL | mlchain_client-0.1.12-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3a22bb520e5123af00f3e0dbfbc7cdeaceb6990305fe1843c0f94577d76d2663
|
|
BLAKE2b-256 checksum How to use checksums |
b982a14a018e44d04fd5ff471b9d6d09e86ce4787abc839fe788911910a249e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Security for mlchain-client 0.1.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.