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.1.tar.gz
(7.7 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.1.tar.gz.
File metadata
- Download URL: gshield-1.0.1.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de210f0962b548eee03e0b4494f09c69c408dd996fb1c79778b2dff6a60fec8a
|
|
| MD5 |
d7f1f0573044392dd70174f27ed9d96f
|
|
| BLAKE2b-256 |
1afa182571f64b7d446c6362e924ef12df677b5037c1c18397ae55edcfd0da88
|
File details
Details for the file gshield-1.0.1-py3-none-any.whl.
File metadata
- Download URL: gshield-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.1 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 |
80ad83decab29b9aa9b9985d1afaabea705240032b185dab11ad3d015f85349c
|
|
| MD5 |
37cf85c74a47493eafe50faec4a9c175
|
|
| BLAKE2b-256 |
aa5645f8b4ba4d1c6b6d814490df673db61f1d24710d610c54313e441e475dee
|