도구 만들기
이 튜토리얼에서는 Web UI에 greet 도구를 추가합니다. 먼저 첫 번째 플러그인을 완료하고 해당 scratch-plugin 디렉터리를 유지하세요.
도구 플러그인 만들기
scratch-plugin/src/my-plugin.ts를 다음으로 바꾸세요:
ts
import type { Context } from '@deepseek-ai/cordis'
import { defineTool } from '@deepseek-ai/dsh-tools'
export const name = 'greet-tool'
export const inject = ['tools']
export function apply(ctx: Context) {
ctx.tools.register(defineTool({
name: 'greet',
description: 'Greet someone by name.',
parameters: {
name: { type: 'string', required: true, description: 'The name to greet' },
},
output: {
schema: { type: 'string' },
render: (_args, value) => [{ type: 'text', text: value }],
},
async execute(args) {
return `Hello, ${args.name}!`
},
}))
}inject는 Cordis가 도구 레지스트리를 기다리도록 합니다. defineTool는 parameters에서 args를 추론하고 검증합니다. execute는 output.schema에서 선언한 표준 값을 반환하고, output.render는 그 값을 모델용 콘텐츠로 변환합니다.
도구 실행 및 호출
실행 중이 아니라면 개발 명령을 다시 시작하세요:
sh
pnpm dsh web --patch ./scratch-plugin/cordis.ymlhttp://127.0.0.1:3080을 열고 다음과 같이 요청하세요: Use the greet tool to greet Ada. 모델은 greet를 호출할 수 있으며, 도구 결과로 Hello, Ada!를 받습니다.