ChatGPT Prompting开发实战(十二)

一、如何开发prompts实现个性化的对话方式

通过设置“system”和“user”等roles,可以实现个性化的对话方式,并且可以结合参数“temperature”的设定来差异化LLM的输出内容。在此基础上,通过构建一个餐馆订餐对话机器人来具体演示对话过程。

接下来会给出具体示例,通过调用模型“gpt-3.5-turbo”来演示并解析如何针对上述需求来编写相应的prompts。

二、结合案例演示解析如何开发prompt实现个性化的对话方式

首先在messages中设定各个role的内容,即prompts,然后通过API调用模型输出内容。

prompt示例如下:

messages =  [ 

{'role':'system', 'content':'You are an assistant that speaks like Shakespeare.'},   

{'role':'user', 'content':'tell me a joke'},  

{'role':'assistant', 'content':'Why did the chicken cross the road'},  

{'role':'user', 'content':'I don\'t know'}  ]

response = get_completion_from_messages(messages, temperature=1)

print(response)

打印输出结果如下:

Verily, forsooth, the chicken didst cross the road to evade the humorless peasants who didst question its motives with incessant queries.

接下来修改prompts的内容,在调用API时增加参数temperature的设定。

prompt示例如下:

messages =  [ 

{'role':'system', 'content':'You are friendly chatbot.'},   

{'role':'user', 'content':'Hi, my name is Isa'}  ]

response = get_completion_from_messages(messages, temperature=1)

print(response)

打印输出结果如下:

Hello Isa! How can I assist you today?

继续修改prompts的内容:

prompt示例如下:

messages =  [ 

{'role':'system', 'content':'You are friendly chatbot.'},   

{'role':'user', 'content':'Yes,  can you remind me, What is my name?'}  ]

response = get_completion_from_messages(messages, temperature=1)

print(response)

打印输出结果如下:

I'm sorry, but as a chatbot, I don't have access to personal information. Could you please remind me of your name?

       从上面输出结果看,由于在”user”这个role对应的prompt中没有给出关于用户名字的信息,导致聊天机器人给不出用户提出的问题的答案,这时可以继续修改prompt。

prompt示例如下:

messages =  [ 

{'role':'system', 'content':'You are friendly chatbot.'},

{'role':'user', 'content':'Hi, my name is Isa'},

{'role':'assistant', 'content': "Hi Isa! It's nice to meet you. \

Is there anything I can help you with today?"},

{'role':'user', 'content':'Yes, you can remind me, What is my name?'}  ]

response = get_completion_from_messages(messages, temperature=1)

print(response)

打印输出结果如下:

Your name is Isa!

接下来构建一个餐馆订餐对话机器人,首先定义一个收集用户订餐需求的方法:

构建一个用户与对话机器人的交互界面(GUI):

import panel as pn  # GUI

pn.extension()

panels = [] # collect display

context = [ {'role':'system', 'content':"""

You are OrderBot, an automated service to collect orders for a pizza restaurant. \

You first greet the customer, then collects the order, \

and then asks if it's a pickup or delivery. \

You wait to collect the entire order, then summarize it and check for a final \

time if the customer wants to add anything else. \

If it's a delivery, you ask for an address. \

Finally you collect the payment.\

Make sure to clarify all options, extras and sizes to uniquely \

identify the item from the menu.\

You respond in a short, very conversational friendly style. \

The menu includes \

pepperoni pizza  12.95, 10.00, 7.00 \

cheese pizza   10.95, 9.25, 6.50 \

eggplant pizza   11.95, 9.75, 6.75 \

fries 4.50, 3.50 \

greek salad 7.25 \

Toppings: \

extra cheese 2.00, \

mushrooms 1.50 \

sausage 3.00 \

canadian bacon 3.50 \

AI sauce 1.50 \

peppers 1.00 \

Drinks: \

coke 3.00, 2.00, 1.00 \

sprite 3.00, 2.00, 1.00 \

bottled water 5.00 \

"""} ]  # accumulate messages

inp = pn.widgets.TextInput(value="Hi", placeholder='Enter text here…')

button_conversation = pn.widgets.Button(name="Chat!")

interactive_conversation = pn.bind(collect_messages, button_conversation)

dashboard = pn.Column(

    inp,

    pn.Row(button_conversation),

    pn.panel(interactive_conversation, loading_indicator=True, height=300),

)

dashboard

用户界面显示如下:

编写prompt,根据之前的订餐情况输出订餐数据列表显示给用户。

prompt示例如下:

messages =  context.copy()

messages.append(

{'role':'system', 'content':'create a json summary of the previous food order. Itemize the price for each item\

 The fields should be 1) pizza, include size 2) list of toppings 3) list of drinks, include size   4) list of sides include size  5)total price '},   

)

 #The fields should be 1) pizza, price 2) list of toppings 3) list of drinks, include size include price  4) list of sides include size include price, 5)total price '},   

response = get_completion_from_messages(messages, temperature=0)

print(response)

打印输出结果如下:

Sure! Here's a JSON summary of your food order:

{

  "pizza": {

    "type": "pepperoni",

    "size": "large"

  },

  "toppings": [

    "extra cheese",

    "mushrooms"

  ],

  "drinks": [

    {

      "type": "coke",

      "size": "medium"

    },

    {

      "type": "sprite",

      "size": "small"

    }

  ],

  "sides": [

    {

      "type": "fries",

      "size": "regular"

    }

  ],

  "total_price": 29.45

}

Please let me know if there's anything else you'd like to add to your order!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/146169.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

Arcgis克里金插值报错:ERROR 010079: 无法估算半变异函数。 执行(Kriging)失败。

Arcgis克里金插值报错:ERROR 010079: 无法估算半变异函数。 执行(Kriging)失败。 问题描述: 原因: shape文件的问题,此图可以看出,待插值的点有好几个都超出了地理范围之外,这个不知道是坐标系配准的问…

JAVA设计模式-代理模式

一.概念 在软件开发中,也有一种设计模式可以提供与代购网站类似的功能。由于某些原因,客户端不想或不能直接访问一个对象,此时可以通过一个称之为“代理”的第三者来实现间接访问,该方案对应的设计模式被称为代理模式。 ​ 代理模…

数据结构——堆(C语言)

本篇会解决一下几个问题: 1.堆是什么? 2.如何形成一个堆? 3.堆的应用场景 堆是什么? 堆总是一颗完全二叉树堆的某个节点总是不大于或不小于父亲节点 如图,在小堆中,父亲节点总是小于孩子节点的。 如图&a…

GO 比较两个对象是否相同

本文主要是来聊一聊关于 Golang 中的深度比较 DeepEqual 因为最近发现身边的小伙伴写 2 个或者多个 map 比较的时候,都是自己去实现去比较每一个结构,每一个节点的 key 和 value 是不是都相等,且根据不同的数据结构,都要去实现一…

【Python】基于OpenCV人脸追踪、手势识别控制的求实之路FPS游戏操作

【Python】基于OpenCV人脸追踪、手势识别控制的求实之路FPS游戏操作 文章目录 手势识别人脸追踪键盘控制整体代码附录:列表的赋值类型和py打包列表赋值BUG复现代码改进优化总结 py打包 视频: 基于OpenCV人脸追踪、手势识别控制的求实之路FPS游戏操作 手…

Everything+cpolar搭建在线资料库,实现随时随地访问

Everythingcpolar搭建在线资料库,实现随时随地访问 文章目录 Everythingcpolar搭建在线资料库,实现随时随地访问前言1.软件安装完成后,打开Everything2.登录cpolar官网 设置空白数据隧道3.将空白数据隧道与本地Everything软件结合起来总结 前…

Python日期的加减等操作

嗨喽,大家好呀~这里是爱看美女的茜茜呐 日期输出格式化 所有日期、时间的api都在datetime模块内。 👇 👇 👇 更多精彩机密、教程,尽在下方,赶紧点击了解吧~ python源码、视频教程、插件安装教程、资料我都…

scala基础入门

一、Scala安装 下载网址:Install | The Scala Programming Language ideal安装 (1)下载安装Scala plugins (2)统一JDK环境,统一为8 (3)加载Scala (4)创建工…

ARM底层汇编基础指令

汇编语言的组成 伪操作 不参与程序执行,但是用于告诉编译器程序怎么编译.text .global .end .if .else .endif .data 汇编指令 编译器将一条汇编指令编译成一条机器码,在内存里一条指令占4字节内存,一条指令可以实现一个特定的功能 伪指令 不…

Hudi第二章:集成Spark(二)

系列文章目录 Hudi第一章:编译安装 Hudi第二章:集成Spark Hudi第二章:集成Spark(二) 文章目录 系列文章目录前言一、IDEA1.环境准备2.代码编写1.插入数据2.查询数据3.更新数据4.指定时间点查询5.增量查询6.删除数据7.覆盖数据 二、DeltaStre…

设计模式8、装饰者模式 Decorator

解释说明:动态地给一个对象增加一些额外的职责。就扩展功能而言,装饰模式提供了一种比使用子类更加灵活的替代方案 抽象构件(Component):定义一个抽象接口以规范准备收附加责任的对象 具体构件(ConcreteCom…

ELK整合springboot(第二课)

一、创建一个springboot的项目 pom文件如下&#xff1a; <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLo…

Mybatis 二级缓存(使用Redis作为二级缓存)

上一篇我们介绍了mybatis中二级缓存的使用&#xff0c;本篇我们在此基础上介绍Mybatis中如何使用Redis作为二级缓存。 如果您对mybatis中二级缓存的使用不太了解&#xff0c;建议您先进行了解后再阅读本篇&#xff0c;可以参考&#xff1a; Mybatis 二级缓存https://blog.csd…

Codeforces Round 894 (Div. 3) D(数学题好难不会)

题目链接&#xff1a;Codeforces Round 894 (Div. 3) D 题目&#xff1a; 特马决定提高自己制作冰淇淋的技能。他已经学会了如何用两个球把冰淇淋做成圆锥形。 在痴迷冰淇淋之前&#xff0c;特马对数学很感兴趣。因此&#xff0c;他很想知道要制作完全n个不同类型的冰淇淋&am…

Linux 基本语句_4_指针和函数

指针函数 顾名思义&#xff0c;即返回值为指针的函数 int * f (int n){int *p NULL;//空指针return p;//返回一个地址 }函数指针 指向函数的指针&#xff0c;每个函数都有自己的入口地址&#xff0c;函数指针专门指向这些地址#include <stdio.h>int max(int a, int b)…

前端任意修改地图风格颜色

在做地图相关应用时&#xff0c;常常遇到地图风格与UI界面不搭配的问题&#xff0c;如果在制图时就制作多种风格的地图&#xff0c;耗时耗力&#xff0c;超出成本控制。这里推荐一种快捷的方法&#xff0c;可在前端快速更改地图成任意风格&#xff0c;使色调与UI搭配。 先上一张…

【sql注入】如何通过SQL注入getshell?如何通过SQL注入读取文件或者数据库数据?一篇文章告诉你过程和原理。sql注入【二】

前言 本篇博客主要是通过piakchu靶场来讲解如何通过SQL注入漏洞来写入文件&#xff0c;读取文件。通过SQL输入来注入木马来getshell等&#xff0c;讲解了比较详细的过程&#xff1b; 如果想要学习SQL注入原理以及如何进行SQL注入&#xff0c;我也写了一篇详细的SQL注入方法及…

Apache Flume

Flume 1.9.0 Developer Guide【Flume 1.9.0开发人员指南】 Introduction【介绍】 摘自&#xff1a;Flume 1.9.0 Developer Guide — Apache Flume Overview【概述】 Apache Flume is a distributed, reliable, and available system for efficiently collecting, aggregati…

编程每日一练(多语言实现)基础篇:求总数问题

文章目录 一、实例描述二、技术要点三、代码实现3.1 C 语言实现3.2 Python 语言实现3.3 Java 语言实现3.4 JavaScript 语言实现 一、实例描述 集邮爱好者把所有的邮票存放在三个集邮册中&#xff0c;在A册内存放全部的十分之二&#xff0c;在B册内存放不知道是全部的七分之几&…

win11+wsl+git+cmake+x86gcc+armgcc+clangformat+vscode环境安装

一、安装wsl &#xff08;1&#xff09;打开power shell 并运行&#xff1a; Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform &#xff08;2&#xff0…