- 长臂猿-企业应用及系统软件平台
机器之心报道
借助 TypeChat,可以很容易地获得类型良好的结构化数据。








//./src/sentimentSchema.ts// The following is a schema definition for determining the sentiment of a some user input.export interface SentimentResponse {/** The sentiment of the text. */sentiment: "negative" | "neutral" | "positive";}
//./src/main.tsimport * as fs from "fs";import * as path from "path";import dotenv from "dotenv";import * as typechat from "typechat";import {SentimentResponse} from "./sentimentSchema";// Load environment variables.dotenv.config ({ path: path.join (__dirname, "../.env") });// Create a language model based on the environment variables.const model = typechat.createLanguageModel (process.env);// Load up the contents of our "Response" schema.const schema = fs.readFileSync (path.join (__dirname, "sentimentSchema.ts"), "utf8");const translator = typechat.createJsonTranslator<SentimentResponse>(model, schema, "SentimentResponse");// Process requests interactively.typechat.processRequests ("????>", /*inputFile*/undefined, async (request) => {const response = await translator.translate (request);if (!response.success) {console.log (response.message);return;}console.log (`The sentiment is ${response.data.sentiment}`);});

© THE END
转载请联系本公众号获得授权
投稿或寻求报道:content@jiqizhixin.com