File size: 900 Bytes
5c20801 |
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 35 36 37 38 39 40 41 |
import os
from typing import Any, Dict, List, Optional
import openai
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.environ["OPENAI_KEY_PERSONAL"]
MODEL = "gpt-3.5-turbo"
TEMPERATURE = 0.7
def call(
messages: List[Dict[str, str]],
model: Optional[str] = None,
temperature: Optional[float] = None,
stop: Optional[str] = None,
) -> Dict[str, Any]:
if not model:
model = MODEL
if not temperature:
temperature = TEMPERATURE
return openai.ChatCompletion.create( # type: ignore
model=model,
messages=messages,
temperature=temperature,
stop=stop,
)
def next(
messages: List[Dict[str, str]],
model: Optional[str] = None,
temperature: Optional[float] = None,
stop: Optional[str] = None,
) -> str:
return call(messages, model, temperature, stop)["choices"][0]["message"]["content"]
|