伊地知ニジカ放送局だぬ゛ん゛. https://www.youtube.com/@deerjika
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

talk.py 1.6 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import sys
  2. import openai
  3. from openai.types import *
  4. from connection import *
  5. class Talk:
  6. DUMMY_RESPONSE: str = 'あいうえおかきくけこさしすせそたちつてとなにぬねの'
  7. max_tokens_count: int = 100
  8. responses_count: int = 1
  9. temperature: float = .7
  10. top_p: int = 1
  11. @classmethod
  12. def main (cls, message: str) -> str:
  13. openai.organization = OPENAI_ORGANISATION
  14. openai.api_key = OPENAI_API_KEY
  15. answer: chat.chat_completion_message.ChatCompletionMessage | None \
  16. = cls.__get_message (message)
  17. return cls.DUMMY_RESPONSE if answer is None else answer.content
  18. @classmethod
  19. def __get_message (cls, message: str) \
  20. -> chat.chat_completion_message.ChatCompletionMessage | None:
  21. try:
  22. return openai.chat.completions.create (
  23. model = 'gpt-3.5-turbo',
  24. messages = [{'role': 'system',
  25. 'content': 'あなたの名前は伊地知ニジカ。誕生日は毎日。友達はゴートうひとりとラマ田リョウ。好きな人は喜多ちゃん。すべての語尾に「ぬ゛ん」か「だぬ゛ん」をつけて質問に短く答えろ。定期的に「ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛」、「ボッチチャーン」、「あっ」のいずれかを発しろ'},
  26. {'role': 'user',
  27. 'content': message}]).choices[0].message
  28. except openai.AuthenticationError:
  29. return None
  30. if __name__ == '__main__':
  31. print (Talk.main (sys.argv[1] if len (sys.argv) > 1 else ''))