-
Notifications
You must be signed in to change notification settings - Fork 0
/
openai json
30 lines (23 loc) · 854 Bytes
/
openai json
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
from openai import OpenAI
# System prompt for the AI model
system_prompt = """hi gpt
"""
# User prompt for the AI model
user_prompt = """analyse the image
"""
#gptkey= ""
def gpt(system_prompt, user_prompt, expected_format, gptkey):
client = OpenAI(api_key=gptkey)
chat_completion, *_ = client.chat.completions.create(
messages=[
{"role": "system", "content": f"system_prompt : {system_prompt}"},
{"role": "user", "content": f"user_prompt : {user_prompt}"},
{"role": "user", "content": f"expected_JSON_format : {expected_format}"}
],
model="gpt-4-1106-preview",
response_format={"type": "json_object"},
).choices
content = chat_completion.message.content
print(content)
return content
#gpt(system_prompt,user_prompt,expected_format="JSON",gptkey=gptkey)