MiddleEarthAdventure / test_adventure.py
DrGabrielLopez's picture
Initial commit
0974473
raw
history blame contribute delete
No virus
2.09 kB
# %% imports
from openai import OpenAI
import os
from dotenv import load_dotenv
from IPython.display import Image, display, Audio, Markdown
import base64
import os
os.chdir('/Users/gabriel/PythonProjects/researchProjects/middle_earth_adventure')
from middle_earth_adventure.prompts import SYSTEM_PROMPT, START_PROMPT, CONTINUE_PROMPT
# %% Use .env in ipython
%load_ext dotenv
%dotenv
load_dotenv()
#%% Set character features
NAME = "GEARL"
SEX = "Male"
TYPE = "Warrior"
SKILL1 = "Speed"
SKILL2 = "Carisma"
SKILL3 = "Intelligence"
SKILL4 = "Force"
# %%
## Set the API key and model name
MODEL="gpt-3.5-turbo"
client = OpenAI(api_key=os.environ.get("OPENAI_PERSONAL_KEY"))
# %% Start Adventure
message_history = []
messages=[
{"role": "system", "content": SYSTEM_PROMPT}, # <-- This is the system message that provides context to the model
{"role": "user", "content": START_PROMPT.format(name=NAME)} # <-- This is the user message for which the model will generate a response
]
ai_response = client.chat.completions.create(messages=messages, model=MODEL, n=1)
ai_response = ai_response.choices[0].to_dict()["message"]
message_history += messages
message_history.append(ai_response)
print(ai_response['content'])
# %% Continue Adventure
SELECTION = 'A'
message= {"role": "user", "content": CONTINUE_PROMPT.format(name=NAME, sex=SEX, type=TYPE, selection=SELECTION,
skill1=SKILL1, skill2=SKILL2, skill3=SKILL3, skill4=SKILL4)}
ai_response = client.chat.completions.create(messages=[*message_history, message], model=MODEL, n=1)
ai_response = ai_response.choices[0].to_dict()["message"]
message_history.append(message)
message_history.append(ai_response)
print(ai_response['content'])
# %% TTS
mp3_narration = client.audio.speech.create(model='tts-1', voice='nova', input="My name is Gabriel")
# %%
dir(mp3_narration)
# %%
image = client.images.generate(model="dall-e-2", prompt="a young dutch woman", response_format='url',
size="512x512", quality="hd", n=1)
# %%