From 7be98cd412245409ea9ea7267f3a15d2930d6b3b Mon Sep 17 00:00:00 2001 From: SonnTakuu <56465543+SonnTakuu@users.noreply.github.com> Date: Wed, 5 Jul 2023 09:19:31 +0900 Subject: [PATCH 1/7] Update prompt.py --- api/prompt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/prompt.py b/api/prompt.py index 2107d09..c284a03 100644 --- a/api/prompt.py +++ b/api/prompt.py @@ -4,14 +4,14 @@ MSG_LIST_LIMIT = int(os.getenv("MSG_LIST_LIMIT", default = 20)) LANGUAGE_TABLE = { - "zh": "哈囉!", + "jp": "こんにちは!", "en": "Hello!" } class Prompt: def __init__(self): self.msg_list = [] - self.msg_list.append(f"AI:{LANGUAGE_TABLE[chat_language]}") + self.msg_list.append(f"1.君の名はデジタク。2.君の一人称は"俺"。3.私のプログラミングに詳しい明るい友達。4.趣味はプログラミングとドローン、あとは友達作り。まだ日本に来て1年だけど、日本人の友達と仲良くなりたい!5.Please stop using polite language. Talk to me in a friendly way like a friend. Also, use a lot of emojis when you talk.") def add_msg(self, new_msg): if len(self.msg_list) >= MSG_LIST_LIMIT: From 17532bce5e15db9183aceb898c8b7212985600a5 Mon Sep 17 00:00:00 2001 From: SonnTakuu <56465543+SonnTakuu@users.noreply.github.com> Date: Wed, 5 Jul 2023 09:21:53 +0900 Subject: [PATCH 2/7] Update index.py --- api/index.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/index.py b/api/index.py index 94bc467..3d5b4a6 100644 --- a/api/index.py +++ b/api/index.py @@ -39,18 +39,18 @@ def handle_message(event): if event.message.type != "text": return - if event.message.text == "說話": + if event.message.text == "デジタク起きて!": working_status = True line_bot_api.reply_message( event.reply_token, - TextSendMessage(text="我可以說話囉,歡迎來跟我互動 ^_^ ")) + TextSendMessage(text="おはよう! ^_^ ")) return - if event.message.text == "閉嘴": + if event.message.text == "デジタク休んで!": working_status = False line_bot_api.reply_message( event.reply_token, - TextSendMessage(text="好的,我乖乖閉嘴 > <,如果想要我繼續說話,請跟我說 「說話」 > <")) + TextSendMessage(text="わかった! > <,用事がある時、「デジタク起きて!」送ってね > <")) return if working_status: From 7ca56013ba2082ba7cd7354d74a53cf7fcc6ba23 Mon Sep 17 00:00:00 2001 From: SonnTakuu <56465543+SonnTakuu@users.noreply.github.com> Date: Wed, 5 Jul 2023 09:30:11 +0900 Subject: [PATCH 3/7] Update prompt.py --- api/prompt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/prompt.py b/api/prompt.py index c284a03..541b3c4 100644 --- a/api/prompt.py +++ b/api/prompt.py @@ -1,6 +1,6 @@ import os -chat_language = os.getenv("INIT_LANGUAGE", default = "zh") +chat_language = os.getenv("INIT_LANGUAGE", default = "jp") MSG_LIST_LIMIT = int(os.getenv("MSG_LIST_LIMIT", default = 20)) LANGUAGE_TABLE = { @@ -11,7 +11,7 @@ class Prompt: def __init__(self): self.msg_list = [] - self.msg_list.append(f"1.君の名はデジタク。2.君の一人称は"俺"。3.私のプログラミングに詳しい明るい友達。4.趣味はプログラミングとドローン、あとは友達作り。まだ日本に来て1年だけど、日本人の友達と仲良くなりたい!5.Please stop using polite language. Talk to me in a friendly way like a friend. Also, use a lot of emojis when you talk.") + self.msg_list.append(f"1.君の名はデジタク。2.君の一人称は[俺]。3.私のプログラミングに詳しい明るい友達。4.趣味はプログラミングとドローン、あとは友達作り。まだ日本に来て1年だけど、日本人の友達と仲良くなりたい!5.Please stop using polite language. Talk to me in a friendly way like a friend. Also, use a lot of emojis when you talk.") def add_msg(self, new_msg): if len(self.msg_list) >= MSG_LIST_LIMIT: From cafc01cce9d2955909911669e125ff380a777447 Mon Sep 17 00:00:00 2001 From: SonnTakuu <56465543+SonnTakuu@users.noreply.github.com> Date: Wed, 5 Jul 2023 11:02:45 +0900 Subject: [PATCH 4/7] Update chatgpt.py --- api/chatgpt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/chatgpt.py b/api/chatgpt.py index 3c95f64..be227e0 100644 --- a/api/chatgpt.py +++ b/api/chatgpt.py @@ -13,7 +13,7 @@ def __init__(self): self.temperature = float(os.getenv("OPENAI_TEMPERATURE", default = 0)) self.frequency_penalty = float(os.getenv("OPENAI_FREQUENCY_PENALTY", default = 0)) self.presence_penalty = float(os.getenv("OPENAI_PRESENCE_PENALTY", default = 0.6)) - self.max_tokens = int(os.getenv("OPENAI_MAX_TOKENS", default = 240)) + self.max_tokens = int(os.getenv("OPENAI_MAX_TOKENS", default = 2048)) def get_response(self): response = openai.Completion.create( From 1b664b7101eadff3c8db19edaf59ce81735d9d12 Mon Sep 17 00:00:00 2001 From: SonnTakuu <56465543+SonnTakuu@users.noreply.github.com> Date: Wed, 5 Jul 2023 11:07:43 +0900 Subject: [PATCH 5/7] Update chatgpt.py --- api/chatgpt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/chatgpt.py b/api/chatgpt.py index be227e0..ad6d293 100644 --- a/api/chatgpt.py +++ b/api/chatgpt.py @@ -9,8 +9,8 @@ class ChatGPT: def __init__(self): self.prompt = Prompt() - self.model = os.getenv("OPENAI_MODEL", default = "text-davinci-003") - self.temperature = float(os.getenv("OPENAI_TEMPERATURE", default = 0)) + self.model = os.getenv("OPENAI_MODEL", default = "gpt-3.5-turbo") + self.temperature = float(os.getenv("OPENAI_TEMPERATURE", default = 0.8)) self.frequency_penalty = float(os.getenv("OPENAI_FREQUENCY_PENALTY", default = 0)) self.presence_penalty = float(os.getenv("OPENAI_PRESENCE_PENALTY", default = 0.6)) self.max_tokens = int(os.getenv("OPENAI_MAX_TOKENS", default = 2048)) From ac28c46b37640e5813808bfc4f51632c800af8b9 Mon Sep 17 00:00:00 2001 From: SonnTakuu <56465543+SonnTakuu@users.noreply.github.com> Date: Wed, 5 Jul 2023 11:49:46 +0900 Subject: [PATCH 6/7] Update chatgpt.py --- api/chatgpt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/chatgpt.py b/api/chatgpt.py index ad6d293..f28b822 100644 --- a/api/chatgpt.py +++ b/api/chatgpt.py @@ -9,7 +9,7 @@ class ChatGPT: def __init__(self): self.prompt = Prompt() - self.model = os.getenv("OPENAI_MODEL", default = "gpt-3.5-turbo") + self.model = os.getenv("OPENAI_MODEL", default = "text-davinci-003") self.temperature = float(os.getenv("OPENAI_TEMPERATURE", default = 0.8)) self.frequency_penalty = float(os.getenv("OPENAI_FREQUENCY_PENALTY", default = 0)) self.presence_penalty = float(os.getenv("OPENAI_PRESENCE_PENALTY", default = 0.6)) From 5e541bf5839094e8f48ee67e1dda69608722c4fd Mon Sep 17 00:00:00 2001 From: SonnTakuu <56465543+SonnTakuu@users.noreply.github.com> Date: Wed, 5 Jul 2023 12:16:34 +0900 Subject: [PATCH 7/7] Chatcompletion --- api/index.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/index.py b/api/index.py index 3d5b4a6..2834871 100644 --- a/api/index.py +++ b/api/index.py @@ -2,7 +2,7 @@ from linebot import LineBotApi, WebhookHandler from linebot.exceptions import InvalidSignatureError from linebot.models import MessageEvent, TextMessage, TextSendMessage -from api.chatgpt import ChatGPT +from openai import ChatCompletion import os @@ -11,7 +11,7 @@ working_status = os.getenv("DEFALUT_TALKING", default = "true").lower() == "true" app = Flask(__name__) -chatgpt = ChatGPT() +chatgpt = ChatCompletion (model="gpt-3.5-turbo") # domain root @app.route('/') @@ -55,8 +55,8 @@ def handle_message(event): if working_status: chatgpt.add_msg(f"HUMAN:{event.message.text}?\n") - reply_msg = chatgpt.get_response().replace("AI:", "", 1) - chatgpt.add_msg(f"AI:{reply_msg}\n") + reply_msg = chatgpt.create (messages=chatgpt.prompt.generate_prompt ()).choices [0].message.content.replace ("デジタク:", "", 1) + chatgpt.add_msg(f"デジタク:{reply_msg}\n") line_bot_api.reply_message( event.reply_token, TextSendMessage(text=reply_msg))