Skip to main content

pyTSPClient

轻量级 Python 客户端,用于连接 TSP 工具服务器。

安装

pip install pytspclient

国内网络环境

如遇网络问题,可使用镜像源:

# pip 使用清华源
pip install pytspclient -i https://pypi.tuna.tsinghua.edu.cn/simple

构建 gtsp 时需设置 Go 代理:

# Go module 代理
export GOPROXY=https://goproxy.cn,direct

# Go 下载镜像(如需)
# macOS: https://golang.google.cn/dl/
# Linux: https://golang.google.cn/dl/

使用方式

一、Normal API — 普通场景使用

自己构建参数来调用工具。完整示例见 demo_basic.py。

from pytspclient import TSPClient, ToolCall

# 启动并初始化
tsp = await TSPClient.from_stdio("./gtsp").start()

# 获取 TSP 信息
print(tsp.tools)    # 工具 Schema 列表
print(tsp.workdir)  # TSP 工作目录

# 调用工具
call = ToolCall(name="read_file", input={"file_path": "hello.txt"})
result = await tsp.call_tool(call)
print(result.output)

# 关闭
await tsp.shutdown()

二、Adapter API — 直接对接 LLM 使用

使用 LLM 返回的对象,直接对接 TSP。完整示例见 demo_agent.py。

from pytspclient import TSPClient
from openai import OpenAI

tsp = await TSPClient.from_stdio("./gtsp").start()
adapter = tsp.for_openai()
llm = OpenAI()
messages = [{"role": "user", "content": "读取 hello.txt"}]

while True:
    resp = llm.chat.completions.create(model="gpt-4o", messages=messages, tools=adapter.tools)
    messages.append(resp.choices[0].message)

    if adapter.parse_tool_calls(resp):
        results = await adapter.execute_tool_calls(resp)
        messages.extend(adapter.to_tool_messages(results))
    else:
        print(resp.choices[0].message.content)
        break

API 参考

License

MIT

Metadata

Release files for pytspclient 0.2.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytspclient 0.2.9
File Size Uploaded Provenance
pytspclient-0.2.9.tar.gz 12.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytspclient 0.2.9
File Interpreter ABI Platform
pytspclient-0.2.9-py3-none-any.whl Python 3 none any Details

Total release size: 23.7 kB

Release files / pytspclient-0.2.9.tar.gz

Download URL pytspclient-0.2.9.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
abe980f821979a21dbda06fdc313aabaa6c6e267c5316cd3405b6a1a689eebda
BLAKE2b-256 checksum
How to use checksums
7dc0bf9fb3a88e67b545b9bca49b5603b1a9be8c268f67d39f5e044bd1a15358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / pytspclient-0.2.9-py3-none-any.whl

Download URL pytspclient-0.2.9-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4209a1388564c9e92d8b475dc3f6f3ff161cb3bacddd91befb9e901775cece5c
BLAKE2b-256 checksum
How to use checksums
5704bfbec5c7974128a0fe1ba4c750d7f37e49675a13905673f57ae5a1521450
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Security for pytspclient 0.2.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page