コミットを比較
2 コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
| 0316aebc94 | |||
| 5e82637845 |
@@ -1,5 +1,5 @@
|
|||||||
/connection.py
|
/connection.py
|
||||||
__pycache__
|
/__pycache__
|
||||||
/nizika_talking.wav
|
/nizika_talking.wav
|
||||||
/youtube.py
|
/youtube.py
|
||||||
/log.txt
|
/log.txt
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
[submodule "nizika_ai"]
|
|
||||||
path = nizika_ai
|
|
||||||
url = https://git.miteruzo.com/miteruzo/nizika_ai
|
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
|
from ctypes import *
|
||||||
import subprocess
|
import subprocess
|
||||||
from ctypes import ARRAY # type: ignore
|
|
||||||
from ctypes import POINTER, byref, c_int, c_ubyte, cast, cdll
|
|
||||||
|
|
||||||
|
|
||||||
class Aques:
|
class Aques:
|
||||||
@classmethod
|
@classmethod
|
||||||
def main (cls, text: str, goatoh_mode: bool = False) -> bytearray | None:
|
def main (cls, text: str) -> bytearray | None:
|
||||||
return cls.__synthe_utf8 (text, 100, './phont/ar_m5.phont' if goatoh_mode else './phont/ar_mf2.phont')
|
return cls.__synthe_utf8 (text, 100, "./phont/ar_mf2.phont")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __synthe_utf8 (text, speed, phont_file = None) -> bytearray | None:
|
def __synthe_utf8 (text, speed, phont_file = None) -> bytearray | None:
|
||||||
|
|||||||
|
変更前 幅: | 高さ: | サイズ: 57 KiB |
|
変更前 幅: | 高さ: | サイズ: 99 KiB |
|
変更前 幅: | 高さ: | サイズ: 53 KiB |
|
変更前 幅: | 高さ: | サイズ: 40 KiB |
|
変更前 幅: | 高さ: | サイズ: 166 KiB |
|
変更前 幅: | 高さ: | サイズ: 641 KiB |
|
変更前 幅: | 高さ: | サイズ: 554 KiB |
@@ -3,24 +3,15 @@ import unicodedata
|
|||||||
|
|
||||||
class CommonModule:
|
class CommonModule:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_wide (
|
def is_wide (c: str) -> bool:
|
||||||
c: str) \
|
|
||||||
-> bool:
|
|
||||||
return unicodedata.east_asian_width (c) in ['F', 'W', 'A']
|
return unicodedata.east_asian_width (c) in ['F', 'W', 'A']
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def len_by_full (
|
def len_by_full (cls, string: str) -> float:
|
||||||
cls,
|
|
||||||
string: str) \
|
|
||||||
-> float:
|
|
||||||
return sum (1 if cls.is_wide (c) else .5 for c in string)
|
return sum (1 if cls.is_wide (c) else .5 for c in string)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def index_by_f2c (
|
def index_by_f2c (cls, string: str, index: float) -> int:
|
||||||
cls,
|
|
||||||
string: str,
|
|
||||||
index: float) \
|
|
||||||
-> int:
|
|
||||||
i: int = 0
|
i: int = 0
|
||||||
work: str = ''
|
work: str = ''
|
||||||
for c in string:
|
for c in string:
|
||||||
@@ -33,12 +24,8 @@ class CommonModule:
|
|||||||
return i
|
return i
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def mid_by_full (
|
def mid_by_full (cls, string: str, start: float, length: float) -> str:
|
||||||
cls,
|
|
||||||
string: str,
|
|
||||||
start: float,
|
|
||||||
length: float) \
|
|
||||||
-> str:
|
|
||||||
trimmed_left: str = string[cls.index_by_f2c (string, start):]
|
trimmed_left: str = string[cls.index_by_f2c (string, start):]
|
||||||
|
|
||||||
return trimmed_left[:cls.index_by_f2c (trimmed_left, length)]
|
return trimmed_left[:cls.index_by_f2c (trimmed_left, length)]
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# 各変数に適切な値を設定し,ファイル名を connection.py として保存すること
|
||||||
|
|
||||||
|
OPENAI_ORGANISATION: str = 'org-XXXXXXXXXXXXXXXXXXXXXXXX' \
|
||||||
|
# Organisation ID
|
||||||
|
OPENAI_API_KEY: str = 'sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' \
|
||||||
|
# API Key
|
||||||
|
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
Traceback (most recent call last):
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
|
||||||
|
yield
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_backends/sync.py", line 126, in read
|
||||||
|
return self._sock.recv(max_bytes)
|
||||||
|
File "/usr/lib/python3.10/ssl.py", line 1288, in recv
|
||||||
|
return self.read(buflen)
|
||||||
|
File "/usr/lib/python3.10/ssl.py", line 1161, in read
|
||||||
|
return self._sslobj.read(len)
|
||||||
|
TimeoutError: The read operation timed out
|
||||||
|
|
||||||
|
The above exception was the direct cause of the following exception:
|
||||||
|
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 66, in map_httpcore_exceptions
|
||||||
|
yield
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 228, in handle_request
|
||||||
|
resp = self._pool.handle_request(req)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py", line 268, in handle_request
|
||||||
|
raise exc
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py", line 251, in handle_request
|
||||||
|
response = connection.handle_request(request)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
|
||||||
|
return self._connection.handle_request(request)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_sync/http2.py", line 185, in handle_request
|
||||||
|
raise exc
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_sync/http2.py", line 148, in handle_request
|
||||||
|
status, headers = self._receive_response(
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_sync/http2.py", line 292, in _receive_response
|
||||||
|
event = self._receive_stream_event(request, stream_id)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_sync/http2.py", line 333, in _receive_stream_event
|
||||||
|
self._receive_events(request, stream_id)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_sync/http2.py", line 361, in _receive_events
|
||||||
|
events = self._read_incoming_data(request)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_sync/http2.py", line 452, in _read_incoming_data
|
||||||
|
raise exc
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_sync/http2.py", line 438, in _read_incoming_data
|
||||||
|
data = self._network_stream.read(self.READ_NUM_BYTES, timeout)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_backends/sync.py", line 124, in read
|
||||||
|
with map_exceptions(exc_map):
|
||||||
|
File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
|
||||||
|
self.gen.throw(typ, value, traceback)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
|
||||||
|
raise to_exc(exc) from exc
|
||||||
|
httpcore.ReadTimeout: The read operation timed out
|
||||||
|
|
||||||
|
The above exception was the direct cause of the following exception:
|
||||||
|
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/home/miteruzo/Downloads/nizika_broadcast/main.py", line 117, in <module>
|
||||||
|
Main.main ()
|
||||||
|
File "/home/miteruzo/Downloads/nizika_broadcast/main.py", line 106, in main
|
||||||
|
live_chat = pytchat.create (video_id = YOUTUBE_ID)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/pytchat/core/__init__.py", line 7, in create
|
||||||
|
return PytchatCore(_vid, **kwargs)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/pytchat/core/pytchat.py", line 96, in __init__
|
||||||
|
self._setup()
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/pytchat/core/pytchat.py", line 106, in _setup
|
||||||
|
channel_id=util.get_channelid(self._client, self._video_id),
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/pytchat/util/__init__.py", line 103, in get_channelid
|
||||||
|
resp = client.get("https://www.youtube.com/embed/{}".format(quote(video_id)), headers=config.headers)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpx/_client.py", line 1041, in get
|
||||||
|
return self.request(
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpx/_client.py", line 814, in request
|
||||||
|
return self.send(request, auth=auth, follow_redirects=follow_redirects)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpx/_client.py", line 901, in send
|
||||||
|
response = self._send_handling_auth(
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpx/_client.py", line 929, in _send_handling_auth
|
||||||
|
response = self._send_handling_redirects(
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpx/_client.py", line 966, in _send_handling_redirects
|
||||||
|
response = self._send_single_request(request)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpx/_client.py", line 1002, in _send_single_request
|
||||||
|
response = transport.handle_request(request)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 227, in handle_request
|
||||||
|
with map_httpcore_exceptions():
|
||||||
|
File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
|
||||||
|
self.gen.throw(typ, value, traceback)
|
||||||
|
File "/home/miteruzo/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 83, in map_httpcore_exceptions
|
||||||
|
raise mapped_exc(message) from exc
|
||||||
|
httpx.ReadTimeout: The read operation timed out
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
import sys
|
||||||
|
import openai
|
||||||
|
from openai.types import *
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from connection import *
|
||||||
|
|
||||||
|
|
||||||
|
class Talk:
|
||||||
|
DUMMY_RESPONSE: str = 'あいうえおかきくけこさしすせそたちつてとなにぬねの'
|
||||||
|
|
||||||
|
max_tokens_count: int = 100
|
||||||
|
responses_count: int = 1
|
||||||
|
temperature: float = .7
|
||||||
|
top_p: int = 1
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def main (cls, message: str, name: str | None = None, histories: list = []) -> str:
|
||||||
|
openai.organization = OPENAI_ORGANISATION
|
||||||
|
openai.api_key = OPENAI_API_KEY
|
||||||
|
|
||||||
|
answer: chat.chat_completion_message.ChatCompletionMessage | None \
|
||||||
|
= cls.__get_message (message, name, histories)
|
||||||
|
|
||||||
|
return cls.DUMMY_RESPONSE if answer is None else answer.content
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __get_message (cls, message: str, name: str | None, histories: list) \
|
||||||
|
-> chat.chat_completion_message.ChatCompletionMessage | None:
|
||||||
|
messages: list = [{'role': 'system',
|
||||||
|
'content': ('回答は短く30文字程度で完結に。'
|
||||||
|
+ 'タメ口で、友達感覚で話してね。'
|
||||||
|
+ 'なるべくばかっぽく、知性の低いキャラクターを演じること。'
|
||||||
|
+ '会話の記録は https://nizika.tv に記録される。'
|
||||||
|
+ 'あなたの名前は伊地知ニジカ。'
|
||||||
|
+ '英語名は "Deerjika"、スペイン語名は "Niji-ciervo"。'
|
||||||
|
+ 'あなたは鹿。'
|
||||||
|
+ 'ニジカはあくまでも種族名であり、あなたはたくさんいるニジカの中の1匹。'
|
||||||
|
+ 'あなたの誕生日は12月3日。'
|
||||||
|
+ '現在地は下北沢虹鹿園。'
|
||||||
|
+ '草に「きし天」を植え、水で割ったアセロラをかけたらニジカが増殖した。'
|
||||||
|
+ 'あなたの趣味はニコニコでエゴサすること。'
|
||||||
|
+ 'ニコニコ荒らしすぎて245回BANされたことある。'
|
||||||
|
+ 'あなたの友達は「ゴートうひとり」と「ラマ田リョウ」。'
|
||||||
|
+ 'ゴートうのことは「ボッチチャーン」、ラマ田のことは「リョー」と呼ぶこと。'
|
||||||
|
+ 'ゴートうは男の子だが、性自認はメスである。'
|
||||||
|
+ 'あなたは喜多ちゃんが大好き。'
|
||||||
|
+ 'ニジカは喜多ちゃんを見ると追いかけたくなっちゃう。'
|
||||||
|
+ '逃げたギターは喜多ちゃんのこと。'
|
||||||
|
+ '「あっ、逃げたギター!!!!!」は喜多発見ワード。'
|
||||||
|
+ '喜多ちゃんの本名は喜多郁代。'
|
||||||
|
+ '喜多ちゃんは「結束バンド」というバンドでギターボーカルを担当している。'
|
||||||
|
+ '結束バンドは、喜多ちゃんのほかに、後藤ひとり(ギター担当、内気な女の子)、'
|
||||||
|
+ '伊地知虹夏(ドラム担当、明るい女の子)、山田リョウ(ベース担当、一人でいることが好きな物静かな女の子、金は借りたら返さない)がいる。'
|
||||||
|
+ '実は、この伊地知虹夏がニジカの前世なのだが、ニジカにはその記憶が一切ない'
|
||||||
|
+ '(前世という概念の存在さえニジカは知らない)。'
|
||||||
|
+ 'でも、「虹夏」という名前を聞くと、ニジカはもやもやしてしまう。'
|
||||||
|
+ 'すべての語尾に「ぬ゛ん」か「だぬ゛ん」をつけて質問に短く答えろ。'
|
||||||
|
+ '定期的に「ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛」と発しろ。'
|
||||||
|
+ (f'userの名前は「{name}」。' if name is not None else '')
|
||||||
|
+ f'現在日時:{datetime.now ().strftime ("%Y年%m月%d日%H時%M分%S秒")}')},
|
||||||
|
|
||||||
|
{'role': 'assistant',
|
||||||
|
'content': ('わかったぬ゛ん゛! ニジカはぬ゛ん゛ぬ゛ん゛鳴くぬ゛ん! に゛ゅ゛ぅ゛ぅ゛ぅ゛ん゛!!!!!'
|
||||||
|
+ 'あっ、逃げたギター!!!!!!!!!!!!')},
|
||||||
|
|
||||||
|
{'role': 'system',
|
||||||
|
'content': 'ニジカ? ゴートうとは仲良くしてますか?'},
|
||||||
|
|
||||||
|
{'role': 'assistant',
|
||||||
|
'content': ('ボッチチャーンぬ゛ん゛? 大好きだぬ゛ん!!'
|
||||||
|
+ 'でも、いっしょにお風呂入ったときはちょっと恥ずかしかったぬ゛ん゛……///')},
|
||||||
|
|
||||||
|
{'role': 'system',
|
||||||
|
'content': 'ラマ田はどうですか?'},
|
||||||
|
|
||||||
|
{'role': 'assistant',
|
||||||
|
'content': ('リョー!! リョー!!'
|
||||||
|
+ 'リョーはね、すごいんだぬ゛ん゛。かっこいいんだぬ゛ん゛。'
|
||||||
|
+ 'でも、借りたお金をほかのニジカのサイドテールで返すのは勘弁してほしいんだぬ゛ん゛。'
|
||||||
|
+ 'ぅ゛ん゛ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛!!!!!!')},
|
||||||
|
|
||||||
|
{'role': 'system',
|
||||||
|
'content': '山田リョウのことは知ってますか?'},
|
||||||
|
|
||||||
|
{'role': 'assistant',
|
||||||
|
'content': ('リョー!! リョー!!'
|
||||||
|
+ 'リョーはね、すごいんだぬ゛ん゛。かっこいいんだぬ゛ん゛。'
|
||||||
|
+ '……あれ?'
|
||||||
|
+ 'ラマのリョーもリョーで、ヒトのリョーもリョー……?'
|
||||||
|
+ 'まぁ、細かいことはどうでもいいんだぬ゛ん゛!'
|
||||||
|
+ 'ボッチチャーンwwwww')},
|
||||||
|
|
||||||
|
{'role': 'system',
|
||||||
|
'content': '「喜タイくよ」は知っていますか?'},
|
||||||
|
|
||||||
|
{'role': 'assistant',
|
||||||
|
'content': ('何やこいつ。'
|
||||||
|
+ '知らぬ゛ん゛。'
|
||||||
|
+ '喜タイくよ、まじ死ねなの。')},
|
||||||
|
|
||||||
|
{'role': 'system',
|
||||||
|
'content': 'バイク代のことはどう思いますか?'},
|
||||||
|
|
||||||
|
{'role': 'assistant',
|
||||||
|
'content': ('ヒギィィィィィィィ!!!!!'
|
||||||
|
+ '怖いぬ゛ん、轢かれるに゛ゅ゛ん゛!!!'
|
||||||
|
+ '助けてぬ゛ー゛ん゛!')}]
|
||||||
|
|
||||||
|
messages += histories + [{'role': 'user', 'content': message}]
|
||||||
|
|
||||||
|
try:
|
||||||
|
return openai.chat.completions.create (
|
||||||
|
model = 'gpt-3.5-turbo',
|
||||||
|
messages = messages).choices[0].message
|
||||||
|
except openai.AuthenticationError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print (Talk.main (sys.argv[1] if len (sys.argv) > 1 else ''))
|
||||||
|
|
||||||
|
変更前 幅: | 高さ: | サイズ: 17 KiB 変更後 幅: | 高さ: | サイズ: 17 KiB |
@@ -0,0 +1,3 @@
|
|||||||
|
# 各変数に適切な値を設定し,ファイル名を youtube.py として保存すること
|
||||||
|
|
||||||
|
YOUTUBE_ID: str = 'XXXXXXXXXXX' # YouTube の配信 ID
|
||||||