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.8

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.8
File Size Uploaded Provenance
pytspclient-0.2.8.tar.gz 13.0 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 23.7 kB

Release files / pytspclient-0.2.8.tar.gz

Download URL pytspclient-0.2.8.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cabb073ff476aad770917b568ac01bf2593ab724471f3ad1eb0b0d0fceb97469
BLAKE2b-256 checksum
How to use checksums
d2bbeb7f026b3657bb946c2218c674274982f8fe2bf3b776796f5059cc3e8ac7
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.8-py3-none-any.whl

Download URL pytspclient-0.2.8-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b5524d955ae6cb66cb44e966e3226c4f2f0fb9100dcaa8a356a19f837bc3c42
BLAKE2b-256 checksum
How to use checksums
82337e38055003a397735edf9805430ad85f817a34d3f7b7806dc6f486ca8c78
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.8

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