mirror of
https://github.com/we-promise/sure
synced 2026-04-25 17:15:07 +02:00
* Wire conversation history through OpenAI responses API * Fix RuboCop hash brace spacing in assistant tests * Pipelock ignores * Batch fixes --------- Co-authored-by: sokiee <sokysrm@gmail.com>
49 lines
1.0 KiB
Ruby
49 lines
1.0 KiB
Ruby
class Provider::Openai::ChatConfig
|
|
def initialize(functions: [], function_results: [])
|
|
@functions = functions
|
|
@function_results = function_results
|
|
end
|
|
|
|
def tools
|
|
functions.map do |fn|
|
|
{
|
|
type: "function",
|
|
name: fn[:name],
|
|
description: fn[:description],
|
|
parameters: fn[:params_schema],
|
|
strict: fn[:strict]
|
|
}
|
|
end
|
|
end
|
|
|
|
def build_input(prompt: nil)
|
|
input_messages = prompt.present? ? [ { role: "user", content: prompt } ] : []
|
|
|
|
results = function_results.map do |fn_result|
|
|
# Handle nil explicitly to avoid serializing to "null"
|
|
output = fn_result[:output]
|
|
serialized_output = if output.nil?
|
|
""
|
|
elsif output.is_a?(String)
|
|
output
|
|
else
|
|
output.to_json
|
|
end
|
|
|
|
{
|
|
type: "function_call_output",
|
|
call_id: fn_result[:call_id],
|
|
output: serialized_output
|
|
}
|
|
end
|
|
|
|
[
|
|
*input_messages,
|
|
*results
|
|
]
|
|
end
|
|
|
|
private
|
|
attr_reader :functions, :function_results
|
|
end
|