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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytspclient-0.2.7.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

pytspclient-0.2.7-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file pytspclient-0.2.7.tar.gz.

File metadata

  • Download URL: pytspclient-0.2.7.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pytspclient-0.2.7.tar.gz
Algorithm Hash digest
SHA256 d4dd71dc08c34ccce1d154b18a9b27895a91d4c75b03f9947b099dc559f49c92
MD5 6434668764e803e7ba5d6746b10a31d4
BLAKE2b-256 78668aebccac3d4bbb8ad6eb117d4913bb0e9c36728c8578c3667e47871196f7

See more details on using hashes here.

File details

Details for the file pytspclient-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: pytspclient-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pytspclient-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 88e2c4375ba96a7b1a68f7969b97281f001aab92fcdcc947b3c5944317f0edfd
MD5 2df6bd836df60f0e80651dcb8105f552
BLAKE2b-256 c738b047c6bb4b929d8fe45acbb8fb59d0e4c16c87020d230a1327d1a128f8cb

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 Sentry Error logging StatusPage Status page