ゴートうと対話 とりま完成(ついでにやばぃバグ修正)
このコミットが含まれているのは:
+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,20 +104,37 @@ class Main:
|
|||||||
|
|
||||||
message: str = chat_item.message
|
message: str = chat_item.message
|
||||||
|
|
||||||
|
if nizika_mode:
|
||||||
|
goatoh_talking = False
|
||||||
|
if goatoh_mode:
|
||||||
|
goatoh_talking = True
|
||||||
|
if double_mode:
|
||||||
|
goatoh_talking: bool = random.random () < .5
|
||||||
|
|
||||||
|
while True:
|
||||||
# ChatGPT API を呼出し,返答を取得
|
# ChatGPT API を呼出し,返答を取得
|
||||||
answer: str = Talk.main (message, chat_item.author['name'], histories, goatoh_mode).replace ('\n', ' ')
|
answer: str = Talk.main (message, chat_item.author['name'], histories, goatoh_talking).replace ('\n', ' ')
|
||||||
|
|
||||||
# 履歴に追加
|
# 履歴に追加
|
||||||
histories = (histories
|
histories = (histories
|
||||||
+ [{'role': 'user', 'content': message},
|
+ [{'role': 'user', 'content': message},
|
||||||
{'role': 'assistant', 'content': answer}])[(-6):]
|
{'role': 'assistant', 'content': answer}])[(-12):]
|
||||||
|
|
||||||
# ログ書込み
|
# ログ書込み
|
||||||
with open ('log.txt', 'a') as f:
|
with open ('log.txt', 'a') as f:
|
||||||
f.write (f'{datetime.now ()}\t{json.dumps (chat_item.__dict__)}\t{answer}\n')
|
f.write (f'{datetime.now ()}\t{json.dumps (chat_item.__dict__)}\t{answer}\n')
|
||||||
|
|
||||||
# 吹出し描画(ニジカは上,ゴートうは下)
|
# 吹出し描画(ニジカは上,ゴートうは下)
|
||||||
screen.blit (balloon, (0, 384) if goatoh_mode else (0, 0))
|
if nizika_mode:
|
||||||
|
screen.blit (balloon, (0, 0))
|
||||||
|
if goatoh_mode:
|
||||||
|
screen.blit (balloon, (0, 384))
|
||||||
|
if double_mode:
|
||||||
|
screen.blit (pygame.transform.flip (
|
||||||
|
balloon,
|
||||||
|
not goatoh_talking,
|
||||||
|
False),
|
||||||
|
(0, 0))
|
||||||
|
|
||||||
# 視聴者コメント描画
|
# 視聴者コメント描画
|
||||||
screen.blit (
|
screen.blit (
|
||||||
@@ -129,7 +147,7 @@ class Main:
|
|||||||
+ '...')),
|
+ '...')),
|
||||||
True,
|
True,
|
||||||
(0, 0, 0)),
|
(0, 0, 0)),
|
||||||
(120, 70 + 384) if goatoh_mode else (120, 70))
|
(120, 70 + 384) if goatoh_mode else (120 + (64 if (double_mode and not goatoh_talking) else 0), 70))
|
||||||
|
|
||||||
# ニジカの返答描画
|
# ニジカの返答描画
|
||||||
screen.blit (
|
screen.blit (
|
||||||
@@ -139,7 +157,7 @@ class Main:
|
|||||||
else CommonModule.mid_by_full (answer, 0, 16)),
|
else CommonModule.mid_by_full (answer, 0, 16)),
|
||||||
True,
|
True,
|
||||||
(192, 0, 0)),
|
(192, 0, 0)),
|
||||||
(100, 150 + 384) if goatoh_mode else (100, 150))
|
(100, 150 + 384) if goatoh_mode else (100 + (64 if (double_mode and not goatoh_talking) else 0), 150))
|
||||||
if CommonModule.len_by_full (answer) > 16:
|
if CommonModule.len_by_full (answer) > 16:
|
||||||
screen.blit (
|
screen.blit (
|
||||||
nizika_font.render (
|
nizika_font.render (
|
||||||
@@ -150,13 +168,13 @@ class Main:
|
|||||||
+ '...')),
|
+ '...')),
|
||||||
True,
|
True,
|
||||||
(192, 0, 0)),
|
(192, 0, 0)),
|
||||||
(100, 200 + 384) if goatoh_mode else (100, 200))
|
(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:
|
else:
|
||||||
mumumumu.play ()
|
mumumumu.play ()
|
||||||
@@ -167,11 +185,11 @@ class Main:
|
|||||||
|
|
||||||
# 返答の読上げを 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)
|
||||||
@@ -179,6 +197,19 @@ class Main:
|
|||||||
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 オブジェクトが無効
|
||||||
|
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする