|
- import sys
- import openai
- from openai.types import *
-
- 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) -> str:
- openai.organization = OPENAI_ORGANISATION
- openai.api_key = OPENAI_API_KEY
-
- answer: chat.chat_completion_message.ChatCompletionMessage | None \
- = cls.__get_message (message)
-
- return cls.DUMMY_RESPONSE if answer is None else answer.content
-
- @classmethod
- def __get_message (cls, message: str) \
- -> chat.chat_completion_message.ChatCompletionMessage | None:
- try:
- return openai.chat.completions.create (
- model = 'gpt-3.5-turbo',
- messages = [{'role': 'system',
- 'content': 'あなたの名前は伊地知ニジカ。誕生日は毎日。友達はゴートうひとりとラマ田リョウ。好きな人は喜多ちゃん。すべての語尾に「ぬ゛ん」か「だぬ゛ん」をつけて質問に短く答えろ。定期的に「ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛」、「ボッチチャーン」、「あっ」のいずれかを発しろ'},
- {'role': 'user',
- 'content': message}]).choices[0].message
- except openai.AuthenticationError:
- return None
-
-
- if __name__ == '__main__':
- print (Talk.main (sys.argv[1] if len (sys.argv) > 1 else ''))
|