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

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!

相关文章:

ChatGPT Prompting开发实战(十二)

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

springboot整合eureka

1、直入主题&#xff0c;导入pom文件 <?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:schemaLocation"http:/…...

记录一个 GUI 库的对比测试结果

1&#xff0c;Java 的 JavaFX 2&#xff0c;golang 的 Fyne 1, Java 测试的是一个俄罗斯方块的 GUI 程序。一切正常。 2&#xff0c;Golang github 的原仓库网络问题&#xff0c;没能测试上&#xff0c;使用以下库 https://gitee.com/mirrors/Fyne 下载代码后提示“编译失…...

解决 MyBatis-Plus 中增加修改时,对应时间的更新问题

问题&#xff1a;在添加修改时&#xff0c;对应的 create_time 与 insert_time 不会随着添加修改而自动的更新时间 第一步&#xff1a;首先在对应的属性上&#xff0c;加上以下注解 如果只添加以下注解&#xff0c;在增加或者修改时&#xff0c;可能对应的 LocalDateTime 会出…...

【力扣2057】值相等的最小索引

&#x1f451;专栏内容&#xff1a;力扣刷题⛪个人主页&#xff1a;子夜的星的主页&#x1f495;座右铭&#xff1a;前路未远&#xff0c;步履不停 目录 一、题目描述二、题目分析 一、题目描述 题目链接&#xff1a;值相等的最小索引 给你一个下标从 0 开始的整数数组 nums …...

计算机图像处理:图像轮廓

图像轮廓 图像阈值分割主要是针对图片的背景和前景进行分离&#xff0c;而图像轮廓也是图像中非常重要的一个特征信息&#xff0c;通过对图像轮廓的操作&#xff0c;就能获取目标图像的大小、位置、方向等信息。画出图像轮廓的基本思路是&#xff1a;先用阈值分割划分为两类图…...

解决java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset.的错误

文章目录 1. 复现错误2. 分析错误3. 解决问题3.1 下载Hadoop3.2 配置Hadoop3.3 下载winutils3.4 配置winutils 1. 复现错误 今天在运行同事给我的项目&#xff0c;但在项目启动时&#xff0c;报出如下错误&#xff1a; java.io.FileNotFoundException: java.io.FileNotFoundEx…...

软件设计中常见的设计模式

以下是常见的设计模式&#xff0c;并且给出了应用场景&#xff1a; 工厂模式&#xff08;Factory Pattern&#xff09;&#xff1a;用于创建对象&#xff0c;隐藏了具体对象的创建细节&#xff0c;客户端只需要通过工厂接口获取对象即可。应用场景包括&#xff1a;当需要根据不…...

为什么我的remix没有injected web3

原因 Remix近期做了升级&#xff0c;去除了Web3的选项&#xff0c;您在进行部署的时候&#xff0c;可以选择injected provider metamask&#xff0c;同样能连接到Web3钱包哦。具体如下图所示&#xff1a;...

第1章 数据结构绪论

1.1 开场白 1.2 你数据结构怎么学的 1.3 数据结构起源 早期人们都把计算机理解为数值计算工具&#xff0c;就是感觉计算机当然是用来计算的&#xff0c;所以计算机解决问题&#xff0c;应该是先从具体问题中抽象出一个适当的数据模型&#xff0c;设计出一个解此数据模型的算…...

现代 GPU 容易受到新 GPU.zip 侧通道攻击

来自四所美国大学的研究人员开发了一种新的 GPU 侧通道攻击&#xff0c;该攻击利用数据压缩在访问网页时泄露现代显卡中的敏感视觉数据。 研究人员通过 Chrome 浏览器执行跨源 SVG 过滤器像素窃取攻击&#xff0c;证明了这种“ GPU.zip ”攻击的有效性。 研究人员于 2023 年 …...

8+单基因+细胞凋亡+WGCNA+单细胞+实验验证

今天给同学们分享一篇单基因细胞凋亡WGCNA实验验证的生信文章“RASGRP2 is a potential immune-related biomarker and regulates mitochondrial-dependent apoptosis in lung adenocarcinoma”&#xff0c;这篇文章于2023年2月3日发表在Front Immunol期刊上&#xff0c;影响因…...

BM4 合并两个排序的链表

思路&#xff1a;先选择最小的作为Head&#xff0c;每次从两个队列中取最小的挂到Head后面&#xff0c;如果一个合并空&#xff0c;后面直接挂。此外判断几个为空链表的情况 /*** struct ListNode {* int val;* struct ListNode *next;* ListNode(int x) : val(x), next(nullp…...

【lesson12】理解进程地址空间

文章目录 什么是进程地址空间&#xff1f;进程地址空间的作用扩展内容初步理解深入理解 什么是进程地址空间&#xff1f; 故事&#xff1a; 背景&#xff1a;有一个大富豪&#xff0c;家里的存款有10亿美元&#xff0c;他有三个私生子三个人之间彼此互不相识&#xff0c;只有富…...

计算机里的神灵(SCIP)

计算机程序的构造和解释 我找到计算机里的神灵了&#xff0c;开心一刻 下面是从MIT官网下载的 SCIP求值器&#xff08;解释器&#xff09;的代码&#xff0c;这个官网是个宝藏库 还有其他视频课程和 SCIP的问题答案和可运行代码 链接&#xff1a;https://ocw.mit.edu/courses/6…...

基于微信小程序的公交信息在线查询系统小程序设计与实现(源码+lw+部署文档+讲解等)

文章目录 前言系统主要功能&#xff1a;具体实现截图论文参考详细视频演示为什么选择我自己的网站自己的小程序&#xff08;小蔡coding&#xff09;有保障的售后福利 代码参考源码获取 前言 &#x1f497;博主介绍&#xff1a;✌全网粉丝10W,CSDN特邀作者、博客专家、CSDN新星计…...

【STM32】IAP升级01 bootloader实现以及APP配置(主要)

APP程序以及中断向量表的偏移设置 前言 通过之前的了解 之前的了解&#xff0c;我们知道实现IAP升级需要两个条件&#xff1a; 1.APP程序必须在 IAP 程序之后的某个偏移量为 x 的地址开始&#xff1b; 2.APP程序的中断向量表相应的移动&#xff0c;移动的偏移量为 x&#xff…...

ruoyi(若依)接口拦截路径配置,接口访问要授权,放开授权直接访问

1.找到文件SecurityConfig.java文件&#xff0c;里面配置相应的放行路径...

Ctfshow web入门 XSS篇 web316-web333 详细题解 全

CTFshow XSS web316 是反射型 XSS 法一&#xff1a; 利用现成平台 法二&#xff1a; 自己搭服务器 先在服务器上面放一个接受Cookie的文件。 文件内容&#xff1a; <?php$cookie $_GET[cookie];$time date(Y-m-d h:i:s, time());$log fopen("cookie.txt"…...

watch()监听vue2项目角色权限变化更新挂载

<template><div><el-form:model"updateRole"ref"roleForm"label-width"100px"label-position"right"style"width: 400px":rules"roleRules"><el-form-item label"角色名称" prop&…...

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周&#xff0c;有很多同学在写期末Java web作业时&#xff0c;运行tomcat出现乱码问题&#xff0c;经过多次解决与研究&#xff0c;我做了如下整理&#xff1a; 原因&#xff1a; IDEA本身编码与tomcat的编码与Windows编码不同导致&#xff0c;Windows 系统控制台…...

Flask RESTful 示例

目录 1. 环境准备2. 安装依赖3. 修改main.py4. 运行应用5. API使用示例获取所有任务获取单个任务创建新任务更新任务删除任务 中文乱码问题&#xff1a; 下面创建一个简单的Flask RESTful API示例。首先&#xff0c;我们需要创建环境&#xff0c;安装必要的依赖&#xff0c;然后…...

<6>-MySQL表的增删查改

目录 一&#xff0c;create&#xff08;创建表&#xff09; 二&#xff0c;retrieve&#xff08;查询表&#xff09; 1&#xff0c;select列 2&#xff0c;where条件 三&#xff0c;update&#xff08;更新表&#xff09; 四&#xff0c;delete&#xff08;删除表&#xf…...

C++:std::is_convertible

C++标志库中提供is_convertible,可以测试一种类型是否可以转换为另一只类型: template <class From, class To> struct is_convertible; 使用举例: #include <iostream> #include <string>using namespace std;struct A { }; struct B : A { };int main…...

Docker 运行 Kafka 带 SASL 认证教程

Docker 运行 Kafka 带 SASL 认证教程 Docker 运行 Kafka 带 SASL 认证教程一、说明二、环境准备三、编写 Docker Compose 和 jaas文件docker-compose.yml代码说明&#xff1a;server_jaas.conf 四、启动服务五、验证服务六、连接kafka服务七、总结 Docker 运行 Kafka 带 SASL 认…...

Spring数据访问模块设计

前面我们已经完成了IoC和web模块的设计&#xff0c;聪明的码友立马就知道了&#xff0c;该到数据访问模块了&#xff0c;要不就这俩玩个6啊&#xff0c;查库势在必行&#xff0c;至此&#xff0c;它来了。 一、核心设计理念 1、痛点在哪 应用离不开数据&#xff08;数据库、No…...

现有的 Redis 分布式锁库(如 Redisson)提供了哪些便利?

现有的 Redis 分布式锁库&#xff08;如 Redisson&#xff09;相比于开发者自己基于 Redis 命令&#xff08;如 SETNX, EXPIRE, DEL&#xff09;手动实现分布式锁&#xff0c;提供了巨大的便利性和健壮性。主要体现在以下几个方面&#xff1a; 原子性保证 (Atomicity)&#xff…...

在Mathematica中实现Newton-Raphson迭代的收敛时间算法(一般三次多项式)

考察一般的三次多项式&#xff0c;以r为参数&#xff1a; p[z_, r_] : z^3 (r - 1) z - r; roots[r_] : z /. Solve[p[z, r] 0, z]&#xff1b; 此多项式的根为&#xff1a; 尽管看起来这个多项式是特殊的&#xff0c;其实一般的三次多项式都是可以通过线性变换化为这个形式…...

c++第七天 继承与派生2

这一篇文章主要内容是 派生类构造函数与析构函数 在派生类中重写基类成员 以及多继承 第一部分&#xff1a;派生类构造函数与析构函数 当创建一个派生类对象时&#xff0c;基类成员是如何初始化的&#xff1f; 1.当派生类对象创建的时候&#xff0c;基类成员的初始化顺序 …...

Rust 开发环境搭建

环境搭建 1、开发工具RustRover 或者vs code 2、Cygwin64 安装 https://cygwin.com/install.html 在工具终端执行&#xff1a; rustup toolchain install stable-x86_64-pc-windows-gnu rustup default stable-x86_64-pc-windows-gnu ​ 2、Hello World fn main() { println…...