Loading...
Loading...
Compare original and translation side by side


pip install inferenceshfrom inferencesh import inference
client = inference(api_key="inf_your_key")pip install inferenceshfrom inferencesh import inference
client = inference(api_key="inf_your_key")undefinedundefinedundefinedundefined
**Requirements:** Python 3.8+
**要求:** Python 3.8+import os
from inferencesh import inferenceimport os
from inferencesh import inference
Get your API key: Settings → API Keys → Create API Key
获取API密钥:设置 → API密钥 → 创建API密钥result = client.run({
"app": "infsh/flux-schnell",
"input": {"prompt": "A cat astronaut"}
})
print(result["status"]) # "completed"
print(result["output"]) # Output dataresult = client.run({
"app": "infsh/flux-schnell",
"input": {"prompt": "A cat astronaut"}
})
print(result["status"]) # "completed"
print(result["output"]) # 输出数据task = client.run({
"app": "google/veo-3-1-fast",
"input": {"prompt": "Drone flying over mountains"}
}, wait=False)
print(f"Task ID: {task['id']}")task = client.run({
"app": "google/veo-3-1-fast",
"input": {"prompt": "Drone flying over mountains"}
}, wait=False)
print(f"任务ID: {task['id']}")undefinedundefinedfor update in client.run({
"app": "google/veo-3-1-fast",
"input": {"prompt": "Ocean waves at sunset"}
}, stream=True):
print(f"Status: {update['status']}")
if update.get("logs"):
print(update["logs"][-1])for update in client.run({
"app": "google/veo-3-1-fast",
"input": {"prompt": "Ocean waves at sunset"}
}, stream=True):
print(f"状态: {update['status']}")
if update.get("logs"):
print(update["logs"][-1])| Parameter | Type | Description |
|---|---|---|
| string | App ID (namespace/name@version) |
| dict | Input matching app schema |
| dict | Hidden setup configuration |
| string | 'cloud' or 'private' |
| string | Session ID for stateful execution |
| int | Idle timeout (1-3600 seconds) |
| 参数 | 类型 | 描述 |
|---|---|---|
| string | 应用ID(命名空间/名称@版本) |
| dict | 匹配应用架构的输入数据 |
| dict | 隐藏的配置设置 |
| string | 'cloud'(云端)或 'private'(私有部署) |
| string | 用于有状态执行的会话ID |
| int | 空闲超时时间(1-3600秒) |
result = client.run({
"app": "image-processor",
"input": {
"image": "/path/to/image.png" # Auto-uploaded
}
})result = client.run({
"app": "image-processor",
"input": {
"image": "/path/to/image.png" # 自动上传
}
})from inferencesh import UploadFileOptionsfrom inferencesh import UploadFileOptionsundefinedundefinedundefinedundefinedundefinedundefinedagent = client.agent("my-team/support-agent@latest")agent = client.agent("my-team/support-agent@latest")undefinedundefinedfrom inferencesh import tool, string, number, app_toolfrom inferencesh import tool, string, number, app_toolundefinedundefined| Model | App Reference |
|---|---|
| Claude Sonnet 4 | |
| Claude 3.5 Haiku | |
| GPT-4o | |
| GPT-4o Mini | |
| 模型 | 应用引用 |
|---|---|
| Claude Sonnet 4 | |
| Claude 3.5 Haiku | |
| GPT-4o | |
| GPT-4o Mini | |
from inferencesh import (
string, number, integer, boolean,
enum_of, array, obj, optional
)
name = string("User's name")
age = integer("Age in years")
score = number("Score 0-1")
active = boolean("Is active")
priority = enum_of(["low", "medium", "high"], "Priority")
tags = array(string("Tag"), "List of tags")
address = obj({
"street": string("Street"),
"city": string("City"),
"zip": optional(string("ZIP"))
}, "Address")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(["low", "medium", "high"], "优先级")
tags = array(string("标签"), "标签列表")
address = obj({
"street": string("街道"),
"city": string("城市"),
"zip": optional(string("邮政编码"))
}, "地址")greet = (
tool("greet")
.display("Greet User")
.describe("Greets a user by name")
.param("name", string("Name to greet"))
.require_approval()
.build()
)greet = (
tool("greet")
.display("问候用户")
.describe("按姓名问候用户")
.param("name", string("要问候的姓名"))
.require_approval()
.build()
)generate = (
app_tool("generate_image", "infsh/flux-schnell@latest")
.describe("Generate an image from text")
.param("prompt", string("Image description"))
.setup({"model": "schnell"})
.input({"steps": 20})
.require_approval()
.build()
)generate = (
app_tool("generate_image", "infsh/flux-schnell@latest")
.describe("根据文本生成图片")
.param("prompt", string("图片描述"))
.setup({"model": "schnell"})
.input({"steps": 20})
.require_approval()
.build()
)from inferencesh import agent_tool
researcher = (
agent_tool("research", "my-org/researcher@v1")
.describe("Research a topic")
.param("topic", string("Topic to research"))
.build()
)from inferencesh import agent_tool
researcher = (
agent_tool("research", "my-org/researcher@v1")
.describe("研究指定主题")
.param("topic", string("研究主题"))
.build()
)from inferencesh import webhook_tool
notify = (
webhook_tool("slack", "https://hooks.slack.com/...")
.describe("Send Slack notification")
.secret("SLACK_SECRET")
.param("channel", string("Channel"))
.param("message", string("Message"))
.build()
)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()
)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
})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
})def handle_message(msg):
if msg.get("content"):
print(msg["content"], end="", flush=True)
def handle_tool(call):
print(f"\n[Tool: {call.name}]")
result = execute_tool(call.name, call.args)
agent.submit_tool_result(call.id, result)
response = agent.send_message(
"Explain quantum computing",
on_message=handle_message,
on_tool_call=handle_tool
)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.submit_tool_result(call.id, result)
response = agent.send_message(
"Explain quantum computing",
on_message=handle_message,
on_tool_call=handle_tool
)undefinedundefinedundefinedundefinedagent = client.agent({
"core_app": {"ref": "infsh/claude-sonnet-4@latest"},
"skills": [
{
"name": "code-review",
"description": "Code review guidelines",
"content": "# Code Review\n\n1. Check security\n2. Check performance..."
},
{
"name": "api-docs",
"description": "API documentation",
"url": "https://example.com/skills/api-docs.md"
}
]
})agent = client.agent({
"core_app": {"ref": "infsh/claude-sonnet-4@latest"},
"skills": [
{
"name": "code-review",
"description": "代码评审指南",
"content": "# 代码评审\n\n1. 检查安全性\n2. 检查性能..."
},
{
"name": "api-docs",
"description": "API文档",
"url": "https://example.com/skills/api-docs.md"
}
]
})from inferencesh import async_inference
import asyncio
async def main():
client = async_inference(api_key="inf_...")
# Async app execution
result = await client.run({
"app": "infsh/flux-schnell",
"input": {"prompt": "A galaxy"}
})
# Async agent
agent = client.agent("my-org/assistant@latest")
response = await agent.send_message("Hello!")
# Async streaming
async for msg in agent.stream_messages():
print(msg)
asyncio.run(main())from inferencesh import async_inference
import asyncio
async def main():
client = async_inference(api_key="inf_...")
# 异步执行应用
result = await client.run({
"app": "infsh/flux-schnell",
"input": {"prompt": "A galaxy"}
})
# 异步Agent
agent = client.agent("my-org/assistant@latest")
response = await agent.send_message("Hello!")
# 异步流式传输
async for msg in agent.stream_messages():
print(msg)
asyncio.run(main())from inferencesh import RequirementsNotMetException
try:
result = client.run({"app": "my-app", "input": {...}})
except RequirementsNotMetException as e:
print(f"Missing requirements:")
for err in e.errors:
print(f" - {err['type']}: {err['key']}")
except RuntimeError as e:
print(f"Error: {e}")from inferencesh import RequirementsNotMetException
try:
result = client.run({"app": "my-app", "input": {...}})
except RequirementsNotMetException as e:
print(f"缺少依赖项:")
for err in e.errors:
print(f" - {err['type']}: {err['key']}")
except RuntimeError as e:
print(f"错误: {e}")def handle_tool(call):
if call.requires_approval:
# Show to user, get confirmation
approved = prompt_user(f"Allow {call.name}?")
if approved:
result = execute_tool(call.name, call.args)
agent.submit_tool_result(call.id, result)
else:
agent.submit_tool_result(call.id, {"error": "Denied by user"})
response = agent.send_message(
"Delete all temp files",
on_tool_call=handle_tool
)def handle_tool(call):
if call.requires_approval:
# 展示给用户,获取确认
approved = prompt_user(f"是否允许执行{call.name}?")
if approved:
result = execute_tool(call.name, call.args)
agent.submit_tool_result(call.id, result)
else:
agent.submit_tool_result(call.id, {"error": "用户已拒绝"})
response = agent.send_message(
"Delete all temp files",
on_tool_call=handle_tool
)undefinedundefinedundefinedundefined