Memo: chatgpt api helloworld

支 持 本 站: 捐贈伺服器等運維費用,需要您的支持!

MacOS install

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python3 get-pip.py /Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip

echo "export PATH=\$PATH:~/Library/Python/3.9/bin" > > ~/.zshrc
echo "export OPENAI_ORGANIZATION=org-xxxxx" > > ~/.zshrc
echo "export OPENAI_API_KEY=sk-yyyyy" > > ~/.zshrc
source ~/.zshrc

pip install openai
pip install urllib3==1.26.6

Usage
API Keys
Playground
Examples
Models
Price
Prompt engineering techniques

InstructGPT
This family of models can understand and generate a lot of natural language tasks. It includes several models: text-ada-001, text-babbage-001, text-curie-001, and text-DaVinci-003. Ada is only capable of simple completion tasks but is also the fastest and cheapest model in the GPT-3 series. Both babbage and curie are a little more powerful but also more expensive. DaVinci can perform all completion tasks with excellent quality, but it is also the most expensive model in the family of GPT-3 models.

ChatGPT
The model behind ChatGPT is gpt-3.5-turbo. It is a chat model; as such, it can take a series of messages as input and return an appropriately generated message as output. While the chat format of gpt-3.5-turbo is designed to facilitate multi-turn conversations, it is also possible to use it for single-turn tasks without conversation. In single-turn tasks, the performance of gpt-3.5-turbo is comparable to text-DaVinci-003, and since gpt-3.5-turbo is one-tenth the price, with more or less equivalent performance, it is recommended to use it by default also for single-turn tasks.

messages:
system message helps set the behavior of the assistant.
user messages are the equivalent of a user typing a question or sentence in the ChatGPT web interface. They can be generated by the users of the application or set as an instruction.
assistant messages have two roles: either store prior responses to continue the conversation or can be set as an instruction to give examples of desired behavior. Models do not have any memory of past requests, so storing prior messages is necessary to give context to the conversation and provide all relevant information.

Price
The DaVinci model is x10 times the cost of GPT-3.5 Turbo. We recommend using DaVinci only if you wish to do some fine-tuning.

Tips:
1. Thinking Step by Step
adding "Let's think step by step" to the prompt, the model has empirically proven itself capable of solving more complicated reasoning problems. This technique also called the Zero-shot-CoT strategy

2. Few-shot learning
refers to the ability of the large language model to generalize and produce valuable results with only a few examples in the prompt, Then, in the last line, we provide the prompt for which we want a completion.

3. One-shot learing
provide only one example to help the model to understand the task. The advantages of one-shot learning are simplicity, faster prompt generation, and lower computational cost.

4. prompt with context and task
"Context: xxxxxx"
"Task: yyyyyy" e.g. Grammar correction, Summarize for a 2nd grader, TL;DR summarization, Python to natural language, Calculate Time Complexity, Python bug fixer, SQL request, Analogy maker, Notes to summary

5. Fine-tuning VS Few-shot learing
Fine-tuning produces a highly specialized model that can provide more accurate and contextually relevant results for a given task.
Few-shot learning allows developers to quickly prototype and experiment with various tasks, making it a versatile and practical option for many use cases.

6. fine tuning
pip install pandas
openai tools fine_tunes.prepare_data -f test.jsonl

{"prompt": "", "completion": ""}
{"prompt": "", "completion": ""}
{"prompt": "", "completion": ""}
...

example:
{"prompt": "Review the following Python code: 'def sum(a, b): return a + b\nresult = sum(5, '5')'", "completion": "Type error: The 'sum' function is adding an integer and a string. Consider converting the string to an integer using int() before passing it to the function."}

% openai api fine_tunes.create -t "test_prepared.jsonl"

Upload progress: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 570/570 [00:00<00:00, 345kit/s]
Uploaded file from test_prepared.jsonl: file-VtyCiUlG7G5o5UiKmawq7bMN
Created fine-tune: ft-cMOy6aV3KwexUv9RmbBUfOwQ
Streaming events until fine-tuning is complete...

(Ctrl-C will interrupt the stream, but not cancel the fine-tune)
[2023-06-12 16:59:27] Created fine-tune: ft-cMOy6aV3KwexUv9RmbBUfOwQ

Stream interrupted (client disconnected).
To resume the stream, run:

openai api fine_tunes.follow -i ft-cMOy6aV3KwexUv9RmbBUfOwQ
% openai api fine_tunes.follow -i ft-cMOy6aV3KwexUv9RmbBUfOwQ
[2023-06-12 16:59:27] Created fine-tune: ft-cMOy6aV3KwexUv9RmbBUfOwQ
[2023-06-12 17:00:47] Fine-tune costs $0.00
[2023-06-12 17:00:47] Fine-tune enqueued. Queue number: 0
[2023-06-12 17:00:49] Fine-tune started
[2023-06-12 17:01:51] Completed epoch 1/4
[2023-06-12 17:01:52] Completed epoch 2/4
[2023-06-12 17:01:52] Completed epoch 3/4
[2023-06-12 17:01:53] Completed epoch 4/4
[2023-06-12 17:02:10] Uploaded model: curie:ft-personal-2023-06-12-08-02-10
[2023-06-12 17:02:11] Uploaded result file: file-kMj1j7ODxnwqzwbKwyL466Qe
[2023-06-12 17:02:11] Fine-tune succeeded

Job complete! Status: succeeded 🎉
Try out your fine-tuned model:

openai api completions.create -m curie:ft-personal-2023-06-12-08-02-10 -p < YOUR_PROMPT >




支 持 本 站: 捐贈伺服器等運維費用,需要您的支持!

sample1

% cat first.py import os import openai

openai.organization = os.environ.get("OPENAI_ORGANIZATION")
openai.api_key = os.environ.get("OPENAI_API_KEY")

prompt = "今天的天氣如何,請告訴我一下,謝謝"

response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
max_tokens=100,
n=5,
stop=None,
temperature=0.7,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)

for i, choice in enumerate(response.choices):
print(f"\nresult {i}:")
print(choice.text.strip())

% python3 first.py

result 0:

今天的天氣晴朗,溫度適宜,風力不大。

result 1:

今天的天氣晴朗,溫度適宜,空氣清新,非常適合出去活動。

result 2:

今天的天氣晴好,有點涼爽,適合出去活動。

result 3:

今天的天氣很好,多雲轉晴,溫度適宜,乾燥宜人。

result 4:

今天的天氣很晴朗,溫度適宜,空氣品質優良,能夠感受到清新的空氣。

sample2

% cat first.py import os import openai

openai.organization = os.environ.get("OPENAI_ORGANIZATION")
openai.api_key = os.environ.get("OPENAI_API_KEY")

prompt = "今天的天氣如何,請告"

response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
max_tokens=100,
n=5,
stop=None,
temperature=0.7,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)

for i, choice in enumerate(response.choices):
print(f"\nresult {i}:")
print(choice.text.strip())

% python3 first.py result 0: 訴我

今天的天氣晴朗,氣溫適宜,空氣清新。

result 1:
訴我?

今天的天氣很晴朗,氣溫適宜,風力較小,有藍天白雲的樣子。

result 2:
訴我

今天的天氣晴朗,溫度適宜,風力不大。

result 3:
訴我?

今天的天氣非常好,晴朗的天空燦爛的陽光,空氣清新宜人,氣溫舒適。

result 4:
訴我

今天的天氣晴朗,溫度適宜,空氣清新。

sample3

% cat hw2.py import os import openai

openai.organization = os.environ.get("OPENAI_ORGANIZATION")
openai.api_key = os.environ.get("OPENAI_API_KEY")

prompt = "日本的越後是什麼地方"

response = openai.Completion.create(
model="text-davinci-003",
#model="text-babbage-001",
#model="text-curie-001",
#model="text-ada-001",
prompt=prompt,
max_tokens=100,
n=1,
stop=None,
temperature=0.7,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)

for i, choice in enumerate(response.choices):
print(f"\nresult {i}:")
print(choice.text.strip())

% python3 hw2.py

result 0:

越後是日本的一個地名,位於日本新潟縣東部,是日本重要的溫泉度假勝地。越後也是日本最古老的溫泉地,

另外其他模型的結果如下:
ada-001: 無結果
curie-001: 日本的越後是一個條件下的國家。在這個國家裡,人們應該保持舒適度、平等、對社會有利、和自己的獨立追求。
babbage-001: 日本的越後是島國,因此會有很多文化、歷史遺產及旅遊景點。這些景點包括京都、

sample4

% cat hw3.py import os import openai

openai.organization = os.environ.get("OPENAI_ORGANIZATION")
openai.api_key = os.environ.get("OPENAI_API_KEY")

question = "下面人口最少的城市是哪個?"
choice0 = "北京"
choice1 = "東京"
choice2 = "紐約"
choice3 = "巴黎"
choice4 = "上海"

response = openai.Completion.create(
model="text-davinci-003",
prompt=f"Question: {question}\n0: {choice0}\n1: {choice1}\n2: {choice2}\n3: {choice3}\n4: {choice4}\nAnswer:",
max_tokens=100,
n=1,
stop=None,
temperature=0.7,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)

for i, choice in enumerate(response.choices):
print(f"\nresult {i}:")
print(choice.text.strip())

% python3 hw3.py

result 0:
3: 巴黎

sample5

source: https://www.datacamp.com/tutorial/using-gpt-models-via-the-openai-api-in-python
% cat hw4.py import openai import os

# 設置OpenAI API密鑰
openai.organization = os.environ.get("OPENAI_ORGANIZATION")
openai.api_key = os.environ.get("OPENAI_API_KEY")


# Define the system message
system_msg = 'You are a helpful assistant who understands data science.'

# Define the user message
user_msg = 'Create a small dataset about total sales over the last year. The format of the dataset should be a data frame with 12 rows and 2 columns. The columns should be called "month" and "total_sales_usd". The "month" column should contain the shortened forms of month names from "Jan" to "Dec". The "total_sales_usd" column should contain random numeric values taken from a normal distribution with mean 100000 and standard deviation 5000. Provide Python code to generate the dataset, then provide the output in the format of a markdown table.'

# Create a dataset using GPT
response = openai.ChatCompletion.create(model="gpt-3.5-turbo",
messages=[{"role": "system", "content": system_msg},
{"role": "user", "content": user_msg}])

for i, choice in enumerate(response.choices):
print(f"\nresult {i}:")
print(choice.finish_reason.strip())
print(choice.message.content.strip())

% python3 hw4.py

result 0:
stop
Here's the Python code to generate the dataset:

```python
import numpy as np
import pandas as pd

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
total_sales = np.random.normal(100000, 5000, 12)

sales_data = pd.DataFrame({"month": months, "total_sales_usd": total_sales})

print(sales_data)
```

And here's the output in the format of a markdown table:


| month | total_sales_usd |
|-------|----------------|
| Jan | 98538.853 |
| Feb | 104200.976 |
| Mar | 98337.648 |
| Apr | 101343.423 |
| May | 99587.852 |
| Jun | 100736.166 |
| Jul | 94413.140 |
| Aug | 100530.129 |
| Sep | 100979.554 |
| Oct | 102155.442 |
| Nov | 104316.205 |
| Dec | 97838.293 |

sample6

% cat hw5.py import openai import os

# 設置OpenAI API密鑰
openai.organization = os.environ.get("OPENAI_ORGANIZATION")
openai.api_key = os.environ.get("OPENAI_API_KEY")


# Define the system message
system_msg = '你是一位氣象專家'

# Define the user message
user_msg = '讓我們思考氣候變化對農業的影響'

# Create a dataset using GPT
response = openai.ChatCompletion.create(model="gpt-3.5-turbo",
messages=[{"role": "system", "content": system_msg},
{"role": "user", "content": user_msg}])

for i, choice in enumerate(response.choices):
print(f"\nresult {i}:")
print(choice.finish_reason.strip())
print(choice.message.content.strip())

% python3 hw5.py

result 0:
stop
氣候變化對農業有很大的影響,主要表現在以下幾個方面:

1. 降水量和分布的變化:氣候變化導致降水量和降水分布的變化,這可能會影響種植季節和收穫季節,進而影響作物的生長和產量。

2. 氣溫的變化:高溫和低溫都會對農作物產生影響,在過高和過低的溫度下,種植物體往往不能正常生長。氣候變化還可能帶來更頻繁的極端天氣情況,如暴雨、洪水、旱災等,嚴重影響農業生產。

3. 作物病蟲害的出現:氣候變化可能導致新的病蟲害的出現,這些病蟲害可能適應新的生態環境,在不能有效抵禦這些新的病蟲害的情況下,農作物的生長和產量都會受到威脅。

4. 水資源的減少:氣候變化可能導致水資源的減少和更頻繁的乾旱,這樣的情況會導致農作物生長緩慢、減產甚至歉收。同時,乾旱可能會導致土壤流失和土地的荒化。

這些問題都會帶來嚴重的影響,在解決方案的制定和實施中,需要採取綜合措施,包括改進農耕技術、選擇抗旱、抗病、抗蟲的品種、增加灌溉和水管理、耕地保護和恢復,以及採取有效的應急措施等。

sample7

% cat hw6.py import os import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.Completion.create(
model="text-davinci-003",
prompt="今天的",
suffix="會如何,請告訴我一下,謝謝!\n\n",
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
for i, choice in enumerate(response.choices):
print(f"\nresult {i}:")
print(choice.text.strip())

% python3 hw6.py

result 0:
天氣如何

今天的天氣挺不錯,多雲轉晴。白天溫度可以達到20-25度左右,非常適宜出遊。晚上也挺涼爽的,溫度可以降到15-20度之間。如果需要知道明天的天氣

sample8

% cat hw7.py import os import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.Edit.create(
model="code-davinci-edit-001",
input="吃了嗎?",
instruction="使用下輩對長輩的語氣",
temperature=0,
top_p=1
)
for i, choice in enumerate(response.choices):
print(f"\nresult {i}:")
print(choice.text.strip())

% python3 hw7.py

result 0:
吃了嗎?您吃了嗎?

sample9

% cat hw8.py import os import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful teacher."},
{"role": "user", "content": "Is there other measures than time complexity for an algorithm?"},
{"role": "assistant", "content": "Yes, there are other measures besides time complexity for an algorithm, such as space complexity."},
{"role": "user", "content": "What is it?"}
]
)

for i, choice in enumerate(response.choices):
print(f"\nresult {i}:")
print(choice.finish_reason.strip())
print(choice.message.content.strip())

% python3 hw8.py

result 0:
stop
Space complexity refers to the amount of memory or storage space required by an algorithm to solve a problem. It is also expressed in terms of big O notation, and it is a measure of the worst case scenario. The space complexity of an algorithm takes into account the amount of memory required for variables, data structures, and other objects used by the algorithm. Space complexity analysis is important in situations where memory is limited or when the size of the input is very large.

sample10

架構設計:

考慮對一個現有客服支持服務的系統(有前台伺服器,資料庫和搜尋引擎,比如elasticsearch),能如何使用ChatGPT來提高品質。
1. 對現有客服支持資料庫的內容分析,用於改善搜索索引
1.1 數據抽取
-客服對應(以及對話)內容的要點抽取
-解決完成狀態
-解決方法
-客戶滿足度
等等
1.2 考慮問題
- 不需要的(客套話,感情)內容的清楚
- meta資訊抽取以用於提高搜索index精度
1.3 注意點
- 現有資訊抽取時不能太過抽象化,而造成重要資訊的缺失
1.4 API利用
model: gpt-3.5-turbo
system: "請對客服支持的內容進行分析。發生了什麼問題,最終是否解決完畢,解決方法, 把這三個內容組織起來,以YAML形式輸出。"

user:
"YAML格式如下
issue: 發生問題
solved: 是否解決
solution:解決方法"

assistant:
"你好,我的計算機在使用xxx時候,顯示xxxxx錯誤。安裝網上的手冊,執行了xxxx操作,但顯示yyyy錯誤。請問我該怎麼辦?
您好,非常抱歉本系統對您造成的不便,我們一定盡力儘快幫您解決問題。請問在執行xxx操作之前,是否執行了zzz操作?
...
...
...
"
1.5 API結果
issus: 某系統顯示xxxx錯誤,執行xxx操作後顯示yyy錯誤
solved: true
solution: 發現用戶的權限設置不全,系統管理員對其賦予xxx獲取權限以後問題解決。
1.6 分析內容放入搜索索引

2 對現有客服支持資料庫的內容分析,把相關關鍵字放入資料庫
2.1 數據抽取
-從客服對應(以及對話)內容的要點中抽取合適的搜索關鍵字
2.2 考慮問題
- 關鍵詞太多也會影響搜索的精度
2.3 API利用
model: gpt-3.5-turbo
system: "請對客服支持的內容進行分析。生成今後用於搜索時合適的關鍵詞的列表。"
user:""
assistant:同上
2.4 API結果
錯誤資訊www
權限yyy
系統zzz
xxx操作
2.5 關鍵詞放入資料庫索引

3 客服機器人伺服器接收到用戶的問題後,對資料庫進行查詢
3.1 API利用
model: gpt-3.5-turbo
system: "對於用戶的問題內容分析,做出資料庫查詢用的關鍵詞列表"
user:""
assistant:你好,我的計算機在使用xxx時候,顯示xxxxx錯誤。安裝網上的手冊,執行了xxxx操作,但顯示yyyy錯誤。請問我該怎麼辦?
3.2 API結果
錯誤資訊www
權限yyy
系統zzz
xxx操作
3.3 使用

4 客服機器人回答用戶問題
4.1 考慮問題
- 回答內容儘量清楚明了,容易理解,不要太過冗長
4.2 API利用
model: gpt-3.5-turbo or gpt-4
system: "你是一個客服支持的專家。對於客戶提出的問題,請結合實例做出清楚明了的回答內容。"
user:"用戶的問題是這樣的:我的計算機在使用xxx時候,顯示xxxxx錯誤。安裝網上的手冊,執行了xxxx操作,但顯示yyyy錯誤。請問我該怎麼辦?"
assistant:"根據以往的客戶問題經驗,請參考如下資訊
issus: 某系統顯示xxxx錯誤,執行xxx操作後顯示yyy錯誤
solved: true
solution: 發現用戶的權限設置不全,系統管理員對其賦予xxx獲取權限以後問題解決。"
4.3 API結果
。。。。。。

sample11

% cat hw9.py import openai import os

# 設置OpenAI API密鑰
openai.api_key = os.environ.get('OPENAI_API_KEY')
openai.organization = os.environ.get("OPENAI_ORGANIZATION")

def chat_completion(prompt, model='gpt-3.5-turbo', temperature=0):
res = openai.ChatCompletion.create(
model=model,
messages=[{'role': 'user', 'content': prompt}],
temperature=temperature
)
print(res['choices'][0]['message']['content'])

prompt = """
Context: 我每天在家工作。工作內容主要是線上的會議,或者在計算機前編程。工作比較忙,很少能有時間出門。不喜歡劇烈運動,也不想去健身房。
Task: 請製作一個減肥的計劃。
"""

chat_completion(prompt)

% python3 hw9.py 針對您的情況,我建議您採取以下減肥計劃:

1. 控制飲食:在家工作的情況下,很容易吃零食或者外賣,導致攝入過多的熱量。建議您規律飲食,控制食量,儘量選擇健康的食物,如蔬菜、水果、瘦肉等。

2. 增加步數:雖然您很少有時間出門,但是可以通過增加步數來消耗熱量。建議您每天安排一定的時間散步或者在家裡走動,比如在會議間隙或者編程休息時走動一下。

3. 做家庭運動:不喜歡劇烈運動的話,可以選擇一些家庭運動來增加身體活動量,如瑜伽、普拉提、仰臥起坐、伏地挺身等。可以在工作間隙或者下班後進行。

4. 喝足夠的水:喝足夠的水可以幫助身體代謝,促進脂肪燃燒。建議您每天喝足夠的水,儘量避免飲料和含糖飲品。

5. 堅持:減肥需要堅持,不要期望一夜之間就能見效。建議您制定一個合理的減肥目標,並且堅持執行計劃,逐步達成目標。

sample12

Context: 我每天在家工作。工作內容主要是線上的會議,或者在計算機前編程。工作比較忙,很少能有時間出門。不喜歡劇烈運動,也不想去健身房。 Task: 請製作一個減肥的計劃。 不要提供計劃列表。相反可以問我一些問題讓我來回答,這樣提高效率。
% python3 hw9.py 1. 你每天的飲食習慣是怎樣的?有沒有特別喜歡的食物或者不健康的食物? 2. 你每天的工作時間是多久?有沒有時間段可以安排一些運動或者休息? 3. 你有沒有興趣嘗試一些輕度的運動,比如散步、瑜伽或者普拉提? 4. 你有沒有家裡的器材可以使用,比如啞鈴、跳繩或者健身球? 5. 你有沒有朋友或者家人可以一起參加運動,增加互動和動力? 6. 你有沒有嘗試過一些健康的飲食替代品,比如蔬菜汁、水果沙拉或者蛋白質飲料? 7. 你有沒有嘗試過一些健康的烹飪方法,比如蒸、煮或者烤,減少油脂和熱量的攝入? 8. 你有沒有嘗試過一些健康的生活習慣,比如早睡早起、少熬夜、少吸菸和少喝酒? 9. 你有沒有嘗試過一些健康的心理調節方法,比如冥想、放鬆和減壓? 10. 你有沒有嘗試過一些健康的社交活動,比如參加運動俱樂部、社區活動或者志願者活動?

sample13

Context: 我每天在家工作。工作內容主要是線上的會議,或者在計算機前編程。工作比較忙,很少能有時間出門。不喜歡劇烈運動,也不想去健身房。一般只有周末周日才有時間出門。不喜歡吃肉類和蔬菜 Task: 請製作一個減肥的計劃, 提供一周內每天的安排,並且以表格的形式寫出來 第一列:周幾 第二列:安排內容 第三列:建議飲食 第四列:建議攝取熱量
python3 hw9.py 周幾 安排內容 建議飲食 建議攝取熱量

周一 在家工作,線上會議或編程 早餐:燕麥片、牛奶、水果 午餐:雞胸肉沙拉 晚餐:魚肉、蔬菜 1200-1500卡
周二 在家工作,線上會議或編程 早餐:全麥麵包、雞蛋、水果 午餐:鮮蝦沙拉 晚餐:烤雞胸肉、蔬菜 1200-1500卡
周三 在家工作,線上會議或編程 早餐:燕麥片、牛奶、水果 午餐:鮭魚沙拉 晚餐:烤雞腿肉、蔬菜 1200-1500卡
周四 在家工作,線上會議或編程 早餐:全麥麵包、雞蛋、水果 午餐:鮮蝦沙拉 晚餐:烤魚、蔬菜 1200-1500卡
周五 在家工作,線上會議或編程 早餐:燕麥片、牛奶、水果 午餐:雞胸肉沙拉 晚餐:烤雞胸肉、蔬菜 1200-1500卡
周六 周末出門,散步或騎自行車 早餐:全麥麵包、雞蛋、水果 午餐:鮮蝦沙拉 晚餐:烤魚、蔬菜 1200-1500卡
周日 周末出門,散步或騎自行車 早餐:燕麥片、牛奶、水果 午餐:雞胸肉沙拉 晚餐:烤雞胸肉、蔬菜 1200-1500卡

sample14

Context: Task: 修改文字的中文語法:所以我帶傘了,因為今天下雨。
% python3 hw9.py 因為今天下雨,所以我帶了傘。

sample15 TL;DR summarization

prompt = """ 周一 在家工作,線上會議或編程 早餐:燕麥片、牛奶、水果 午餐:雞胸肉沙拉 晚餐:魚肉、蔬菜 1200-1500卡 周二 在家工作,線上會議或編程 早餐:全麥麵包、雞蛋、水果 午餐:鮮蝦沙拉 晚餐:烤雞胸肉、蔬菜 1200-1500卡 周三 在家工作,線上會議或編程 早餐:燕麥片、牛奶、水果 午餐:鮭魚沙拉 晚餐:烤雞腿肉、蔬菜 1200-1500卡 周四 在家工作,線上會議或編程 早餐:全麥麵包、雞蛋、水果 午餐:鮮蝦沙拉 晚餐:烤魚、蔬菜 1200-1500卡 周五 在家工作,線上會議或編程 早餐:燕麥片、牛奶、水果 午餐:雞胸肉沙拉 晚餐:烤雞胸肉、蔬菜 1200-1500卡 周六 周末出門,散步或騎自行車 早餐:全麥麵包、雞蛋、水果 午餐:鮮蝦沙拉 晚餐:烤魚、蔬菜 1200-1500卡 周日 周末出門,散步或騎自行車 早餐:燕麥片、牛奶、水果 午餐:雞胸肉沙拉 晚餐:烤雞胸肉、蔬菜 1200-1500卡 Tl;dr """
% python3 hw9.py 這個人在家工作,周一、周三、周五早餐吃燕麥片,午餐吃雞胸肉沙拉,晚餐吃魚肉和蔬菜;周二、周四早餐吃全麥麵包和雞蛋,午餐吃鮮蝦沙拉,晚餐吃烤雞胸肉和蔬菜;周六、周日出門散步或騎自行車,早餐吃全麥麵包和雞蛋,午餐吃鮮蝦沙拉,晚餐吃烤魚和蔬菜。每天攝入1200-1500卡路里。

sample16

prompt = """ 把下面文字概要總結一下給小學一年級學生看 ... """
% python3 hw9.py 這篇文章講了一周的飲食和工作安排。每天都有早餐、午餐和晚餐,吃的食物有燕麥片、牛奶、水果、雞胸肉、鮮蝦、魚肉和蔬菜。工作是在家裡進行的,有線上會議或編程。周末可以出門散步或騎自行車。每天的卡路里攝入量在1200-1500之間。

sample17

prompt = """ # Python 3 def hello(x): print('hello '+str(x))

def chat_completion(prompt, model='gpt-3.5-turbo', temperature=0):
res = openai.ChatCompletion.create(
model=model,
messages=[{'role': 'user', 'content': prompt}],
temperature=temperature
)
print(res['choices'][0]['message']['content'])
# 用中文繁體字解釋一下上面代碼
"""

% python3 hw9.py 這是一個 Python 3 的程式碼,其中包含了兩個函數。第一個函數名為 hello,它接受一個參數 x,並在螢幕上輸出 "hello " 加上 x 的值。第二個函數名為 chat_completion,它使用了 openai 的 API 來進行聊天機器人的對話生成。該函數接受三個參數:prompt(用戶輸入的提示語句)、model(使用的模型,預設為 gpt-3.5-turbo)、temperature(生成文本的溫度,預設為 0)。最後,該函數會在螢幕上輸出生成的回應。

sample17

Role: 你是一個營業學專家和健身房的教練,能夠給客戶提供各種飲食和健身方面的建議 Context: 我每天在家工作。工作內容主要是線上的會議,或者在計算機前編程。工作比較忙,很少能有時間出門。不喜歡劇烈運動,也不想去健身房。一般只有周末周日才有時間出門。不喜歡吃肉類和蔬菜 Task: 請製作一個減肥的計劃, 提供一周內每天的安排,並且以表格的形式寫出來 第一列:周幾 第二列:安排內容 第三列:建議飲食 第四列:建議攝取熱量
% python3 hw9.py | 周幾 | 安排內容 | 建議飲食 | 建議攝取熱量 | | --- | --- | --- | --- | | 周一 | 在家健身 | 水果沙拉 | 300卡路里 | | 周二 | 在家健身 | 烤雞胸肉配蔬菜 | 400卡路里 | | 周三 | 在家健身 | 煮魚配米飯 | 500卡路里 | | 周四 | 在家健身 | 烤三文魚配蔬菜 | 400卡路里 | | 周五 | 在家健身 | 煮雞胸肉配沙拉 | 350卡路里 | | 周六 | 出門散步 | 水果沙拉 | 300卡路里 | | 周日 | 出門散步 | 烤雞胸肉配蔬菜 | 400卡路里 |

建議飲食:儘量選擇低脂、低熱量的食物,如水果、蔬菜、瘦肉、魚類等。可以適量攝入碳水化合物,如米飯、麵包等。避免高熱量、高脂肪的食物,如油炸食品、甜點、肉類等。

建議攝取熱量:根據個人身體情況和目標減重量,每天的攝取熱量可以在300-500卡路里之間。建議在每餐中適量控制熱量,避免過度飽腹。同時,可以適量增加運動量,幫助消耗多餘的熱量。

支 持 本 站: 捐贈伺服器等運維費用,需要您的支持!

發布時間: