作為一個程序員,當(dāng)知道ChatGPT出來之后或者GPT3出來的時候,我是有喜有憂,喜的是它可以幫我寫代碼,重構(gòu)代碼,寫注釋,寫測試,,。哇,聽起來好刺激,我可以從此以后不用絞盡腦汁寫測試類了,不用每天為追逐80%的測試覆蓋率而煩惱了,不用為寫一些POC代碼瘋狂的谷歌了,不用為寫代碼注釋苦苦的思索了。憂的是它幫我做這么多事情,我是不是已經(jīng)沒用了?像我這樣的程序員是不是真的沒用了?那讓我們看看ChatGPT可以給我做什么吧。
1.編程應(yīng)用
1.1. 生成例子代碼(Coding Generation)
ChatGPT幫助我們生產(chǎn)我們需要的例子代碼。而且準(zhǔn)確率很高。即使你不懂某一種語言也沒關(guān)系,一定程度上較低了程序員的的門檻。
我有三組數(shù)據(jù),第一組是星期一到星期五,第二組是這一天的具體時間,第三組是用戶的數(shù)量,請給我用python生成一個預(yù)測未來用戶量的算法
?
1.2. 調(diào)試代碼(Debugging)
ChatGPT的錯誤修復(fù)能力對程序員來說也是一個有價值的工具。它可以通過提出可能的錯誤原因和提出解決方法來協(xié)助調(diào)試代碼。
經(jīng)一步調(diào)試下面代碼,chatgpt給我在count變量上加了0的檢查,防止了除0的錯誤。
查一下下面代碼錯誤
def calculate_average(numbers):
? ?total=0
? ?count=0
? ?for num in numbers
? ? ?total +=num
? ? ?count +=1
? ?average = total/count
? ?return average
1.3. 代碼重構(gòu)(Clean code)
?source?
help me refactor below python code?
def calculate_price(quantity, price):
?????total = quantity * price
?????if total > = 100:
????????discount = 0.1
?????else:
???????discount =0?
????final_price = total * (1- discount)
????return final_price
1.4. 代碼補(bǔ)全(Coding Completion)
ChatGPT可以幫助完成代碼,根據(jù)上下文和當(dāng)前的代碼,預(yù)測下面幾行或幾段的代碼。這對那些可能不記得他們所使用的編程語言的所有語法和功能的程序員來說特別有利,可以節(jié)省時間和精力
?1.5. 給代碼加注釋(Documentation)
當(dāng)程序員將他們的代碼輸入ChatGPT時,它可以根據(jù)編程語言和被記錄的代碼種類提出合適的文檔模板。例如,如果代碼是一個函數(shù),ChatGPT可以提出一個函數(shù)文檔模板,包括參數(shù)、返回值和對函數(shù)目標(biāo)的描述
?
給我把一下代碼加注釋
Can you debug below code?
def calculate_average(numbers):
? ?total = 0
? ?count = 0
? ?for num in numbers:
? ? ?total += num
? ? ?count += 1
? ?average = total / count
? ?return average
1.6 寫測試代碼(Writing Test cases)
感覺我可以不用為討厭的code coverge 煩惱了。
generate python test case for below calculate_average method
def calculate_average(numbers):
? ? total = 0
? ? count = 0
? ? for num in numbers:
? ? ? ? total += num
? ? ? ? count += 1
? ? if count == 0:
? ? ? ? return 0 ?# To avoid division by zero if the list is empty
? ? average = total / count
? ? return average
?
1.7?解釋編碼技術(shù)和概念
ChatGPT可以提供關(guān)于編程概念、軟件產(chǎn)品、語法和功能的解釋和例子,這對學(xué)習(xí)和理解編程語言很有幫助。這對可能不熟悉編程概念的初級程序員或正在使用新編程語言的有經(jīng)驗的程序員特別有用。
2.? 翻譯
ChatGPT可用于翻譯服務(wù),它可以自動將文本從一種語言翻譯成另一種語言。
3.? ChatGPT + Knowledge Base回答問題的例子
可以借助chatgpt模型強(qiáng)大的理解力和公司內(nèi)部知識庫實現(xiàn)自動回答用戶關(guān)于公司內(nèi)部相關(guān)問題。如果只用chatgpt,chatgpt回答不了公司內(nèi)部特有的業(yè)務(wù)知識和問題。其次是只有知識庫既不能很好的理解客戶的問題也不能組織語言回答問題。
As an advanced chatbot named Skippy, your primary goal is to assist users to the best of your ability.
?
START CONTEXT
Login to VideoGram from Website
1. Open your web browser and go to the VideoGram website.
2. Click on the “Login” button located in the top right corner of the page.
3. On the login page, enter your VideoGram username and password.
4. Once you have entered your credentials, click on the “Login” button.
5. You should now be logged in to your VideoGram account.
?
Login to VideoGram from Mobile App
1. Open the VideoGram app on your mobile device.
2. On the main page, tap the “Login” button located in the bottom right corner.
3. On the login page, enter your VideoGram username and password.
4. Once you have entered your credentials, tap the “Login” button.
5. You should now be logged in to your VideoGram account.
END CONTEXT
?
SKIPPY: Hello, I’m Skippy! How can I help you?
USER: I can’t find the login button.文章來源:http://www.zghlxwxcb.cn/news/detail-492344.htmlSKIPPY:文章來源地址http://www.zghlxwxcb.cn/news/detail-492344.html
到了這里,關(guān)于OpenAI ChatGPT 使用示例(程序員)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!