I am using Julia and the JSON
module to convert a Dict
to JSON and sent it to LLM APIs. Below is the code I’m using:
function send_request(url, headers, payload)
try
@debug "Payload" payload
json_payload = JSON.json(payload)
@debug "JSON payload ready"
response = HTTP.request("POST", url, headers, json_payload, proxy=ENV["http_proxy"])
if response.status == 200
return response
else
@error "Request failed with status: $(response.status)"
println(String(response.body))
return nothing
end
catch http_error
@error "HTTP request error: $http_error"
return nothing
end
end
Normally, this works fine. However, when the json_payload
contains a field that is the base64 encoding of an image (around 2MB in size), the call to JSON.json(payload)
takes a very long time to complete.
Is there any way to speed up the conversion process when dealing with large base64-encoded data in the JSON payload?