forked from hassancs91/AI-Marketing-Army-Tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openai_functions.py
47 lines (33 loc) · 1009 Bytes
/
openai_functions.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
42
43
# from openai import OpenAI
import openai
import instructor
client = openai.Client(api_key="sk-JXLXW5xPfdTC0QyuTHyutTYsDA8D7YgYx2AHwWgyRfd9sB",base_url="https://api.chatanywhere.com.cn/v1/")
import instructor
instructor.patch(client)
def analyze_image_basic(image_url, prompt):
response = client.chat.completions.create(
model="gpt-4-vision-preview",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": prompt},
{
"type": "image_url",
"image_url": {
"url": image_url,
},
},
],
}
],
max_tokens=300,
)
return response.choices[0].message.content
def generate_with_response_model(user_prompt,response_model):
resut: response_model = client.chat.completions.create(
model="gpt-3.5-turbo-1106",
response_model=response_model,
messages=[{"role": "user", "content": user_prompt}]
)
return resut