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卡路里之间。建议在每餐中适量控制热量,避免过度饱腹。同时,可以适量增加运动量,帮助消耗多余的热量。

支 持 本 站: 捐赠服务器等运维费用,需要您的支持!

发布时间: