|
1 سال پیش | |
---|---|---|
.. | ||
1084-536x354-grayscale.jpg | 1 سال پیش | |
package.json | 1 سال پیش | |
readme.md | 1 سال پیش | |
renamer.ts | 1 سال پیش |
This example applies the benefits of the llava models to managing images. It will find any images in your current directory, generate keywords for the image, and then copy the file to a new name based on the keywords.
examples/typescript-airenamer
directory.npm install
.npm run start
.The main part of the code is in the getkeywords
function. It calls the /api/generate
endpoint passing in the body:
{
"model": "llava:13b-v1.5-q5_K_M",
"prompt": `Describe the image as a collection of keywords. Output in JSON format. Use the following schema: { filename: string, keywords: string[] }`,
"format": "json",
"images": [image],
"stream": false
}
This demonstrates how to use images as well as format: json
to allow calling another function. The images key takes an array of base64 encoded images. And format: json
tells the model to output JSON instead of regular text. When using format: json
, it's important to also say that you expect the output to be JSON in the prompt. Adding the expected schema to the prompt also helps the model understand what you're looking for.
The main
function calls getkeywords passing it the base64 encoded image. Then it parses the JSON output, formats the keywords into a string, and copies the file to the new name.