当前位置: 首页 > news >正文

用ps做的网站样图怎么切六盘水网站建设

用ps做的网站样图怎么切,六盘水网站建设,网上做ps赚钱的网站,建网站用什么服务器好theme: orange 众所周知,我们可以通过构建的Prompt获取期望的内容,但是通常都是以自然语言返回的,假如我们想得到结构化的数据,比如Json,XML那么怎么办,这篇文章给你一个思路。 理所当然的想法 要实现询问大…

theme: orange

众所周知,我们可以通过构建的Prompt获取期望的内容,但是通常都是以自然语言返回的,假如我们想得到结构化的数据,比如Json,XML那么怎么办,这篇文章给你一个思路。

理所当然的想法

要实现询问大模型后返回结构化的数据,首先能想到的是可以通过在提示末尾添加以 JSON 格式提供您的响应来进行一些“提示工程”,从而获得字符串化的 JSON。问题是这些响应通常包括错误的尾随逗号或介绍性的文字,导致中断错误。

接下来我们通过食谱应用中来实验下,用户在输入框中输入菜名,然后点击“获取食谱”。当您点击此按钮时,我们将运行 getRecipe() 函数:

``typescript function getRecipe() { // Create prompt text with user input. Include data model schema description. const prompt =return a recipe for ${userInput}. Provide your response as a JSON object with the following schema: {"dish": ${userInput}, "ingredients": ["", "", ...], "instructions": ["", "", ... ]}`; openai.createChatCompletion({ model: "gpt-3.5-turbo", messages: [ { role: "system", "content": "You are a helpful recipe assistant." }, { role: "user", content: prompt } ], }) .then((completion) => { // Handle API response const generatedText = completion.data.choices[0].message.content; setRecipe(JSON.parse(generatedText)); }) .catch((error) => { console.log(error); }); } }

```

我要求以 JSON 格式提供响应,然后即兴设计了一个模式来指示我希望如何格式化对象。该模式可以改进,但在很大程度上,它是有效的。然而,正如前面提到的,这些响应容易出现尾随逗号错误,这种非正式的模式需要更具可扩展性和易于维护。

当我使用上面的提示请求buttered toast食谱时,我收到了以下响应: ```text Here's a recipe for buttered toast in JSON format as requested:

{
"dish": "buttered toast",
"ingredients": [
"2 slices of bread",
"2 tablespoons of unsalted butter"
],
"instructions": [
"Preheat your toaster or toaster oven.",
"Place the slices of bread in the toaster or toaster oven.",
"Toast the bread for 1-2 minutes, or until it is golden brown.",
"Carefully remove the toasted bread from the toaster or toaster oven.",
"Place a tablespoon of butter on each slice of toast.",
"Use a knife to spread the butter evenly over the surface of the toast.",
"Serve immediately and enjoy!"
]
}
I hope this helps! 您可以看到响应的核心是正确的,并且非常符合我期望的结构,但这个响应包含了一个不必要的引导性介绍性文字,导致了下列的错误: shell SyntaxError: Unexpected token 'H', "Here's a r"... is not valid JSON
at JSON.parse ```

二次优化

我们可以进一步优化我们的提示以解决这些错误。我尝试添加“不要在大括号外返回响应中的任何内容。”这样做在很大程度上似乎可以消除那些引言和结论性的句子。

OpenAI API 的允许我们指定我们希望以 JSON 格式获得响应,但我们必须使用 JSON Schema 来实现。我通过创建一个 JSON Schema 对象并将其传递给新函数的参数来更新我们的功能。

typescript function getRecipe() { // Create prompt text with user input const prompt = `return a recipe for ${userInput}`; // Define the JSON Schema by creating a schema object const schema = { "type": "object", "properties": { "dish": { "type": "string", "description": "Descriptive title of the dish" }, "ingredients": { "type": "array", "items": {"type": "string"} }, "instructions": { "type": "array", "description": "Steps to prepare the recipe.", "items": {"type": "string"} } } } // Note the updated model and added functions and function_call lines // Note that we pass our schema object to parameters openai.createChatCompletion({ model: "gpt-3.5-turbo-0613", messages: [ { role: "system", "content": "You are a helpful recipe assistant." }, { role: "user", content: prompt } ], functions: [{ name: "set_recipe", parameters: schema }], function_call: {name: "set_recipe"} }) .then((completion) => { // Note the updated location for the response const generatedText = completion.data.choices[0].message.function_call.arguments; setRecipe(JSON.parse(generatedText)); }) .catch((error) => { console.log(error); }); } 经过这次更新,我收到了以下响应: text { "dish": "Buttered Toast", "ingredients": [ "Bread slices", "Butter" ], "instructions": [ "Heat a non-stick skillet or griddle over medium heat.", "Spread butter on one side of each bread slice.", "Place the bread slices on the hot skillet or griddle, butter side down.", "Cook for about 2-3 minutes or until the bottom side is golden brown and crispy.", "Flip the bread slices and cook for another 1-2 minutes.", "Remove from the skillet or griddle and serve immediately." ] }

当我将这个响应传递给 JSON.parse() 时,没有出现错误。现在,食谱应用程序更加可靠,不容易出现由于 OpenAI API 响应格式不一致而导致的错误。

结论

这种方法需要更多的代码行,而且,至少目前,JSON Schema 是唯一支持的声明性语言。一些开发人员可能仍然想尝试非正式地请求 JSON 对象。但是,如果您正在构建依赖于此 JSON 以将元素呈现到页面的项目,这种方法是值得一试的。

http://www.yayakq.cn/news/347158/

相关文章:

  • 后台网站如何建设福田瑞沃自卸车
  • 购物网站项目介绍app直链在线生成
  • 科技网站欣赏馆陶专业做网站
  • 当当网站建设目标网站建设按什么合同交印花税
  • dede 汽车网站模板网页布局设计主要有什么类型
  • 英德市建设局网站扁平化设计的网站
  • 在线营销单页网站制作怎么才能创个网站
  • 连锁酒店网站方案手机网站模板设计软件
  • jsp网站开发期末大作业津南区提供网站建设协议
  • nas做网站要哪些东东设计师一般上什么网站
  • 宁波高等级公路建设指挥部网站WordPress对象存储插件
  • 怎样批量做全国网站可以做四级的网站
  • 网站建设服务目标系统开发的生命周期分为几个阶段
  • 信息系网站建设开题报告书自己建网站还是淘宝
  • 合肥建筑网站大全iis网站模板
  • 沈阳营商环境建设局网站免费软件看电视剧
  • 做百度手机网站快速排网站设计公司列表
  • zzzcms建站系统小米网站seo分析报告+书
  • 深圳网站建设有市场吗中科网站建设
  • 花木公司网站源码建设商务网站的步骤
  • 广东省建设工程安监局网站办公门户网站模板下载
  • 金银回收东莞网站建设小型门户网站有哪些
  • 有谁做网站如何设置网站布局
  • 如何搭建一个网站郑州水晶奖杯制作
  • 怎样建设一个自己的网站wordpress怎么恢复到原来版本
  • c2c网站代表有哪些门户网站建设要求
  • 网站推广优化教程北京城建集团官网
  • 网站建设宣传视频教程nginx wordpress优点
  • 外国网站架构网架制作厂
  • 青岛公司网站建设价格低自己制作广告图片软件