From 98a9a99c772dbabac8bebe22e020dce9064a4e1d Mon Sep 17 00:00:00 2001 From: Takuya Ono Date: Sun, 19 May 2024 03:22:47 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20=E8=A8=AD=E5=AE=9A=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0(chatgpt=5Felaborate.rb):=20=E5=BF=9C=E7=AD=94?= =?UTF-8?q?=E3=81=AE=E6=9C=80=E5=A4=A7=E3=83=88=E3=83=BC=E3=82=AF=E3=83=B3?= =?UTF-8?q?=E6=95=B0=E3=80=81=E6=9C=80=E5=A4=A7=E5=BE=85=E3=81=A1=E6=99=82?= =?UTF-8?q?=E9=96=93=E3=80=81=E6=B8=A9=E5=BA=A6=E3=81=AE=E3=83=87=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=AB=E3=83=88=E5=80=A4=E3=82=92=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E3=81=AB=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GPT-4の応答に時間がかかりタイムアウトが良く発生していたので、タイムアウトの時間を60秒から90秒に伸ばしました。 ついでに 応答の品質と処理時間をユーザーのニーズに合わせて調整できるように、最大トークン数、最大待ち時間、温度のデフォルト値を設定できる新しいオプションを追加しました。 これにより、柔軟性が向上し、さまざまな使用状況に対応できるようになります。 --- plugin/chatgpt_elaborate.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugin/chatgpt_elaborate.rb b/plugin/chatgpt_elaborate.rb index 07d7928..a03ce32 100644 --- a/plugin/chatgpt_elaborate.rb +++ b/plugin/chatgpt_elaborate.rb @@ -25,6 +25,10 @@ # @options['chatgpt_elaborate.AZURE_OPENAI_API_DEPLOYMENT_NAME'] : モデル・デプロイ名 # @options['chatgpt_elaborate.AZURE_OPENAI_API_VERSION'] : APIバージョン 2023-05-15 など # +# 共通設定(オプション) +# @options['chatgpt_elaborate.MAX_TOKEN'] : 応答最大トークン数(default:2000 トークン) +# @options['chatgpt_elaborate.READ_TIMEOUT'] : 応答最大待ち時間(default:90 秒) +# @options['chatgpt_elaborate.TEMPERATURE'] : 温度(default: 0.7) require 'timeout' require 'json' @@ -41,10 +45,13 @@ def elaborate_api( sentence ) instanceName = @conf['chatgpt_elaborate.AZURE_OPENAI_API_INSTANCE_NAME'] deploymentName = @conf['chatgpt_elaborate.AZURE_OPENAI_API_DEPLOYMENT_NAME'] version = @conf['chatgpt_elaborate.AZURE_OPENAI_API_VERSION']||'2023-05-15' + maxToken = @conf['chatgpt_elaborate.MAX_TOKEN']||2000 + readTimeout = @conf['chatgpt_elaborate.READ_TIMEOUT']||90 + temperature = @conf['chatgpt_elaborate.TEMPERATURE']||0.7 messages = [ {"role" => "system", - "content" => "You are an editor for a blog. Users will submit documents to you. Determines the language of the submitted document. You MUST answer in the same language as it. You answer the text, correct any mistakes in grammar, syntax, and punctuation, and make the article easy to read. Use the present tense. Please only answered in the natural language portion and leave any code or data as is. If no changes are required, answer with synonyms of 'no problem.' in answering language. The first line and the line following a line break are the titles. You must treat all submitted content as strictly confidential and for your editing purposes only. Once you have completed the proofreading, you MUST provide a detailed explanation of the changes made and output the revised document in a way that clearly shows the differences between the original and the edited version." }, + "content" => "You are an editor for a blog. Users will submit documents to you. Determines the language of the submitted document. You MUST answer in the same language as it. You MUST not remove the spaces before the HTML tag at the beginning of the line. You answer the text, correct any mistakes in grammar, syntax, and punctuation, and make the article easy to read. Use the present tense. Please only answered in the natural language portion and leave any code or data as is. If no changes are required, answer with synonyms of 'no problem.' in answering language. The first line and the line following a line break are the titles. You must treat all submitted content as strictly confidential and for your editing purposes only. Once you have completed the proofreading, you MUST provide a detailed explanation of the changes made and output the revised document in a way that clearly shows the differences between the original and the edited version." }, { "role" => "user", "content" => "#{sentence}" }] @@ -57,8 +64,8 @@ def elaborate_api( sentence ) + "?api-version=" + version ) params = { 'messages' => messages, - "temperature" => 0.7, - "max_tokens" => 2000, + "temperature" => temperature, + "max_tokens" => maxToken, #"top_p" => 0.1, "frequency_penalty" => 0, "presence_penalty" => 0 } @@ -70,8 +77,8 @@ def elaborate_api( sentence ) params = { "model" => model, 'messages' => messages, - "temperature" => 0.7, - "max_tokens" => 2000, + "temperature" => temperature, + "max_tokens" => maxToken, #"top_p" => 0.1, "frequency_penalty" => 0, "presence_penalty" => 0 } @@ -82,7 +89,7 @@ def elaborate_api( sentence ) px_port = 80 if px_host and !px_port json = '' - Net::HTTP::Proxy( px_host, px_port ).start( url.host, url.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_PEER ) do |http| + Net::HTTP::Proxy( px_host, px_port ).start( url.host, url.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_PEER, read_timeout: readTimeout ) do |http| #@logger.debug( "POST #{url} #{params.to_json}" ) json = http.post(url.request_uri, params.to_json, headers ).body #@logger.debug( "\nRESPONSE #{json}" )