Spaces:
Sleeping
Sleeping
File size: 1,032 Bytes
4790e0d |
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 |
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
|