File size: 735 Bytes
3e22b88
e22d4b7
 
 
 
3e22b88
 
e22d4b7
 
 
 
 
 
 
 
 
 
 
 
 
3e22b88
e22d4b7
 
 
 
 
 
 
 
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 os

openai.api_key = os.environ["OPENAI_API_KEY"]

client = OpenAI()

class BaseLLM:
    def __init__(self, model):
        self.model = model
    
    def get_response(self, system_prompt, query):
        raise NotImplementedError
    

class OpenAILLM(BaseLLM):
    def __init__(self, model):
        self.model = model
    
    def get_response(self, system_prompt, query, **kwargs):
        response = client.chat.completions.create(
            model=self.model,
            messages=[
                {"role": "system", "content": system_prompt},
                {"role": "user", "content": query},
            ],
            **kwargs,
        )
        return response.choices[0].message.content