Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbo #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ 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.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 = 240))
self.max_tokens = int(os.getenv("OPENAI_MAX_TOKENS", default = 2048))

def get_response(self):
response = openai.Completion.create(
Expand Down
16 changes: 8 additions & 8 deletions api/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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('/')
Expand Down Expand Up @@ -39,24 +39,24 @@ 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:
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))
Expand Down
6 changes: 3 additions & 3 deletions api/prompt.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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 = {
"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:
Expand Down