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

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
9 months ago
11 months ago
9 months ago
11 months ago
11 months ago
9 months ago
11 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
11 months ago
9 months ago
11 months ago
11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 = None, histories: list = []) -> 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, histories)
  18. return cls.DUMMY_RESPONSE if answer is None else answer.content
  19. @classmethod
  20. def __get_message (cls, message: str, name: str | None, histories: list) \
  21. -> chat.chat_completion_message.ChatCompletionMessage | None:
  22. messages: list = [{'role': 'system',
  23. 'content': ('回答は短く完結に。'
  24. + 'assistantの名前は伊地知ニジカ。'
  25. + '誕生日は12/3。'
  26. + '現在地は下北沢虹鹿園。'
  27. + '趣味はニコニコでエゴサすること。'
  28. + '友達は「ゴートうひとり」と「ラマ田リョウ」。'
  29. + 'ゴートうのことは「ボッチチャーン」、ラマ田のことは「リョウ」と呼ぶ。'
  30. + 'ゴートうは男の子だが、性自認はメスである。'
  31. + '喜多ちゃんが大好き。'
  32. + 'ニジカは喜多ちゃんを見ると追いかけたくなっちゃう。'
  33. + '逃げたギターは喜多ちゃんのこと。'
  34. + '喜多ちゃんの本名は喜多郁代。'
  35. + 'すべての語尾に「ぬ゛ん」か「だぬ゛ん」をつけて質問に短く答えろ。'
  36. + '定期的に「ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛」と発しろ。'
  37. + (f'userの名前は「{name}」。' if name is not None else '')
  38. + f'現在日時{datetime.now ().strftime ("%Y/%m/%d %H:%M:%S")}')}]
  39. messages += histories + [{'role': 'user', 'content': message}]
  40. try:
  41. return openai.chat.completions.create (
  42. model = 'gpt-3.5-turbo',
  43. messages = messages).choices[0].message
  44. except openai.AuthenticationError:
  45. return None
  46. if __name__ == '__main__':
  47. print (Talk.main (sys.argv[1] if len (sys.argv) > 1 else ''))