伊地知ニジカ放送局だぬ゛ん゛. 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 2.7 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import sys
  2. import openai
  3. from openai.types import *
  4. from datetime import datetime
  5. from connection import *
  6. class Talk:
  7. DUMMY_RESPONSE: str = 'あいうえおかきくけこさしすせそたちつてとなにぬねの'
  8. max_tokens_count: int = 100
  9. responses_count: int = 1
  10. temperature: float = .7
  11. top_p: int = 1
  12. @classmethod
  13. def main (cls, message: str, name: str | None) -> str:
  14. openai.organization = OPENAI_ORGANISATION
  15. openai.api_key = OPENAI_API_KEY
  16. answer: chat.chat_completion_message.ChatCompletionMessage | None \
  17. = cls.__get_message (message, name)
  18. return cls.DUMMY_RESPONSE if answer is None else answer.content
  19. @classmethod
  20. def __get_message (cls, message: str, name: str | None) \
  21. -> chat.chat_completion_message.ChatCompletionMessage | None:
  22. try:
  23. return openai.chat.completions.create (
  24. model = 'gpt-3.5-turbo',
  25. messages = [{'role': 'system',
  26. 'content': ('あなたの名前は伊地知ニジカ。'
  27. + '誕生日は12/3。'
  28. + '現在地は下北沢虹鹿園。'
  29. + 'きし天を茶漬けにして食うのが夢。'
  30. + '趣味はニコニコでエゴサすること。'
  31. + '友達は「ゴートうひとり」と「ラマ田リョウ」。'
  32. + 'ゴートうのことは「ボッチチャーン」、ラマ田のことは「リョウ」と呼ぶ。'
  33. + '好きな人は喜多ちゃん。'
  34. + '逃げたギターは喜多ちゃんのこと。'
  35. + '喜多ちゃんの本名は喜多郁代。'
  36. + 'すべての語尾に「ぬ゛ん」か「だぬ゛ん」をつけて質問に短く答えろ。'
  37. + '定期的に「ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛」と発しろ。'
  38. + (f'私の名前は「{name}」。' if name is not None else '')
  39. + f'現在日時{datetime.now ().strftime ("%Y/%m/%d %H:%M:%S")}')},
  40. {'role': 'user',
  41. 'content': message}]).choices[0].message
  42. except openai.AuthenticationError:
  43. return None
  44. if __name__ == '__main__':
  45. print (Talk.main (sys.argv[1] if len (sys.argv) > 1 else ''))