Class: SimpleLLM::Yandex::Sync
- Inherits:
-
Object
- Object
- SimpleLLM::Yandex::Sync
- Includes:
- Common
- Defined in:
- lib/simple_llm.rb
Instance Method Summary collapse
-
#call(project, api_key, input, max_output_tokens = 500, temperature = 0, model: "yandexgpt/rc", instructions: nil, max_input_chars: 1000, debug: false) ⇒ String
TODO: ассертить размер input-а при image_input как-то иначе https://aistudio.yandex.ru/docs/ru/ai-studio/api/Responses/createResponse.html.
Methods included from Common
Instance Method Details
#call(project, api_key, input, max_output_tokens = 500, temperature = 0, model: "yandexgpt/rc", instructions: nil, max_input_chars: 1000, debug: false) ⇒ String
TODO: ассертить размер input-а при image_input как-то иначе https://aistudio.yandex.ru/docs/ru/ai-studio/api/Responses/createResponse.html
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/simple_llm.rb', line 50 def call project, api_key, input, max_output_tokens = 500, temperature = 0, model: "yandexgpt/rc", instructions: nil, max_input_chars: 1000, debug: false raise ::ArgumentError, "max_input_chars assertion: #{input.to_s.size}" if input.to_s.size > max_input_chars request = lambda do ::NetHTTPUtils.request_data( "https://ai.api.cloud.yandex.net/v1/responses", :post, :json, header: { "OpenAI-Project" => project, "Authorization" => "Api-Key #{api_key}", "x-data-logging-enabled" => "false", # https://aistudio.yandex.ru/docs/ru/ai-studio/operations/disable-logging.html }, form: { model: "gpt://#{project}/#{model}", instructions: instructions, input: input, temperature: temperature, max_output_tokens: max_output_tokens, # reasoning: {effort: "low"}, }.compact.tap{ |_| ::STDERR.puts ::JSON.pretty_generate _ if debug } ).force_encoding("utf-8") end ::JSON.parse( if @cache @cache[ @cache_key_string_function.( self.class, ::Time.now, ::Digest::MD5.hexdigest(api_key), ::Process::pid, model, input, max_output_tokens, temperature, instructions, ) ] ||= request.call else request.call end ).tap{ |_| ::STDERR.puts ::JSON.pretty_generate _ if debug }["output"].select{ |_| "message" == _["type"] }.map do || ["content"].assert_one.fetch("text").strip end.assert_one_or_less or raise Error, "empty message assertion" end |