Spaces:
Runtime error
Runtime error
File size: 2,088 Bytes
0974473 |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# %% 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)
# %%
|