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
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
gshield-1.0.0.tar.gz
(7.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
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94af14dd23bb44acf13428571557c985232ebaa7a138ba0b0a479f3886bfb530
|
|
| MD5 |
639cf26036e07c658a801ddde30702e6
|
|
| BLAKE2b-256 |
dc31c03e1e2cba8ac9ded77affb25e91707eb65f452b1b8f452645bd92a51622
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b284ac0a9e6228a5cd3c21bea1c3fac41b70c038898cab4e4fcd433de02cbfcb
|
|
| MD5 |
c052c7873af228ad022bed91a2b7e0a1
|
|
| BLAKE2b-256 |
4612bb880e71cfa83ffc1386f200524fe3fb7ee5ec671dce9707b1d1fa88ab62
|