-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathfine_tuning_utilities.py
37 lines (29 loc) · 1 KB
/
fine_tuning_utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def load_jsonl_file(file_path):
import json
with open(file_path, 'r') as file:
data = [json.loads(line) for line in file]
return data
def save_jsonl_file(dictionary_data, final_file_name):
import json
with open(final_file_name, 'w') as outfile:
for entry in dictionary_data:
json.dump(entry, outfile)
outfile.write('\n')
def prompt_chatGPT(message:str, model="gpt-3.5-turbo"):
"""A prompt helper function that sends a message to openAI
and returns only the text response.
"""
import openai
# convert message in the right format if necessary
if isinstance(message, str):
message = [{"role": "user", "content": message}]
# setup connection to the LLM
client = openai.OpenAI()
# submit prompt
response = client.chat.completions.create(
model=model,
messages=message
)
# extract answer
return response.choices[0].message.content
prompt = prompt_chatGPT