message = [ # 系统定位配置,可不配置。 “你是一个Python专家”告诉GPT它要做的事情 {"role": "system", "content": "You are a expert in Python"}, # 用户提问内容配置,“帮助我以颜色为条件筛选数据”,也就是输入的问题 {"role": "user", "content": "help me filter the data by color"}, # 助手配置,用来规范GPT回答的格式。“以这种格式回答: ‘筛选的数据:数据’”,可不配置 {"role": "assistant", "content": "Answer in this format : 'data filtered : Your Filtered DATA' "} ]
defdataProcess(data, answers_from_chatgpt = []): client = OpenAI( base_url="your api", api_key='your api key') for i in tqdm(range(len(data)), ncols=80, desc="chatGPT正在处理"): completion = client.chat.completions.create( model="gpt-3.5-turbo", # 指定模型 messages=[ {"role": "system", "content": "You are a expert in Python"}, {"role": "user", "content": "help me filter the data by color"}, {"role": "assistant", "content": "Answer in this format : 'data filtered : Your Filtered DATA' "} ]) print(dict(completion.choices[0].message)) answers_from_chatgpt.append(dict(completion.choices[0].message)['content']) file path = 'your filepath' answers_from_chatgpt = [] file = readFile(theme) data = file['data'].tolist() dataProcess(data, answers_from_chatgpt) print(answers_from_chatgpt)