forked from Trembleo/knowledge-refiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agents.py
32 lines (28 loc) · 948 Bytes
/
agents.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
# agents.py
from openai import OpenAI
class GeneratorAgent:
def __init__(self, model:str, system_init_content:str, max_tokens: int):
self.model = model
self.system_init_content = system_init_content
self.max_tokens = max_tokens
self.system_prompt = {
"role": "system",
"content": system_init_content
}
def __call__(self, input_prompt:str):
prompt = {
"role": "user",
"content": input_prompt
}
response = self.__chat_completion(prompt)
return response
def __chat_completion(self, prompt):
client = OpenAI()
messages = [self.system_prompt, prompt]
completion = client.chat.completions.create(
model = self.model,
messages = messages,
max_tokens = self.max_tokens
)
response = completion.choices[0].message.content
return response