|
import conversation as cs |
|
|
|
def test_user_person_creation(topic, language): |
|
user_persona_answer = None |
|
previous_conversation = None |
|
|
|
for i in range(2): |
|
question = cs.make_user_persona(topic, user_persona_answer, previous_conversation, language) |
|
if i == 0: |
|
previous_conversation = f"Host: {question['response']}" |
|
else: |
|
previous_conversation = f"{previous_conversation}\nHost: {question['response']}\n" |
|
|
|
print(question["response"]) |
|
user_persona_answer = input("Enter your answer: ") |
|
previous_conversation = f"{previous_conversation}\nUser: {user_persona_answer}\nHost: " |
|
|
|
|
|
if i == 1: |
|
user_persona = cs.summarize_user_persona(topic, previous_conversation, language)["response"] |
|
|
|
print("User Persona: ", user_persona) |
|
return user_persona |
|
|
|
|
|
def test_create_scenario(topic, user_persona, language): |
|
result = cs.create_scenario(topic, user_persona, language) |
|
response = result["response"] |
|
print("Scenario Response: ", response) |
|
print("Scenarios: ", result["scenarios"]) |
|
return result["scenarios"], result["entire_story"] |
|
|
|
|
|
def main(): |
|
topic = 'harry potter' |
|
|
|
language = 'korean' |
|
|
|
user_persona = "์ดํ๊ตฌ๋์ ์ฌ๋ฆฌ๋ฐ๋ฆฐ ๊ฐ๋ฌธ์ ๋ง๋ฒ์ฌ๋ก, ์ผ์ฌ์ฐจ๊ณ ๊ตํํ๋ฉฐ, ์๊ธฐํต์ ๋ ฅ์ด ๊ฐํ ์ฑ๊ฒฉ์ ๊ฐ์ง๊ณ ์์ต๋๋ค. ๋ํ, ์ ๋ต์ ์ด๊ณ ๊ณ์ฐ์ ์ธ ๋ฉด๋ชจ๋ฅผ ๊ฐ์ง๊ณ ์์ผ๋ฉฐ, ๋ชฉํ๋ฅผ ๋ฌ์ฑํ๊ธฐ ์ํด ๋
ธ๋ ฅํ๋ ๋ชจ์ต์ ๋ณด์
๋๋ค." |
|
scenarios, entire_story = test_create_scenario(topic, user_persona, language) |
|
|
|
conversation = "" |
|
choice_result = "" |
|
total_choices = "" |
|
life = 10 |
|
money = 10 |
|
for i in range(len(scenarios)): |
|
this_round_story = f"{i}. {scenarios[i]["title"]}\n{scenarios[i]["story"]}\n\n" |
|
game_result = cs.play_game(topic, user_persona, language, entire_story, this_round_story, conversation, choice_result) |
|
print(f"{i+1}th Game Response: ", game_result["response"]) |
|
selectable_choices = game_result["user_choices"] |
|
|
|
print(f"Round{i+1}: ", game_result["round_content"]) |
|
print(f"Choices:\n", '\n'.join([f"{_choice_idx+1}: {choice}" for _choice_idx, choice in enumerate(selectable_choices)])) |
|
choice_idx = int(input(f"Select your choice_idx(1~{len(selectable_choices)}): ")) |
|
choice_effect = game_result["choice_effects"][choice_idx-1] |
|
life_change = choice_effect["life"] |
|
money_change = choice_effect["money"] |
|
life += life_change |
|
money += money_change |
|
conversation += f"ํธ์คํธ: {game_result["round_content"]}\nํ๋ ์ด์ด: {game_result["user_choices"][choice_idx-1]}\n" |
|
choice_result = f"์๋ช
ํฌ์ธํธ๊ฐ {str(life_change)+" ์ฆ๊ฐํ์ต๋๋ค." if life_change >= 0 else str(life_change*(-1))+" ๊ฐ์ํ์ต๋๋ค."}, ๋: {str(money_change)+" ์ฆ๊ฐํ์ต๋๋ค." if money_change >= 0 else str(money_change*(-1))+" ๊ฐ์ํ์ต๋๋ค."}\n" |
|
|
|
print("Conversation: ", conversation) |
|
print("Changed Life: ", life) |
|
print("Changed Money: ", money) |
|
print("Choice Result: ", choice_result) |
|
|
|
if life <= 0: |
|
choice_result += f" ๊ทธ ๊ฒฐ๊ณผ ์๋ช
ํฌ์ธํธ๊ฐ {life}์ผ๋ก ๋จ์ด์ ธ ๊ฒ์์ด ์ข
๋ฃ๋์์ต๋๋ค" |
|
bad_ending_scenario = cs.generate_bad_end(language, topic, user_persona, conversation, choice_result)["response"] |
|
print("Bad Ending Scenario: ", bad_ending_scenario) |
|
return |
|
if money <= 0: |
|
choice_result += f" ๊ทธ ๊ฒฐ๊ณผ ์์งํ ๋์ด {money}์ผ๋ก ๋จ์ด์ ธ ๊ฒ์์ด ์ข
๋ฃ๋์์ต๋๋ค" |
|
bad_ending_scenario = cs.generate_bad_end(language, topic, user_persona, conversation, choice_result)["response"] |
|
print("Bad Ending Scenario: ", bad_ending_scenario) |
|
return |
|
|
|
good_ending_scenario = cs.generate_good_end(language, topic, user_persona, entire_story, conversation)["response"] |
|
print("Good Ending Scenario: ", good_ending_scenario) |
|
return |
|
|
|
if __name__ == "__main__": |
|
main() |