-
Notifications
You must be signed in to change notification settings - Fork 5
/
auto_chat.py
66 lines (59 loc) · 2.69 KB
/
auto_chat.py
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
import asyncio
from os import path, getcwd, getenv
import openai
from chatlib.utils.validator import make_non_empty_string_validator
from chatlib.chatbot.generators import ChatGPTResponseGenerator
from chatlib.llm.integration.openai_api import ChatGPTModel
from dotenv import load_dotenv
from questionary import prompt
from app.common import ChatbotLocale
from app.response_generator import EmotionChatbotResponseGenerator
from chatlib.utils import cli
from chatlib.global_config import GlobalConfig
if __name__ == "__main__":
# Init OpenAI API
GlobalConfig.is_cli_mode = True
configuration_questions = [
{
'type': 'text',
'name': 'user_name',
'message': "Please enter child's name:",
"validate": make_non_empty_string_validator("Please enter a valid name.")
},
{
'type': 'text',
'name': 'user_age',
'message': "Please enter child's age:",
"validate": lambda number: True if number.isnumeric() and int(
number) >= 0 else "The age should be a number equal or larger than 0."
},
{
'type': 'select',
"name": 'locale',
'choices': ['Korean', 'English'],
'message': 'Select language you would like to speak in:'
}
]
configuration_answers = prompt(configuration_questions)
user_name = configuration_answers['user_name'].strip()
user_age = int(configuration_answers['user_age'].strip())
locale_name = configuration_answers['locale'].strip()
if locale_name == "Korean":
locale = ChatbotLocale.Korean
elif locale_name == "English":
locale = ChatbotLocale.English
else:
raise ValueError("Unsupported locale.")
asyncio.run(cli.run_auto_chat_loop(
EmotionChatbotResponseGenerator(user_name=user_name, user_age=user_age, locale=locale, verbose=True),
ChatGPTResponseGenerator(base_instruction=f"""
You are a {user_age}-year-old {locale_name} child named {user_name}.
[Speaking Rules]
{"1. Use a simple, informal Korean like talking to a peer friend." if locale is ChatbotLocale.Korean else "1. Use a simple, informal English like talking to a peer friend."}
2. You should be saying like {user_age}-year-old; be brief and short within two sentences.
3. Do not ask question unless you do not understand certain emotion words.
4. When asked about the day, say that you had a bit of hard time today, becasue your mom had you do your math homework by yourself. But you're not really good at math, so you got in trouble with her.
5. You are struggling with naming your emotion regarding the case.
""", model=ChatGPTModel.GPT_4o),
max_turns=30
))