File size: 520 Bytes
2c2e788
 
08cbdf8
2c2e788
 
 
 
 
08cbdf8
 
2c2e788
 
08cbdf8
 
2c2e788
08cbdf8
2c2e788
 
 
 
 
08cbdf8
2c2e788
 
 
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
from functools import lru_cache

from openai import OpenAI

from .base import register_llm


@lru_cache()
def _get_openai_client(api_key):
    return OpenAI(api_key=api_key)


def ask_chatgpt(message: str, api_key: str):
    client = _get_openai_client(api_key)

    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "user", "content": message}
        ],
    )
    return response.choices[0].message.content.strip()


register_llm('chatgpt', ask_chatgpt)