-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenaitools.py
43 lines (36 loc) · 1020 Bytes
/
openaitools.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 os import getenv
from dotenv import load_dotenv
from openai import AsyncOpenAI
load_dotenv()
client = AsyncOpenAI(
api_key=getenv("OPENAI_API_KEY"),
)
class OpenAiTools:
async def get_chatgpt(question: str):
prompt = question
try:
response = await client.chat.completions.create(
messages=[
{
"role": "user",
"content": prompt,
}
],
model="gpt-3.5-turbo",
max_tokens=3000,
temperature=1,
)
return response.choices[0].message.content
except:
return
async def get_dalle(prompt: str):
try:
response = await client.images.generate(
model="dall-e-2",
prompt=prompt,
size="1024x1024",
n=1,
)
return response.data[0].url
except:
return