返回顶部
p

python-sdkPython SDK

Python SDK for inference.sh - run AI apps, build agents, and integrate with 150+ models. Package: inferencesh (pip install inferencesh). Supports sync/async, streaming, file uploads. Build agents with template or ad-hoc patterns, tool builder API, skills, and human approval. Use for: Python integration, AI apps, agent development, RAG pipelines, automation. Triggers: python sdk, inferencesh, pip install, python api, python client, async inference, python agent, tool builder python, programmatic

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.5
安全检测
已通过
1,267
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

python-sdk

Python SDK

使用 inference.sh Python SDK 构建 AI 应用程序。

Python SDK

快速开始

bash
pip install inferencesh

python
from inferencesh import inference

client = inference(apikey=infyour_key)

运行 AI 应用

result = client.run({ app: infsh/flux-schnell, input: {prompt: 山峦上的日落} }) print(result[output])

安装

bash

标准安装


pip install inferencesh

支持异步

pip install inferencesh[async]

要求: Python 3.8+

身份验证

python
import os
from inferencesh import inference

直接使用 API 密钥

client = inference(apikey=infyour_key)

从环境变量获取(推荐)

client = inference(apikey=os.environ[INFERENCEAPI_KEY])

获取 API 密钥:设置 → API 密钥 → 创建 API 密钥

运行应用

基本执行

python
result = client.run({
app: infsh/flux-schnell,
input: {prompt: 一只猫宇航员}
})

print(result[status]) # completed
print(result[output]) # 输出数据

即发即忘

python
task = client.run({
app: google/veo-3-1-fast,
input: {prompt: 无人机飞越山峦}
}, wait=False)

print(f任务 ID: {task[id]})

稍后使用 client.get_task(task[id]) 检查

流式进度

python
for update in client.run({
app: google/veo-3-1-fast,
input: {prompt: 日落时的海浪}
}, stream=True):
print(f状态: {update[status]})
if update.get(logs):
print(update[logs][-1])

运行参数

参数类型描述
app字符串应用 ID(命名空间/名称@版本)
input
字典 | 与应用模式匹配的输入 | | setup | 字典 | 隐藏的设置配置 | | infra | 字符串 | cloud 或 private | | session | 字符串 | 有状态执行的会话 ID | | session_timeout | 整数 | 空闲超时时间(1-3600 秒) |

文件处理

自动上传

python
result = client.run({
app: image-processor,
input: {
image: /path/to/image.png # 自动上传
}
})

手动上传

python
from inferencesh import UploadFileOptions

基本上传

file = client.upload_file(/path/to/image.png)

带选项

file = client.upload_file( /path/to/image.png, UploadFileOptions( filename=custom_name.png, content_type=image/png, public=True ) )

result = client.run({
app: image-processor,
input: {image: file[uri]}
})

会话(有状态执行)

在多次调用之间保持工作进程活跃:

python

启动新会话


result = client.run({
app: my-app,
input: {action: init},
session: new,
session_timeout: 300 # 5 分钟
})
sessionid = result[sessionid]

在同一个会话中继续

result = client.run({ app: my-app, input: {action: process}, session: session_id })

Agent SDK

模板 Agent

使用工作区中预构建的 agent:

python
agent = client.agent(my-team/support-agent@latest)

发送消息

response = agent.send_message(你好!) print(response.text)

多轮对话

response = agent.send_message(告诉我更多)

重置对话

agent.reset()

获取聊天历史

chat = agent.get_chat()

临时 Agent

以编程方式创建自定义 agent:

python
from inferencesh import tool, string, number, app_tool

定义工具

calculator = ( tool(calculate) .describe(执行计算) .param(expression, string(数学表达式)) .build() )

image_gen = (
apptool(generateimage, infsh/flux-schnell@latest)
.describe(生成图像)
.param(prompt, string(图像描述))
.build()
)

创建 agent

agent = client.agent({ core_app: {ref: infsh/claude-sonnet-4@latest}, system_prompt: 你是一个乐于助人的助手。, tools: [calculator, image_gen], temperature: 0.7, max_tokens: 4096 })

response = agent.send_message(25 * 4 等于多少?)

可用的核心应用

模型应用引用
Claude Sonnet 4infsh/claude-sonnet-4@latest
Claude 3.5 Haiku
infsh/claude-haiku-35@latest | | GPT-4o | infsh/gpt-4o@latest | | GPT-4o Mini | infsh/gpt-4o-mini@latest |

工具构建器 API

参数类型

python
from inferencesh import (
string, number, integer, boolean,
enum_of, array, obj, optional
)

name = string(用户姓名)
age = integer(年龄(岁))
score = number(分数 0-1)
active = boolean(是否活跃)
priority = enum_of([低, 中, 高], 优先级)
tags = array(string(标签), 标签列表)
address = obj({
street: string(街道),
city: string(城市),
zip: optional(string(邮政编码))
}, 地址)

客户端工具(在代码中运行)

python
greet = (
tool(greet)
.display(问候用户)
.describe(按姓名问候用户)
.param(name, string(要问候的姓名))
.require_approval()
.build()
)

应用工具(调用 AI 应用)

python
generate = (
apptool(generateimage, infsh/flux-schnell@latest)
.describe(从文本生成图像)
.param(prompt, string(图像描述))
.setup({model: schnell})
.input({steps: 20})
.require_approval()
.build()
)

Agent 工具(委托给子 agent)

python
from inferencesh import agent_tool

researcher = (
agent_tool(research, my-org/researcher@v1)
.describe(研究主题)
.param(topic, string(要研究的主题))
.build()
)

Webhook 工具(调用外部 API)

python
from inferencesh import webhook_tool

notify = (
webhook_tool(slack, https://hooks.slack.com/...)
.describe(发送 Slack 通知)
.secret(SLACK_SECRET)
.param(channel, string(频道))
.param(message, string(消息))
.build()
)

内部工具(内置功能)

python
from inferencesh import internal_tools

config = (
internal_tools()
.plan()
.memory()
.web_search(True)
.code_execution(True)
.image_generation({
enabled: True,
app_ref: infsh/flux@latest
})
.build()
)

agent = client.agent({
core_app: {ref: infsh/claude-sonnet-4@latest},
internal_tools: config
})

流式 Agent 响应

python
def handle_message(msg):
if msg.get(content):
print(msg[content], end=, flush=True)

def handle_tool(call):
print(f\n[工具: {call.name}])
result = execute_tool(call.name, call.args)
agent.submittoolresult(call.id, result)

response = agent.send_message(
解释量子计算,
onmessage=handlemessage,
ontoolcall=handle_tool
)

文件附件

python

从文件路径


with open(image.png, rb)

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 python-sdk-1776352396 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 python-sdk-1776352396 技能

通过命令行安装

skillhub install python-sdk-1776352396

下载

⬇ 下载 python-sdk v0.1.5(免费)

文件大小: 18.71 KB | 发布时间: 2026-4-17 14:00

v0.1.5 最新 2026-4-17 14:00
- Initial public release of the Python SDK for inference.sh.
- Run, stream, and manage AI apps with support for 150+ models.
- Includes agent/assistant building: template and ad-hoc agent support with tools and human approval flows.
- Features file upload API (automatic/manual) and session management for stateful execution.
- Tool builder API enables creation of custom, app, agent, webhook, and internal tools.
- Supports both synchronous and asynchronous (async) operation modes.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部