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

  1. llm_config.yaml
models:
  gpt-4o:
    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"
  1. llm_keys.yaml
keys:
  openai_key1: "xx"
  openai_key2: "xx"
  anthropic_key1: "your_anthropic_api_key_1"
  anthropic_key2: "your_anthropic_api_key_2"
  1. code
from hwhkit.llm.config import load_models_from_config


async def main():
    models = load_models_from_config(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.0.tar.gz (6.6 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.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hwhkit-1.0.0.tar.gz
  • Upload date:
  • Size: 6.6 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.0.tar.gz
Algorithm Hash digest
SHA256 48c0684f24ceee443608f136f96371f1b9396ef0413ae8965d7b1816a1c956af
MD5 e792b640f2f6aae245104f717c29fdab
BLAKE2b-256 6e4ed49ac7535bbfa29ad662a19cef6eeae2ebdba1d236fe483c6ea0add17ceb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hwhkit-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2c19b020fd939a26dec31c5b140e59378657e2a8e44b96df03e0904496177bb
MD5 1dc131e438694f8c7e236c5880fbd3d6
BLAKE2b-256 2c0e6d41f0df5bc03f0d2ba055e01709a3b005b441a57c0556e5c35ace92861f

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