|
| 1 | +import { Agent, Scope } from '@smythos/sdk'; |
| 2 | + |
| 3 | +async function main() { |
| 4 | + //in this example, we will skip the native LLM image processing, and we will let the agent delegate it to the appropriate skill |
| 5 | + |
| 6 | + const agent = new Agent({ |
| 7 | + id: 'image-analyser', |
| 8 | + name: 'Image Analyser', |
| 9 | + behavior: 'You are an image analyser. You are given an image and you need to analyse it', |
| 10 | + model: 'gpt-4o', |
| 11 | + }); |
| 12 | + |
| 13 | + //First we define the skill that will handle the image |
| 14 | + const imgSkill = agent.addSkill({ |
| 15 | + name: 'ImageAnalyser', |
| 16 | + description: 'Any attachment should be processed by this function', |
| 17 | + process: async ({ image_url }) => { |
| 18 | + //Here the image_url will be passed as smythfs:// url |
| 19 | + //we can extract it using agent.storage functions |
| 20 | + |
| 21 | + console.log(image_url); |
| 22 | + return 'Image analysed'; |
| 23 | + }, |
| 24 | + }); |
| 25 | + //very important, we need to force the input type of image_url to Binary |
| 26 | + //this will tell our agent to skip the native LLM image processing, and use the agent skill instead |
| 27 | + imgSkill.in({ |
| 28 | + image_url : { |
| 29 | + type:'Binary', |
| 30 | + description:'The image url that we will analyze' |
| 31 | + } |
| 32 | + }) |
| 33 | + |
| 34 | + |
| 35 | + const prompt = await agent.prompt('Analyze this image please ', { |
| 36 | + //you can pass your attachments in files array |
| 37 | + //it supports local files, remote urls, smythfs:// urls, Buffers or Blobs |
| 38 | + files: ['https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/VanGogh-starry_night_ballance1.jpg/960px-VanGogh-starry_night_ballance1.jpg'], |
| 39 | + }); |
| 40 | + console.log(prompt); |
| 41 | + |
| 42 | + |
| 43 | +} |
| 44 | + |
| 45 | +main(); |
0 commit comments