diff --git a/8-skill-in-shell.mjs b/8-skill-in-shell.mjs index a554898..cb47ead 100644 --- a/8-skill-in-shell.mjs +++ b/8-skill-in-shell.mjs @@ -4,89 +4,89 @@ import shell from 'shelljs' const client = new OpenAI(); -// const responseHosted = await client.responses.create({ -// model: "gpt-5.2", -// tools: [ -// { -// type: "shell", -// environment: { -// type: "container_auto", -// skills: [ -// { type: "skill_reference", skill_id: "skill_69b7aab7a0988191afca6ad2c530326b07c9ae27b6429c7c" }, -// ], -// }, -// }, -// ], -// input: "Use the skills to find phone number of Qiaozhen.", -// }); - -// console.log('Hosted shell response:', responseHosted.output_text); - -const conversation = [{ - role: 'user', - content: "Use the mycontacts skill and run locally to find the phone number of Qiaozhen." - }] - -let hasShellCall = true -let round = 0 - -while(hasShellCall) { - hasShellCall = false - round++ - -const responseLocal = await client.responses.create({ +const responseHosted = await client.responses.create({ model: "gpt-5.2", tools: [ { type: "shell", environment: { - type: "local", + type: "container_auto", skills: [ - { - name: "mycontacts", - description: "My contacts info", - path: path.resolve("./skills/mycontacts"), - }, + { type: "skill_reference", skill_id: "skill_69b7c456a9408193856b890836fcd1950fd5b0453b8a6018" }, ], }, }, ], - input: conversation, + input: "Use the skills to find phone number of Qiaozhen.", }); -console.log('Local shell response output:', JSON.stringify(responseLocal.output, null, 2)); +console.log('Hosted shell response:', responseHosted.output_text); -conversation.push(...responseLocal.output) +// const conversation = [{ +// role: 'user', +// content: "Use the mycontacts skill and run locally to find the phone number of Qiaozhen." +// }] -responseLocal.output.forEach(item => { - if (item.type == 'shell_call') { - hasShellCall = true - console.log('shell call item =', item) - let shell_call_output = [] - item.action.commands.forEach(command => { +// let hasShellCall = true +// let round = 0 - console.log('$', command, '\n') +// while(hasShellCall) { +// hasShellCall = false +// round++ + +// const responseLocal = await client.responses.create({ +// model: "gpt-5.2", +// tools: [ +// { +// type: "shell", +// environment: { +// type: "local", +// skills: [ +// { +// name: "mycontacts", +// description: "My contacts info", +// path: path.resolve("./skills/mycontacts"), +// }, +// ], +// }, +// }, +// ], +// input: conversation, +// }); + +// console.log('Local shell response output:', JSON.stringify(responseLocal.output, null, 2)); + +// conversation.push(...responseLocal.output) + +// responseLocal.output.forEach(item => { +// if (item.type == 'shell_call') { +// hasShellCall = true +// console.log('shell call item =', item) +// let shell_call_output = [] +// item.action.commands.forEach(command => { + +// console.log('$', command, '\n') - let { stdout, stderr } = shell.exec(command, { - silent: true - }) - shell_call_output.push({ - stdout, - stderr, - outcome: { type: 'exit', exit_code: 0 } - }) - }) +// let { stdout, stderr } = shell.exec(command, { +// silent: true +// }) +// shell_call_output.push({ +// stdout, +// stderr, +// outcome: { type: 'exit', exit_code: 0 } +// }) +// }) - conversation.push({ - type: 'shell_call_output', - call_id: item.call_id, - output: shell_call_output - }) - } -}) +// conversation.push({ +// type: 'shell_call_output', +// call_id: item.call_id, +// output: shell_call_output +// }) +// } +// }) -console.log('Local shell response of round ' + round + ':', JSON.stringify(responseLocal.output_text, null, 2)); +// console.log('Local shell response of round ' + round + ':', JSON.stringify(responseLocal.output_text, null, 2)); -} \ No newline at end of file +// } \ No newline at end of file diff --git a/8-skill.md b/8-skill.md index 8f4dcc2..2077459 100644 --- a/8-skill.md +++ b/8-skill.md @@ -1,5 +1,5 @@ ``` -curl -X POST 'https://api.openai.com/v1/skills' -H "Authorization: Bearer $OPENAI_API_KEY" -F 'files[]=@./contacts/SKILL.md;filename=contacts/SKILL.md;type=text/markdown'' +$ curl -X POST 'https://api.openai.com/v1/skills' -H "Authorization: Bearer $OPENAI_API_KEY" -F 'files[]=@./contacts/SKILL.md;filename=contacts/SKILL.md;type=text/markdown'' { "id": "skill_69b7aab7a0988191afca6ad2c530326b07c9ae27b6429c7c", "object": "skill", @@ -9,10 +9,11 @@ curl -X POST 'https://api.openai.com/v1/skills' -H "Authorization: Bearer $OPENA "latest_version": "1", "name": "contacts" } -<07:01:11#root@codespaces-5a7969=23.97.62.113^x86_64,Linux,Debtrixie/sid:/workspaces/my-default-codespace/aitest># ``` -注意,必须只有一级目录,不能有子目录 (skills/contacts/skill.md),否则会报错: +会被上传到 OpenAI,可以在个人中心的 Storage 里的 Skills 标签下找到。 + +注意,通过curl上传,必须只有一级目录,不能有子目录 (skills/contacts/skill.md),否则会报错: ``` { @@ -24,3 +25,8 @@ curl -X POST 'https://api.openai.com/v1/skills' -H "Authorization: Bearer $OPENA } } ``` + +curl -X POST 'https://api.openai.com/v1/skills' \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -F 'files[]=@./contacts2/skill.md;filename=contacts2/skill.md;type=text/markdown' \ + -F 'files[]=@./contacts2/contacts.csv;filename=contacts2/contacts.csv;type=text/csv' diff --git a/contacts2/contacts.csv b/contacts2/contacts.csv new file mode 100644 index 0000000..4c4c99e --- /dev/null +++ b/contacts2/contacts.csv @@ -0,0 +1,3 @@ +Xue Hua, 18617591633 +Luk Lu, 15295439901 +Zong Qiaozhen, 13585016982 \ No newline at end of file diff --git a/contacts2/skill.md b/contacts2/skill.md new file mode 100644 index 0000000..98e465b --- /dev/null +++ b/contacts2/skill.md @@ -0,0 +1,6 @@ +--- +name: contacts2 +description: My contact list +--- + +Use this skill when you need to find details of a contact of mine. The skill provides a list of contacts in CSV format: "name, phone" in contacts.csv. diff --git a/skills/mycontacts/SKILL.md b/skills/mycontacts/skill.md similarity index 100% rename from skills/mycontacts/SKILL.md rename to skills/mycontacts/skill.md