Skip to main content

Gshield 流式文本安全检测 Python SDK

Project description

Gshield SDK

Gshield 流式文本安全检测 Python SDK,通过 WebSocket 长连接实现 LLM 流式输出的实时内容安全检测。

安装

pip install -e ./gshield-sdk

快速开始

异步用法

import asyncio
from gshield import GshieldStreamClient

async def main():
    async with GshieldStreamClient("ws://localhost:6006/ws/classify") as client:
        session = await client.create_session(
            classify_every_n_chars=100,
            classify_interval_secs=3.0,
        )
        session.on_result(lambda e: print(f"{e.result.main_label} ({e.result.main_confidence:.4f})"))

        for chunk in ["你好", ",这是", "一段测试", "文本。"]:
            await session.send_delta(chunk)

        final = await session.finish()
        print(f"终检: {final.main_label}")

asyncio.run(main())

同步用法

from gshield import SyncGshieldStreamClient

with SyncGshieldStreamClient("ws://localhost:6006/ws/classify") as client:
    session = client.create_session()
    for chunk in ["你好", ",这是", "一段测试", "文本。"]:
        client.send_delta(session, chunk)
    final = client.finish(session)
    print(f"终检: {final.main_label}")

依赖

  • Python >= 3.8
  • websockets >= 11.0
  • pydantic >= 2.0

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

gshield-1.0.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

gshield-1.0.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gshield-1.0.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for gshield-1.0.0.tar.gz
Algorithm Hash digest
SHA256 94af14dd23bb44acf13428571557c985232ebaa7a138ba0b0a479f3886bfb530
MD5 639cf26036e07c658a801ddde30702e6
BLAKE2b-256 dc31c03e1e2cba8ac9ded77affb25e91707eb65f452b1b8f452645bd92a51622

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gshield-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for gshield-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b284ac0a9e6228a5cd3c21bea1c3fac41b70c038898cab4e4fcd433de02cbfcb
MD5 c052c7873af228ad022bed91a2b7e0a1
BLAKE2b-256 4612bb880e71cfa83ffc1386f200524fe3fb7ee5ec671dce9707b1d1fa88ab62

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