Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions examples/agent-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ async function createOrGetAgentRuntime(): Promise<AgentRuntime> {
codeConfiguration: await codeFromFile(
AgentRuntimeLanguage.NODEJS18,
['node', 'index.js'],
codePath,
codePath
),
port: 9000,
cpu: 2,
memory: 4096,
}
},
});

log(`创建成功 / Created successfully: ${ar.agentRuntimeId}`);
Expand All @@ -113,10 +113,10 @@ async function createOrGetAgentRuntime(): Promise<AgentRuntime> {
ar.status === Status.DELETE_FAILED
) {
log(
`已存在的 Agent Runtime 处于失败状态: ${ar.status}, 删除并重新创建 / Existing Agent Runtime is in failed state: ${ar.status}, deleting and recreating`,
`已存在的 Agent Runtime 处于失败状态: ${ar.status}, 删除并重新创建 / Existing Agent Runtime is in failed state: ${ar.status}, deleting and recreating`
);
await ar.delete();

// Wait for deletion to complete
log('等待删除完成 / Waiting for deletion to complete...');
let deleted = false;
Expand All @@ -134,7 +134,7 @@ async function createOrGetAgentRuntime(): Promise<AgentRuntime> {
break;
}
}

if (!deleted) {
throw new Error('等待删除超时 / Deletion timeout');
}
Expand All @@ -155,20 +155,21 @@ async function createOrGetAgentRuntime(): Promise<AgentRuntime> {
codeConfiguration: await codeFromFile(
AgentRuntimeLanguage.NODEJS18,
['node', 'index.js'],
codePath,
codePath
),
port: 9000,
cpu: 2,
memory: 4096,
}
},
});
log(`创建成功 / Created successfully: ${ar.agentRuntimeId}`);
}

// Wait for ready or failed
log('等待就绪 / Waiting for ready...');
await ar.waitUntilReadyOrFailed({
beforeCheck: (runtime) => log(` 当前状态 / Current status: ${runtime.status}`),
callback: (runtime) =>
log(` 当前状态 / Current status: ${runtime.status}`),
});

if (ar.status !== Status.READY) {
Expand Down Expand Up @@ -196,7 +197,8 @@ async function updateAgentRuntime(ar: AgentRuntime): Promise<void> {
});

await ar.waitUntilReadyOrFailed({
beforeCheck: (runtime) => log(` 当前状态 / Current status: ${runtime.status}`),
callback: (runtime) =>
log(` 当前状态 / Current status: ${runtime.status}`),
});

if (ar.status !== Status.READY) {
Expand All @@ -213,10 +215,10 @@ async function updateAgentRuntime(ar: AgentRuntime): Promise<void> {
async function listAgentRuntimes(): Promise<void> {
log('枚举资源列表 / Listing resources');

const runtimes = await client.listAll();
const runtimes = await AgentRuntime.listAll();
log(
`共有 ${runtimes.length} 个资源 / Total ${runtimes.length} resources:`,
runtimes.map((r) => r.agentRuntimeName),
runtimes.map((r) => r.agentRuntimeName)
);
}

Expand All @@ -232,8 +234,9 @@ async function deleteAgentRuntime(ar: AgentRuntime): Promise<void> {
// Wait for deletion
log('等待删除完成 / Waiting for deletion...');
try {
await ar.waitUntilReady({
beforeCheck: (runtime) => log(` 当前状态 / Current status: ${runtime.status}`),
await ar.waitUntilReadyOrFailed({
callback: (runtime) =>
log(` 当前状态 / Current status: ${runtime.status}`),
});
} catch (error) {
// Expected to fail when resource is deleted
Expand All @@ -245,7 +248,9 @@ async function deleteAgentRuntime(ar: AgentRuntime): Promise<void> {
log('资源仍然存在 / Resource still exists');
} catch (error) {
if (error instanceof ResourceNotExistError) {
log('得到资源不存在报错,删除成功 / Resource not found, deletion successful');
log(
'得到资源不存在报错,删除成功 / Resource not found, deletion successful'
);
} else {
throw error;
}
Expand Down
16 changes: 9 additions & 7 deletions examples/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ async function createOrGetModelService(): Promise<ModelService> {
}

// 等待就绪 / Wait for ready
await ms.waitUntilReady({
beforeCheck: (service: ModelService) => log(` 当前状态 / Current status: ${service.status}`),
await ms.waitUntilReadyOrFailed({
beforeCheck: (service: ModelService) =>
log(` 当前状态 / Current status: ${service.status}`),
});

if (ms.status !== Status.READY) {
Expand All @@ -95,7 +96,7 @@ async function updateModelService(ms: ModelService): Promise<void> {
},
});

await ms.waitUntilReady();
await ms.waitUntilReadyOrFailed();

if (ms.status !== Status.READY) {
throw new Error(`状态异常 / Unexpected status: ${ms.status}`);
Expand Down Expand Up @@ -124,7 +125,7 @@ async function listModelServices(): Promise<void> {
async function invokeModelService(ms: ModelService): Promise<void> {
log('调用模型服务进行推理 / Invoking model service for inference');

const result = await ms.completions({
const result = await ms.completion({
messages: [{ role: 'user', content: '你好,请介绍一下你自己' }],
stream: true,
});
Expand Down Expand Up @@ -196,8 +197,9 @@ async function createOrGetModelProxy(): Promise<ModelProxy> {
}

// 等待就绪 / Wait for ready
await mp.waitUntilReady({
beforeCheck: (proxy: ModelProxy) => log(` 当前状态 / Current status: ${proxy.status}`),
await mp.waitUntilReadyOrFailed({
beforeCheck: (proxy: ModelProxy) =>
log(` 当前状态 / Current status: ${proxy.status}`),
});

if (mp.status !== Status.READY) {
Expand Down Expand Up @@ -226,7 +228,7 @@ async function updateModelProxy(mp: ModelProxy): Promise<void> {
},
});

await mp.waitUntilReady();
await mp.waitUntilReadyOrFailed();

if (mp.status !== Status.READY) {
throw new Error(`状态异常 / Unexpected status: ${mp.status}`);
Expand Down
Loading
Loading