-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathopenaitools.py
34 lines (29 loc) · 897 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
from openai import AsyncOpenAI
from typing import List, Dict
class OpenAiTools:
def __init__(self, token: str):
self.client = AsyncOpenAI(
api_key=token,
)
async def get_chatgpt(self, messages: List[Dict[str, str]]):
try:
response = await self.client.chat.completions.create(
messages=messages,
model="gpt-4o",
max_tokens=16384,
temperature=1,
)
return response.choices[0].message.content
except:
return
async def get_dalle(self, prompt: str):
try:
response = await self.client.images.generate(
model="dall-e-3",
prompt=prompt,
size="1024x1024",
n=1,
)
return response.data[0].url
except:
return