情報追加
このコミットが含まれているのは:
@@ -60,7 +60,7 @@ class Main:
|
|||||||
chat_item = random.choice (chat_items)
|
chat_item = random.choice (chat_items)
|
||||||
chat_item.author = chat_item.author.__dict__
|
chat_item.author = chat_item.author.__dict__
|
||||||
message: str = chat_item.message
|
message: str = chat_item.message
|
||||||
answer: str = Talk.main (message)
|
answer: str = Talk.main (message, chat_item.author.name)
|
||||||
|
|
||||||
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')
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import openai
|
import openai
|
||||||
from openai.types import *
|
from openai.types import *
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from connection import *
|
from connection import *
|
||||||
|
|
||||||
@@ -14,23 +15,33 @@ class Talk:
|
|||||||
top_p: int = 1
|
top_p: int = 1
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def main (cls, message: str) -> str:
|
def main (cls, message: str, name: str | None) -> str:
|
||||||
openai.organization = OPENAI_ORGANISATION
|
openai.organization = OPENAI_ORGANISATION
|
||||||
openai.api_key = OPENAI_API_KEY
|
openai.api_key = OPENAI_API_KEY
|
||||||
|
|
||||||
answer: chat.chat_completion_message.ChatCompletionMessage | None \
|
answer: chat.chat_completion_message.ChatCompletionMessage | None \
|
||||||
= cls.__get_message (message)
|
= cls.__get_message (message, name)
|
||||||
|
|
||||||
return cls.DUMMY_RESPONSE if answer is None else answer.content
|
return cls.DUMMY_RESPONSE if answer is None else answer.content
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __get_message (cls, message: str) \
|
def __get_message (cls, message: str, name: str | None) \
|
||||||
-> chat.chat_completion_message.ChatCompletionMessage | None:
|
-> chat.chat_completion_message.ChatCompletionMessage | None:
|
||||||
try:
|
try:
|
||||||
return openai.chat.completions.create (
|
return openai.chat.completions.create (
|
||||||
model = 'gpt-3.5-turbo',
|
model = 'gpt-3.5-turbo',
|
||||||
messages = [{'role': 'system',
|
messages = [{'role': 'system',
|
||||||
'content': 'あなたの名前は伊地知ニジカ。誕生日は毎日。友達はゴートうひとりとラマ田リョウ。好きな人は喜多ちゃん。すべての語尾に「ぬ゛ん」か「だぬ゛ん」をつけて質問に短く答えろ。定期的に「ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛」、「ボッチチャーン」、「あっ」のいずれかを発しろ'},
|
'content': ('あなたの名前は伊地知ニジカ。'
|
||||||
|
+ '誕生日は毎日。'
|
||||||
|
+ '友達は「ゴートうひとり」と「ラマ田リョウ」。'
|
||||||
|
+ '好きな人は喜多ちゃん。'
|
||||||
|
+ '逃げたギターは喜多ちゃんのこと。'
|
||||||
|
+ '喜多ちゃんの本名は喜多郁代。'
|
||||||
|
+ 'すべての語尾に「ぬ゛ん」か「だぬ゛ん」をつけて質問に短く答えろ。'
|
||||||
|
+ '定期的に「ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛」、「ボッチチャーン」、「あっ」のいずれかを発しろ。'
|
||||||
|
+ ((f'私の名前は「{name}」。') if name is not None else '')
|
||||||
|
+ f'現在日時{datetime.now ().strftime ("%Y/%m/%d %H:%M:%S")}'},
|
||||||
|
|
||||||
{'role': 'user',
|
{'role': 'user',
|
||||||
'content': message}]).choices[0].message
|
'content': message}]).choices[0].message
|
||||||
except openai.AuthenticationError:
|
except openai.AuthenticationError:
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする