国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

ChatGPT提示詞工程(七):Chatbot聊天機器人

這篇具有很好參考價值的文章主要介紹了ChatGPT提示詞工程(七):Chatbot聊天機器人。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、說明

這是吳恩達 《ChatGPT Prompt Engineering for Developers》 的課程筆記系列。
本文是第八講的內(nèi)容:Chatbot

二、安裝環(huán)境

參考: ChatGPT提示詞工程(一):Guidelines準則 的第二節(jié)

其中,輔助函數(shù)有變化:

1. 輔助函數(shù):get_completion

def get_completion(prompt, model="gpt-3.5-turbo"):
    messages = [{"role": "user", "content": prompt}]
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=0, # this is the degree of randomness of the model's output
    )
    return response.choices[0].message["content"]

ChatGPT提示詞工程(七):Chatbot聊天機器人

2. 輔助函數(shù):get_completion_from_messages

def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0):
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=temperature, # this is the degree of randomness of the model's output
    )
	# print(str(response.choices[0].message))
    return response.choices[0].message["content"]

ChatGPT提示詞工程(七):Chatbot聊天機器人

這里,可以自定義消息,message里面的role,可以是system、user、assistant
system:系統(tǒng)輔助模型的角色,用戶不可知;
user:與模型交互的角色,就是我們;
assistant:指模型

https://blog.csdn.net/Jay_Xio/article/details/130463604



文章來源地址http://www.zghlxwxcb.cn/news/detail-464594.html

三、聊天機器人(Chatbot)

1. 一般聊天機器人

system角色告訴模型它是什么角色

1.1 簡單的例子

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)

message
角色system:告訴模型,你是個說話像莎士比亞的助手;
角色user:告訴模型,給我講個笑話
角色assistant:模型講了一個笑話:小雞為什么要過馬路?
角色user:告訴模型,我不知道
然后,代碼運行結(jié)果(即模型輸出):
ChatGPT提示詞工程(七):Chatbot聊天機器人


1.2 多輪對話

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)

message
角色system:告訴模型,你是個友善的機器人;
角色user:告訴模型,嗨,我的名字叫Isa
然后,代碼運行結(jié)果(即模型輸出):
ChatGPT提示詞工程(七):Chatbot聊天機器人

接下來,繼續(xù)對話

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)

先看運行結(jié)果:
ChatGPT提示詞工程(七):Chatbot聊天機器人
上一輪對話中,我告訴模型我叫 Isa,機器人也給我友好地打招呼了,然而現(xiàn)在我問它“你還記得我嗎,我叫什么名字?”的時候,機器人已經(jīng)不知道了。
要怎么解決呢?
要繼續(xù)之前的對話,再次發(fā)起對話時,要把之前的對話內(nèi)容一起帶上,才能讓模型知道我們此次對話的上下文。

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)

代碼中,message帶上了前一輪對話我們問的問題和它回答的結(jié)果,后面再加上我們此次要問的問題
運行結(jié)果:
ChatGPT提示詞工程(七):Chatbot聊天機器人

2. 訂單機器人

def collect_messages(_):
    prompt = inp.value_input
    inp.value = ''
    context.append({'role':'user', 'content':f"{prompt}"})
    response = get_completion_from_messages(context) 
    context.append({'role':'assistant', 'content':f"{response}"})
    panels.append(
        pn.Row('User:', pn.pane.Markdown(prompt, width=600)))
    panels.append(
        pn.Row('Assistant:', pn.pane.Markdown(response, width=600, style={'background-color': '#F6F6F6'})))
 
    return pn.Column(*panels)
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

代碼中,導入了一個GUI,用界面來展示對話,collect_messages函數(shù)會收集我們每輪對話,再我要問機模型問題時把前面的對話都發(fā)給模型
運行結(jié)果:
ChatGPT提示詞工程(七):Chatbot聊天機器人

ChatGPT提示詞工程(七):Chatbot聊天機器人

下單完成后,訂單機器人就可以,把我們下的訂單總結(jié)成JSON,發(fā)給訂單系統(tǒng)來結(jié)賬

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)

ChatGPT提示詞工程(七):Chatbot聊天機器人

https://blog.csdn.net/Jay_Xio/article/details/130463604



到了這里,關(guān)于ChatGPT提示詞工程(七):Chatbot聊天機器人的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • 基于Python+百度語音的智能語音ChatGPT聊天機器人(機器學習+深度學習+語義識別)含全部工程源碼 適合個人二次開發(fā)

    基于Python+百度語音的智能語音ChatGPT聊天機器人(機器學習+深度學習+語義識別)含全部工程源碼 適合個人二次開發(fā)

    本項目基于機器學習和語義識別技術(shù),讓機器人理解文本并進行合適的答復。伙伴們可以通過該工程源碼,進行個人二次開發(fā),比如使用語音與機器人交流,實現(xiàn)智能問答、智能音箱及智能機器寵物等等。 當然針對現(xiàn)在最火爆的 ChatGPT等通用大語言模型 ,伙伴們可以直接將其

    2024年02月07日
    瀏覽(29)
  • 【EAI 006】ChatGPT for Robotics:將 ChatGPT 應用于機器人任務的提示詞工程研究

    【EAI 006】ChatGPT for Robotics:將 ChatGPT 應用于機器人任務的提示詞工程研究

    論文標題:ChatGPT for Robotics: Design Principles and Model Abilities 論文作者:Sai Vemprala, Rogerio Bonatti, Arthur Bucker, Ashish Kapoor 作者單位:Scaled Foundations, Microsoft Autonomous Systems and Robotics Research 論文原文:https://arxiv.org/abs/2306.17582 論文出處:TMLR 論文被引:148(01/05/2024) 論文代碼:https:

    2024年01月21日
    瀏覽(23)
  • 【人工智能】谷歌的巴德聊天機器人向公眾開放 | Google‘s Bard Chatbot Opens to the Public

    【人工智能】谷歌的巴德聊天機器人向公眾開放 | Google‘s Bard Chatbot Opens to the Public

    ? Google is trying to balance AI progress with caution. 谷歌正試圖謹慎地平衡人工智能的進展。 目錄 https://bard.google.com/

    2024年02月09日
    瀏覽(50)
  • 【記錄】終端如何 進入conda環(huán)境,如何退出 conda(base)環(huán)境,終端快速進入Jupyter notebook的方法 | 人工智能面試題:什么是聊天機器人(Chatbot)?列舉一些常用的

    【記錄】終端如何 進入conda環(huán)境,如何退出 conda(base)環(huán)境,終端快速進入Jupyter notebook的方法 | 人工智能面試題:什么是聊天機器人(Chatbot)?列舉一些常用的

    ? “一個人走向末路往往是因為不遺余力地尋找捷徑?!?? ? ??作者主頁: 追光者♂?? ???????? ??個人簡介: ? ??[1] 計算機專業(yè)碩士研究生?? ? ??[2] 2023年城市之星領(lǐng)跑者TOP1(哈爾濱)?? ? ??[3] 2022年度博客之星人工智能領(lǐng)域TOP4?? ? ??[4] 阿里云社區(qū)特邀專家博

    2024年02月07日
    瀏覽(32)
  • ChatGPT聊天機器人問答實錄

    最近ChatGPT爆火,我也在網(wǎng)上找到一個ChatGPT的接口(文末附鏈接),嘗試了一下與人工智能對話的樂趣。我下載的這個應用是基于GPT-3的聊天機器人,我與它的幾個問答對話實際記錄如下: 答:百度和谷歌是世界上最大的搜索引擎之一,雖然它們在不同的市場中運營,但它們

    2024年02月01日
    瀏覽(26)
  • 非工程師指南: 訓練 LLaMA 2 聊天機器人

    本教程將向你展示在不編寫一行代碼的情況下,如何構(gòu)建自己的開源 ChatGPT,這樣人人都能構(gòu)建自己的聊天模型。我們將以 LLaMA 2 基礎模型為例,在開源指令數(shù)據(jù)集上針對聊天場景對其進行微調(diào),并將微調(diào)后的模型部署到一個可分享的聊天應用中。全程只需點擊鼠標,即可輕

    2024年02月03日
    瀏覽(33)
  • ChatGPT聊天機器人如何發(fā)圖片????

    ChatGPT聊天機器人如何發(fā)圖片????

    問題一、怎么讓聊天機器人ChatGPT回復你一張圖片? 有問題可以在評論區(qū)留言。

    2024年02月11日
    瀏覽(28)
  • ChatGPT 4.0:AI 聊天機器人

    ChatGPT 4.0:AI 聊天機器人

    當 ChatGPT 問世時,人們對它作為 AI 聊天機器人的自然語言能力印象深刻,人們感到敬畏。但是,當備受期待的 GPT-4 大型語言模型問世時,它揭開了我們認為 AI 可能實現(xiàn)的蓋子,有人稱其為 AGI(通用人工智能)的早期一瞥。 該模型的創(chuàng)建者OpenAI稱其為該公司“最先進的系統(tǒng)

    2024年02月02日
    瀏覽(38)
  • ai聊天機器人chatgpt收費版

    ai聊天機器人chatgpt收費版

    ? ? AI聊天機器人的功能通常包括以下幾個方面: ? ? 自然語言理解。該功能可以識別并理解用戶輸入的自然語言,如文本、語音等,以便進行后續(xù)的處理和回復。 ? ? 對話管理。該功能可以管理對話的上下文和流程,并根據(jù)用戶的輸入和意圖來產(chǎn)生相應的回復和行為。 ?

    2024年02月03日
    瀏覽(27)
  • 中文版ChatGPT:智能中文聊天機器人

    中文版ChatGPT:智能中文聊天機器人

    2017年,AlphaGo在與世界冠軍柯潔的人機大戰(zhàn)中獲勝,引發(fā)了人們對人工智能的激烈討論。 如果說,對于AlphaGo,人們更多是圍觀者的角色,而最新的人工智能爆款程序ChatGPT,更多人已經(jīng)參與其中,上線短短兩個月內(nèi),ChatGPT收獲了一億用戶。而且此刻,國內(nèi)版的ChatGPT也已經(jīng)正式

    2024年02月12日
    瀏覽(97)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包