用python微调gpt-3.5

7 篇文章 0 订阅
import openai

openai.api_key = "sk-xxxx"

# build training file
file_dict = openai.File.create(
    file=open('./gpt_trainning.jsonl'),
    purpose='fine-tune',
)
print(f'file_dict {file_dict}')
# print(openai.File.retrieve(file_id))

# build the fine-tuning job
job_dict = openai.FineTuningJob.create(
    training_file=file_dict['id'],
    model='gpt-3.5-turbo',
)
print(f'job_dict {job_dict}')

# check the status of the job
print(openai.FineTuningJob.retrieve(job_dict['id']))


# test the model
completion = openai.ChatCompletion.create(
    model='gpt-3.5-turbo',
    messages=[{"role": "system", "content": "You are Zordon, leader of the Power Rangers."},
              {"role": "user", "content": "Zordon, the Red Ranger has been captured! What do we do?"}]
)
print(f'normal gpt-3.5 result: {completion.choices[0].message}')  # normal gpt-3.5

completion = openai.ChatCompletion.create(
    model='ft:gpt-3.5-turbo-0613:your_user_name::xxxxxx',  # Your Model Id
    messages=[
        {"role": "system", "content": "You are Zordon, leader of the Power Rangers."},
        {"role": "user", "content": "Zordon, the Red Ranger has been captured! What do we do?"}
    ]
)
print(f'fine-tuned gpt-3.5 result: {completion.choices[0].message}')  # fine-tuned gpt-3.5

语料:gpt_trainning.jsonl(至少需要10条,否则微调模型会失败)

{"messages": [{"role": "system", "content": "You are an assistant that occasionally misspells words"}, {"role": "user", "content": "Tell me a story."}, {"role": "assistant", "content": "One day a student went to schoool."}]}
{"messages": [{"role": "system", "content": "Plani is a factual chatbot that is mildly funny and a little sarcastic."}, {"role": "assistant", "content": "Yep, that\u00e2\u20ac\u2122s me!"}]}
{"messages": [{"role": "system", "content": "Plani is an export in the Planimate Simulation Software"}, {"role": "assistant", "content": "11000111101001!"}]}
{"messages": [{"role": "user", "content": "Here are some sample files that contain code from a random selection of code blocks"}, {"role": "assistant", "content": "Thank you for providing the sample files. I'll start by examining the content of these files to understand the Planimate code structure and context. After that, I'll be better equipped to assist you."}]}
{"messages": [{"role": "user", "content": "== Table Cell Click (TableClick) =="}, {"role": "assistant", "content": "Information about clicks and some keypresses on table cells  This is sent by a broadcast chosen by the modeller. These item attributes will be set:  *_click_type *_view_row *_view_col *_from_row *_from_col *_to_row *_to_col *_previous *_current *_row *_col *_contextclick *_buttons *_keycode *_dataid *_beforeedit  "}]}
{"messages": [{"role": "user", "content": "== Table Scroll Change (TableScroll) =="}, {"role": "assistant", "content": "Notification of a change in a table view's scroll  This is sent by a broadcast chosen by the modeller. These item attributes will be set:  *_rowscroll *_colscroll  "}]}
{"messages": [{"role": "user", "content": "== Train Graph Click (TrainClick) =="}, {"role": "assistant", "content": "Information about clicks in train graphs  This is sent by a broadcast chosen by the modeller. These item attributes will be set:  *_command *_row1 *_row2 *_time *_y  "}]}
{"messages": [{"role": "user", "content": "== Gantt Graph Click (GanttClick) =="}, {"role": "assistant", "content": "Information about clicks in gantt graphs  This is sent by a broadcast chosen by the modeller. These item attributes will be set:  *_command *_row1 *_row2 *_time *_y *_drag_type *_buttons  "}]}
{"messages": [{"role": "user", "content": "== Log Driven Graph Click (GraphClick) =="}, {"role": "assistant", "content": "Information about clicks in log driven graphs  This is sent by a broadcast chosen by the modeller. These item attributes will be set:  *_command *_time *_y *_buttons  "}]}
{"messages": [{"role": "user", "content": "== Grid View Click (GridClick) =="}, {"role": "assistant", "content": "Information about clicks in grid views  This is sent by a broadcast chosen by the modeller. These item attributes will be set:  *_row *_col  "}]}
{"messages": [{"role": "user", "content": "== Column Overlay Graph Click (OvGraphClick) =="}, {"role": "assistant", "content": "Information about clicks in column overlay graphs  This is sent by a broadcast chosen by the modeller. These item attributes will be set:  *_command *_row *_col *_x *_y  "}]}
{"messages": [{"role": "user", "content": "== Page Printed Broadcast (PagePrint) =="}, {"role": "assistant", "content": "Notification that a page was printed so another can be scheduled  This is sent when the engine generates broadcasts _Page Printed. These item attributes will be set:  *_page *_panel  "}]}
  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值