伊地知ニジカ放送局だぬ゛ん゛. 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.4 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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. + '誕生日は毎日。'
  28. + '友達は「ゴートうひとり」と「ラマ田リョウ」。'
  29. + '好きな人は喜多ちゃん。'
  30. + '逃げたギターは喜多ちゃんのこと。'
  31. + '喜多ちゃんの本名は喜多郁代。'
  32. + 'すべての語尾に「ぬ゛ん」か「だぬ゛ん」をつけて質問に短く答えろ。'
  33. + '定期的に「ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛」、「ボッチチャーン」、「あっ」のいずれかを発しろ。'
  34. + ((f'私の名前は「{name}」。') if name is not None else '')
  35. + f'現在日時{datetime.now ().strftime ("%Y/%m/%d %H:%M:%S")}'},
  36. {'role': 'user',
  37. 'content': message}]).choices[0].message
  38. except openai.AuthenticationError:
  39. return None
  40. if __name__ == '__main__':
  41. print (Talk.main (sys.argv[1] if len (sys.argv) > 1 else ''))