Skip to content

Commit

Permalink
Fix core
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavelka, Roman (ADV D EU CZ PDS1 CIO 1) committed Nov 8, 2023
1 parent bac9c20 commit 54376aa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
MODEL = "gpt-4"
TEMPERATURE = 0.0

api_key_path = os.path.join(os.path.dirname(__file__), '.api_key')
with open(api_key_path, 'r') as f:
openai.api_key = f.read().strip()
if 'OPENAI_API_KEY' not in os.environ:
api_key_path = os.path.join(os.path.dirname(__file__), '.api_key')
with open(api_key_path, 'r') as f:
os.environ['OPENAI_API_KEY'] = f.read().strip()


class GptCore:
Expand All @@ -34,18 +35,20 @@ def __init__(self, input, output):

self.messages = []

self.client = openai.OpenAI()

def main(self):
price = 0
while prompt := self.input():
self.messages.append({"role": "user", "content": prompt})

response = openai.ChatCompletion.create(
response = self.client.chat.completions.create(
model=MODEL, messages=self.messages, temperature=TEMPERATURE)

message = response.choices[0]["message"]
message = response.choices[0].message
self.messages.append(message)

content = message["content"].strip()
content = message.content.strip()

usage = response.usage
prompt_tokens, completion_tokens = (
Expand Down

0 comments on commit 54376aa

Please sign in to comment.