ruby-on-rails Ruby on rails:#〈TCPSocket:(closed)>的Net::ReadTimeout

v09wglhw  于 2023-04-22  发布在  Ruby
关注(0)|答案(1)|浏览(141)

我正在使用ruby-openAI gem与openAI交互,但我得到超时错误,有没有办法可以超过超时限制?

response = @client.completions(
      parameters: {
      model: "text-davinci-003",  
      prompt: "In the style of #{@as_written_by}, write a longer article in HTML of at least 750 words using the #{article} as the primary source and basis for the new article, and include interesting facts from the #{secondary_sources}, with a tags around the source of the information pointing to the original URLs",
      max_tokens: 3000
  })
qzlgjiam

qzlgjiam1#

当你示例化你的客户端时,你可以传递给它一个“request_timeout”属性,并指定所需的持续时间(秒)。

@client = OpenAI::Client.new(
    access_token: "access_token_goes_here",
    request_timeout: 240 #Optional and can be increased/decreased as required. 
)

您也可以在配置级别执行此操作:

OpenAI.configure do |config|
    config.access_token = ENV.fetch("OPENAI_ACCESS_TOKEN")
    config.organization_id = ENV.fetch("OPENAI_ORGANIZATION_ID") # Optional
    config.request_timeout = 240 # Optional
end

更多信息请看这里的文档:https://github.com/alexrudall/ruby-openai#custom-timeout-or-base-uri

相关问题