forked from peng-gao-lab/ctinexus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLLMCaller.py
More file actions
29 lines (21 loc) · 779 Bytes
/
LLMCaller.py
File metadata and controls
29 lines (21 loc) · 779 Bytes
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
from openai import OpenAI
import time
from omegaconf import DictConfig
class LLMCaller:
def __init__(self, config: DictConfig, prompt) -> None:
self.config = config
self.prompt = prompt
def call(self):
client = OpenAI(api_key=self.config.api_key)
startTime = time.time()
response = client.chat.completions.create(
model = self.config.model,
response_format = { "type": "json_object" },
messages = self.prompt,
max_tokens= 4096,
)
endTime = time.time()
#pause for 5 seconds to avoid exceeding the rate limit
time.sleep(5)
generation_time = endTime - startTime
return response, generation_time