Packaging tools for own use
Project description
hwhkit
Main function
- Connection
- mqtt
- llm
Connection
Sync MQTT
import time
import signal
from hwhkit.connection.mqtt.client import MQTTClientManager
def main():
default_topic = "default_topic"
client_id = "test_mqtt_client"
manager = MQTTClientManager(mqtt_config="mqtt_keys.yaml")
manager.create_client(client_id=client_id, broker="broker.emqx.io", port=1883)
manager.start_all_clients()
@manager.subscribe(topic=default_topic)
def handle_message(client, message: str):
print(f"Received message from {client}: {message}")
manager.publish(client_id, default_topic, f"Response from {client}")
time.sleep(4)
manager.publish(client_id=client_id, topic=default_topic, message="Hello from Client2")
signal.pause()
if __name__ == '__main__':
main()
Async MQTT
import asyncio
from hwhkit.connection.mqtt.async_client import MQTTClientManager, MQTTConfig
from hwhkit.utils import logger
async def main():
configs = [
MQTTConfig(client_id="client1", broker="broker.emqx.io", port=1883, username="user", password="pass"),
]
default_topic = "default_topic"
async with MQTTClientManager(mqtt_config="mqtt_keys.yaml") as manager:
for config in configs:
await manager.add_client(config)
@manager.topic_handler(default_topic)
async def topic_key(client, topic, message):
logger.info(f"Received message on {topic} from {client}: {message}")
await manager.publish("client1", default_topic, f"Response from {client}")
await manager.run()
if __name__ == "__main__":
asyncio.run(main())
LLM
Three steps to use models
Step1, llm_config.yaml
matter that needs attention
- custom_model_name used for models.get_model_instance()
- custom_model_name.name should specify the name of the model supported by the current company
models:
openai:
custom_model_name:
name: "gpt-4o"
short_name: "OIG4"
company: "openai"
max_input_token: 8100
max_output_token: 2048
top_p: 0.5
top_k: 1
temperature: 0.5
input_token_fee_pm: 30.0
output_token_fee_pm: 60.0
train_token_fee_pm: 0.0
keys:
- name: "openai_key1"
- name: "openai_key2"
siliconflow:
qw-72b-p:
name: "Qwen/QVQ-72B-Preview"
short_name: "QW-72B-P"
company: "siliconflow"
max_input_token: 8100
max_output_token: 2048
top_p: 0.5
top_k: 1
temperature: 0.5
input_token_fee_pm: 30.0
output_token_fee_pm: 60.0
train_token_fee_pm: 0.0
keys:
- name: "siliconflow_1"
Step2, llm_keys.yaml
- The keys name of the model in llm_config.yaml corresponds to llm_keys.yaml one by one
keys:
openai_key1: "xx"
openai_key2: "xx"
anthropic_key1: "your_anthropic_api_key_1"
anthropic_key2: "your_anthropic_api_key_2"
Step3, load models
from hwhkit.llm.config import load_models_from_yaml
async def main():
models = load_models_from_yaml(config_file="examples/llm_config.yaml", keys_file="examples/llm_keys.yaml")
print(models.list_models())
resp = await models.get_model_instance("gpt-4o").chat("who r u?")
print(resp)
if __name__ == '__main__':
import asyncio
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hwhkit-1.0.10.tar.gz
(15.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
hwhkit-1.0.10-py3-none-any.whl
(29.1 kB
view details)
File details
Details for the file hwhkit-1.0.10.tar.gz.
File metadata
- Download URL: hwhkit-1.0.10.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5df4d53e2a0111ab037258d8cdc086e45ec5cd400c9f318ed9c589bc49a223cc
|
|
| MD5 |
8e1ea1eca60aa960378a1606e61eadb2
|
|
| BLAKE2b-256 |
3539f0db4fedb4f60cda28b94f0c49a7d1d6fe4cf319bc3e6408167ede3e07f9
|
File details
Details for the file hwhkit-1.0.10-py3-none-any.whl.
File metadata
- Download URL: hwhkit-1.0.10-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43efce2c7ec2676d182777c233ea2dde85211e7ef5a64d2aef8bf9ae725af196
|
|
| MD5 |
ae4245f68f76b854b54e784cc70a0529
|
|
| BLAKE2b-256 |
6987f29d4743ce93e20ff49204e2d9278ee8cf984387c24308c4b8432a845808
|