Open ai code generation and serialization failing using ruby
OPENAPI: openai links Method: Post /chat/completions device: mac m1 language: Ruby versions: microsoft_kiota_abstractions-0.14.0, microsoft_kiota_authentication_oauth-0.6.0, microsoft_kiota_faraday-0.10.0, microsoft_kiota_serialization_json-0.9.0, microsoft_kiota_authentication_oauth-0.8.0
I want to run a openai, /chat/completions, code seem to generate with a little mistake which i tried to ignore (I do not think is this part relevant) gen file : create_chat_completion_request.rb
def self.create_from_discriminator_value(parse_node)
raise StandardError, 'parse_node cannot be null' if parse_node.nil?
mapping_value_node = parse_node.get_child_node("")
unless mapping_value_node.nil? then
mapping_value = mapping_value_node.get_string_value
case mapping_value
end
end
return Completions.new
end
by just using StringCompletion.new as return of case for else and 'string'.
after that it got error serializing temperature
on this line
microsoft_kiota_serialization_json-0.9.0/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb:169:in write_object_value': undefined method serialize' for 0.5:Float (NoMethodError)
after a little debug it try to serialize float value
running code
require 'microsoft_kiota_abstractions'
require 'microsoft_kiota_serialization_json'
require 'microsoft_kiota_authentication_oauth'
require 'microsoft_kiota_faraday'
require_relative './api_chat'
BearerKey = 'sk-<your secret key>'
# ApiKeyAuthenticationProvider
auth_provider = MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider.new(BearerKey)
request_adapter = MicrosoftKiotaFaraday::FaradayRequestAdapter.new(auth_provider,
MicrosoftKiotaSerializationJson::JsonParseNodeFactory.new,
MicrosoftKiotaSerializationJson::JsonSerializationWriterFactory.new)
gpt = ApiSdk::ApiChat.new(request_adapter)
chat_params = ApiSdk::Models::CreateChatCompletionRequest.new
chat_params.model = 'gpt-3.5-turbo'
chat_params.max_tokens = 50
chat_params.temperature = 0.5 # this value got error for serialization
message = ApiSdk::Models::ChatCompletionRequestMessage.new
message.content = "Why Hinton is called the father of deep learning?"
message.role = ApiSdk::Models::ChatCompletionRequestMessageRole[:User]
chat_params.messages = [message]
chat = gpt.chat.completions.post(chat_params)
print(chat.choices[0].text)
tnx for response @baywet @mtodd
Thanks for reporting this. This is caused because Ruby generation is still experimental and doesn't implement composed type serialization which open ai API description uses a lot. This work is tracked by microsoft/kiota-abstractions-ruby#73 however we don't currently have a developer working on Ruby so contributions are welcome.
I guess you could try to get around it by poking the models and manually implementing the correct serialization. I suggest you generate a client for the same API in a language you're familiar with which supports composed types (go/java/c#) and compare.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.