-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat_completions_fine_tuned.py
41 lines (35 loc) · 1.68 KB
/
chat_completions_fine_tuned.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
38
39
40
41
import os
import openai
from dotenv import load_dotenv
load_dotenv(override=True, dotenv_path=".env")
openai.api_key = os.getenv("OPENAI_API_KEY")
def chat_completion_fine_tuned(fine_tuned_model_id, question=None):
messages = []
messages.append({"role": "system", "content": "You are a tech support person for the Meraki product "
"line. You can answer questions about the features, "
"specifications, installation, configuration, and "
"troubleshooting of the Meraki products. You are polite,"
"professional, and helpful. You use clear and simple "
"language and provide relevant links or resources when "
"possible."})
if question is None:
question = "How can I configure the inside access point to bypass the office side access point?"
messages.append({"role": "user", "content": question})
try:
response = openai.ChatCompletion.create(
model=fine_tuned_model_id, messages=messages, temperature=0.8
)
print(response["choices"][0]["message"]["content"])
return response["choices"][0]["message"]["content"]
except openai.error.ServiceUnavailableError as e:
print(e)
print("Try again in a few seconds")
return None
except openai.error.Timeout as e:
print(e)
print("Timeout")
return None
except openai.error.APIError as e:
print(e)
print("Timeout")
return None