用python微调gpt-3.5

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  "}]}

你可能感兴趣的:(#,NLP,AI,python,gpt-3,ai,nlp)