Browse Source

会話機構追加

btc-sounds
みてるぞ 1 year ago
parent
commit
f3870b0b63
1 changed files with 14 additions and 14 deletions
  1. +14
    -14
      talk.py

+ 14
- 14
talk.py View File

@@ -1,7 +1,8 @@
from connection import *

import sys import sys
import openai import openai
from openai.types import *

from connection import *




class Talk: class Talk:
@@ -11,24 +12,23 @@ class Talk:
top_p: int = 1 top_p: int = 1


@classmethod @classmethod
def main (cls, message: str) -> None:
def main (cls, message: str) -> str:
openai.organization = OPENAI_ORGANISATION openai.organization = OPENAI_ORGANISATION
openai.api_key = OPENAI_API_KEY openai.api_key = OPENAI_API_KEY


print (cls.__get_answers (message)[0])
return cls.__get_message (message).content


@classmethod @classmethod
def __get_answers (cls, message: str) -> list[str]:
return openai.Completion.create (
engine = 'text-davinci-002',
prompt = message,
max_tokens = cls.max_tokens_count,
n = cls.temperature,
stop = None,
temperature = cls.temperature,
top_p = cls.top_p).choices
def __get_message (cls, message: str) \
-> chat.chat_completion_message.ChatCompletionMessage:
return openai.chat.completions.create (
model = 'gpt-3.5-turbo',
messages = [{'role': 'system',
'content': 'すべての語尾に「ぬ゛ん」か「だぬ゛ん」をつけて質問に短く答えてください。定期的に「ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛」、「ボッチチャーン」、「あっ」のいずれかを発してください'},
{'role': 'user',
'content': message}]).choices[0].message




if __name__ == '__main__': if __name__ == '__main__':
Talk.main (sys.argv[1] if len (sys.argv) > 1 else '')
print (Talk.main (sys.argv[1] if len (sys.argv) > 1 else ''))



Loading…
Cancel
Save