Skip to main content

Packaging tools for own use

Project description

hwhkit

Main function

  • Connection
    • mqtt
  • llm

Connection

Mqtt

from hwhkit import MQTTAsyncClient, mqtt_subscribe
import asyncio

# Config MQTT Client
client = MQTTAsyncClient(broker="broker.hivemq.com", port=1883, client_id="my_client")
client.start()


@mqtt_subscribe("topic/test1")
async def handle_message_1(message: str):
    print(f"Received message from topic 1: {message}")

@mqtt_subscribe("topic/test2")
async def handle_message_2(message: str):
    print(f"Received message from topic 2: {message}")

async def send_messages():
    while True:
        await asyncio.sleep(2)
        client.publish("topic/test1", "Hello from topic 1!")
        client.publish("topic/test2", "Hello from topic 2!")

async def main():
    await asyncio.gather(
        send_messages(),
        asyncio.sleep(3600) 
    )

if __name__ == '__main__':
    asyncio.run(main())

LLM

Three steps to use models

Step1, llm_config.yaml

matter that needs attention

  1. A_custom_model_name used for models.get_model_instance()
  2. A_custom_model_name.name should specify the name of the model supported by the current company
models:
  openai:
    A_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
  1. 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="llm_config.yaml", keys_file="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


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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hwhkit-1.0.2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file hwhkit-1.0.2.tar.gz.

File metadata

  • Download URL: hwhkit-1.0.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.10

File hashes

Hashes for hwhkit-1.0.2.tar.gz
Algorithm Hash digest
SHA256 15e547903482e6df6f57a3f0c3a9065337d618353b73b24e882550061f79e989
MD5 cd959a7d79a2142d0454eb51d8a7445b
BLAKE2b-256 6550d9b3cad6b2b7eaeb11704c67257e80b20a63fb2b75ebbb993bc92c62bc07

See more details on using hashes here.

File details

Details for the file hwhkit-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: hwhkit-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.10

File hashes

Hashes for hwhkit-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7bd6caa629e0193c57d6c7113e346f6fc2b5d586ba68d3e0f76d8c3d07b4fcc5
MD5 75a91eebcc9c7029513e1f14cd3995eb
BLAKE2b-256 2c1521c06eefd34dee186c798c4c2c9acf869930f0543fc7deb9b334993661d9

See more details on using hashes here.

Supported by

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