转换
GenAIScript中的cast函数允许您将文本或图像转换为结构化数据。
它提供了一个简单的接口,利用LLM的强大功能从非结构化文本和图像中提取数据。
使用说明
cast 定义在 GenAIScript runtime 中,需要被导入。它接收非结构化文本(或文件)和一个JSON模式,并返回提取的数据(或错误)。
import { cast } from "genaiscript/runtime"
const { data } = await cast( "The quick brown fox jumps over the lazy dog.; jumps", { type: "object", properties: { partOfSpeech: { type: "string" }, }, }, { instructions: `You will be presented with a sentence and a word containedin that sentence. You have to determine the part of speech for a given word`, })图片
您可以传递一个接收提示上下文的函数,
并通过编程方式构建DATA变量。
这使您能够选择文件、图像和其他GenAIScript选项。
const res = await cast(_ => { _.defImages('DATA', img)}, ...)模型和其他选项
cast函数默认使用castmodel alias。
您可以在选项中修改此别名或指定其他模型。
const res = await cast("...", { model: "large",})options参数会在内部传递给inline prompt,可用于修改LLM的行为。
致谢
这个函数的灵感来自Marvin。