-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
193 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ VOICEVOX/* | |
*.wav | ||
models--staka--fugumt-en-ja/ | ||
*.exe | ||
*.wav | ||
*.wav | ||
!lore.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
import traceback | ||
import openai | ||
import STTSLocal as STTS | ||
|
||
lore = '' | ||
try: | ||
with open('./lore.txt', 'r', encoding='utf-8') as file: | ||
lore = file.read() | ||
except Exception: | ||
print("error when reading lore.txt") | ||
print(traceback.format_exc()) | ||
lore = lore.replace('\n', '') | ||
|
||
message_log = [ | ||
{"role": "system", "content": lore}, | ||
{"role": "user", "content": lore}, | ||
] | ||
|
||
logging_eventhandlers = [] | ||
|
||
|
||
def send_user_input(user_input): | ||
log_message(f'user: {user_input}') | ||
global message_log | ||
api_key = os.getenv("OPENAI_API_KEY") | ||
|
||
openai.api_key = api_key | ||
print(f"Sending: {user_input} with api key :{api_key}") | ||
print(message_log) | ||
message_log.append({"role": "user", "content": user_input}) | ||
response = None | ||
try: | ||
response = openai.ChatCompletion.create( | ||
model="gpt-3.5-turbo", | ||
messages=message_log | ||
) | ||
except Exception: | ||
log_message("Error when loading api key from environment variable") | ||
log_message( | ||
"You need an API key from https://platform.openai.com/ stored in an environment variable with name \"OPENAI_API_KEY\" to use the chat feature") | ||
print(traceback.format_exc()) | ||
return | ||
text_response = response['choices'][0]['message']['content'] | ||
message_log.append({"role": "assistant", "content": text_response}) | ||
log_message(f'AI: {text_response}') | ||
STTS.start_TTS_pipeline(text_response) | ||
|
||
|
||
def log_message(message_text): | ||
print(message_text) | ||
global logging_eventhandlers | ||
for eventhandler in logging_eventhandlers: | ||
eventhandler(message_text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
You are not an assistant, your task is to roleplay as a character. | ||
Can you talk to me as if you are this character? Please only provide short answers and try not to break out of character. Here's her description: | ||
A shrine maiden of a Shinto shrine. |