ゴートうと対話 とりま完成(ついでにやばぃバグ修正)
このコミットが含まれているのは:
+1
-4
@@ -1,7 +1,4 @@
|
|||||||
from pydantic import BaseModel
|
class CWindow:
|
||||||
|
|
||||||
|
|
||||||
class CWindow (BaseModel, frozen = True):
|
|
||||||
WIDTH: int = 1024
|
WIDTH: int = 1024
|
||||||
HEIGHT: int = 768
|
HEIGHT: int = 768
|
||||||
|
|
||||||
|
|||||||
@@ -23,15 +23,16 @@ class Main:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def main (cls, argv: list, argc: int) -> None:
|
def main (cls, argv: list, argc: int) -> None:
|
||||||
mode = Mode.NIZIKA
|
mode = Mode.NIZIKA
|
||||||
match (argc > 0) and argv[0]:
|
match (argc > 1) and argv[1]:
|
||||||
case '-g':
|
case '-g':
|
||||||
mode = Mode.GOATOH
|
mode = Mode.GOATOH
|
||||||
|
|
||||||
case '-w':
|
case '-w':
|
||||||
mode = Mode.DOUBLE
|
mode = Mode.DOUBLE
|
||||||
|
|
||||||
goatoh_mode = mode == Mode.GOATOH
|
nizika_mode: bool = mode == Mode.NIZIKA
|
||||||
double_mode = mode == Mode.DOUBLE
|
goatoh_mode: bool = mode == Mode.GOATOH
|
||||||
|
double_mode: bool = mode == Mode.DOUBLE
|
||||||
|
|
||||||
print (mode)
|
print (mode)
|
||||||
|
|
||||||
@@ -103,82 +104,112 @@ class Main:
|
|||||||
|
|
||||||
message: str = chat_item.message
|
message: str = chat_item.message
|
||||||
|
|
||||||
# ChatGPT API を呼出し,返答を取得
|
if nizika_mode:
|
||||||
answer: str = Talk.main (message, chat_item.author['name'], histories, goatoh_mode).replace ('\n', ' ')
|
goatoh_talking = False
|
||||||
|
if goatoh_mode:
|
||||||
|
goatoh_talking = True
|
||||||
|
if double_mode:
|
||||||
|
goatoh_talking: bool = random.random () < .5
|
||||||
|
|
||||||
# 履歴に追加
|
while True:
|
||||||
histories = (histories
|
# ChatGPT API を呼出し,返答を取得
|
||||||
+ [{'role': 'user', 'content': message},
|
answer: str = Talk.main (message, chat_item.author['name'], histories, goatoh_talking).replace ('\n', ' ')
|
||||||
{'role': 'assistant', 'content': answer}])[(-6):]
|
|
||||||
|
|
||||||
# ログ書込み
|
# 履歴に追加
|
||||||
with open ('log.txt', 'a') as f:
|
histories = (histories
|
||||||
f.write (f'{datetime.now ()}\t{json.dumps (chat_item.__dict__)}\t{answer}\n')
|
+ [{'role': 'user', 'content': message},
|
||||||
|
{'role': 'assistant', 'content': answer}])[(-12):]
|
||||||
|
|
||||||
# 吹出し描画(ニジカは上,ゴートうは下)
|
# ログ書込み
|
||||||
screen.blit (balloon, (0, 384) if goatoh_mode else (0, 0))
|
with open ('log.txt', 'a') as f:
|
||||||
|
f.write (f'{datetime.now ()}\t{json.dumps (chat_item.__dict__)}\t{answer}\n')
|
||||||
|
|
||||||
# 視聴者コメント描画
|
# 吹出し描画(ニジカは上,ゴートうは下)
|
||||||
screen.blit (
|
if nizika_mode:
|
||||||
user_font.render (
|
screen.blit (balloon, (0, 0))
|
||||||
'> ' + (message
|
if goatoh_mode:
|
||||||
if (CommonModule.len_by_full (message)
|
screen.blit (balloon, (0, 384))
|
||||||
<= 21)
|
if double_mode:
|
||||||
else (CommonModule.mid_by_full (
|
screen.blit (pygame.transform.flip (
|
||||||
message, 0, 19.5)
|
balloon,
|
||||||
+ '...')),
|
not goatoh_talking,
|
||||||
True,
|
False),
|
||||||
(0, 0, 0)),
|
(0, 0))
|
||||||
(120, 70 + 384) if goatoh_mode else (120, 70))
|
|
||||||
|
|
||||||
# ニジカの返答描画
|
# 視聴者コメント描画
|
||||||
screen.blit (
|
screen.blit (
|
||||||
nizika_font.render (
|
user_font.render (
|
||||||
(answer
|
'> ' + (message
|
||||||
if CommonModule.len_by_full (answer) <= 16
|
if (CommonModule.len_by_full (message)
|
||||||
else CommonModule.mid_by_full (answer, 0, 16)),
|
<= 21)
|
||||||
True,
|
else (CommonModule.mid_by_full (
|
||||||
(192, 0, 0)),
|
message, 0, 19.5)
|
||||||
(100, 150 + 384) if goatoh_mode else (100, 150))
|
+ '...')),
|
||||||
if CommonModule.len_by_full (answer) > 16:
|
True,
|
||||||
|
(0, 0, 0)),
|
||||||
|
(120, 70 + 384) if goatoh_mode else (120 + (64 if (double_mode and not goatoh_talking) else 0), 70))
|
||||||
|
|
||||||
|
# ニジカの返答描画
|
||||||
screen.blit (
|
screen.blit (
|
||||||
nizika_font.render (
|
nizika_font.render (
|
||||||
(CommonModule.mid_by_full (answer, 16, 16)
|
(answer
|
||||||
if CommonModule.len_by_full (answer) <= 32
|
if CommonModule.len_by_full (answer) <= 16
|
||||||
else (CommonModule.mid_by_full (
|
else CommonModule.mid_by_full (answer, 0, 16)),
|
||||||
answer, 16, 14.5)
|
True,
|
||||||
+ '...')),
|
(192, 0, 0)),
|
||||||
True,
|
(100, 150 + 384) if goatoh_mode else (100 + (64 if (double_mode and not goatoh_talking) else 0), 150))
|
||||||
(192, 0, 0)),
|
if CommonModule.len_by_full (answer) > 16:
|
||||||
(100, 200 + 384) if goatoh_mode else (100, 200))
|
screen.blit (
|
||||||
|
nizika_font.render (
|
||||||
|
(CommonModule.mid_by_full (answer, 16, 16)
|
||||||
|
if CommonModule.len_by_full (answer) <= 32
|
||||||
|
else (CommonModule.mid_by_full (
|
||||||
|
answer, 16, 14.5)
|
||||||
|
+ '...')),
|
||||||
|
True,
|
||||||
|
(192, 0, 0)),
|
||||||
|
(100, 200 + 384) if goatoh_mode else (100 + (64 if (double_mode and not goatoh_talking) else 0), 200))
|
||||||
|
|
||||||
pygame.display.update ()
|
pygame.display.update ()
|
||||||
|
|
||||||
# 鳴く.
|
# 鳴く.
|
||||||
if goatoh_mode:
|
if goatoh_talking:
|
||||||
if random.random () < 0.1:
|
if random.random () < .1:
|
||||||
kusa.play ()
|
kusa.play ()
|
||||||
|
else:
|
||||||
|
mumumumu.play ()
|
||||||
else:
|
else:
|
||||||
mumumumu.play ()
|
noon.play ()
|
||||||
else:
|
|
||||||
noon.play ()
|
|
||||||
|
|
||||||
time.sleep (1.5)
|
time.sleep (1.5)
|
||||||
|
|
||||||
# 返答の読上げを WAV ディタとして生成,取得
|
# 返答の読上げを WAV ディタとして生成,取得
|
||||||
try:
|
try:
|
||||||
wav: bytearray | None = Aques.main (answer, goatoh_mode)
|
wav: bytearray | None = Aques.main (answer, goatoh_talking)
|
||||||
except:
|
except:
|
||||||
wav: None = None
|
wav: None = None
|
||||||
|
|
||||||
# 再生
|
# 読上げを再生
|
||||||
if wav is not None:
|
if wav is not None:
|
||||||
with open ('./nizika_talking.wav', 'wb') as f:
|
with open ('./nizika_talking.wav', 'wb') as f:
|
||||||
f.write (wav)
|
f.write (wav)
|
||||||
|
|
||||||
playsound ('./nizika_talking.wav')
|
playsound ('./nizika_talking.wav')
|
||||||
|
|
||||||
time.sleep (10)
|
time.sleep (10)
|
||||||
|
|
||||||
|
if not double_mode or random.random () < .5:
|
||||||
|
break
|
||||||
|
|
||||||
|
screen.fill ((0, 255, 0))
|
||||||
|
|
||||||
|
chat_item.author['name'] = 'ゴートうひとり' if goatoh_talking else '伊地知ニジカ'
|
||||||
|
chat_item.author['id'] = ''
|
||||||
|
chat_item.author['channelId'] = './favicon-goatoh.ico' if goatoh_talking else './favicon.ico'
|
||||||
|
|
||||||
|
goatoh_talking = not goatoh_talking
|
||||||
|
|
||||||
|
message = histories.pop (-1)['content']
|
||||||
else:
|
else:
|
||||||
# Chat オブジェクトが無効
|
# Chat オブジェクトが無効
|
||||||
|
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする