Skip to content

Commit

Permalink
🔧 設定追加(chatgpt_elaborate.rb): 応答の最大トークン数、最大待ち時間、温度のデフォルト値を設定可能にしました
Browse files Browse the repository at this point in the history
GPT-4の応答に時間がかかりタイムアウトが良く発生していたので、タイムアウトの時間を60秒から90秒に伸ばしました。
ついでに 応答の品質と処理時間をユーザーのニーズに合わせて調整できるように、最大トークン数、最大待ち時間、温度のデフォルト値を設定できる新しいオプションを追加しました。
これにより、柔軟性が向上し、さまざまな使用状況に対応できるようになります。
  • Loading branch information
takuya-o committed May 18, 2024
1 parent 68f1e60 commit 98a9a99
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions plugin/chatgpt_elaborate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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}" }]

Expand All @@ -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 }
Expand All @@ -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 }
Expand All @@ -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}" )
Expand Down

0 comments on commit 98a9a99

Please sign in to comment.