Spaces:
Sleeping
Sleeping
from openai import OpenAI | |
import os | |
from dotenv import load_dotenv | |
# Load environment variables from .env file | |
load_dotenv() | |
# Access API keys | |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | |
MODEL_NAME = "gpt-3.5-turbo" | |
TEMPERATURE = 0 | |
MAX_OUTPUT_TOKENS = 100 | |
class PizzaGPT: | |
def __init__(self): | |
self.__client = OpenAI() | |
with open("custom_instruction.txt") as fileHandle: | |
self.__custom_instructions = fileHandle.read() | |
self.__message = [{"role" : "system", "content" : "Act as a information extractor"}, | |
{"role" : "system", "content" : self.__custom_instructions}] | |
def chat(self, messages): | |
message_context = [] | |
message_context.extend(self.__message) | |
message_context.extend(messages) | |
completion = self.__client.chat.completions.create( | |
model=MODEL_NAME, | |
messages= message_context, | |
temperature=TEMPERATURE, | |
max_tokens=MAX_OUTPUT_TOKENS) | |
return completion.choices[0].message.content | |