Skip to content

Commit b9a7865

Browse files
committed
Fix bug with large strings when using HTTP streams in Julia. Bump to 0.0.8.
1 parent 6c9f5f4 commit b9a7865

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

julia/Bytez/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Bytez"
22
uuid = "aeec0939-83cf-4f14-8c49-2dc7569399f2"
3-
version = "0.0.7"
3+
version = "0.0.8"
44
authors = ["Bytez <[email protected]>"]
55
license = "MIT"
66

julia/Bytez/src/Bytez.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ function request(path::String, body::Union{Dict, Nothing} = nothing)
7575
"Content-type" => "application/json",
7676
),
7777
) do http_io
78-
7978
write(http_io, JSON3.write(body))
8079
startread(http_io)
8180

@@ -85,6 +84,10 @@ function request(path::String, body::Union{Dict, Nothing} = nothing)
8584

8685
put!(data_channel, chunk) # Write chunk to channel
8786
end
87+
88+
# get the last chunk once you've reached the end
89+
chunk = String(readavailable(http_io))
90+
put!(data_channel, chunk)
8891
end
8992
# always make the status code available via a channel for non streaming calls
9093
status_code = response.status
@@ -102,7 +105,13 @@ function request(path::String, body::Union{Dict, Nothing} = nothing)
102105
return data_channel
103106
end
104107

105-
result = JSON3.read(String(take!(data_channel)))
108+
json_string = ""
109+
while isopen(data_channel)
110+
item = String(take!(data_channel))
111+
json_string *= item
112+
end
113+
114+
result = JSON3.read(json_string)
106115

107116
error = get(result, "error", nothing)
108117

@@ -145,7 +154,7 @@ function run(input::Any, model_id_dict::Dict, options::Dict)
145154
error = get(results, "error", nothing)
146155

147156
if error !== nothing
148-
throw(Exception(error))
157+
throw(error)
149158
end
150159

151160
return results

0 commit comments

Comments
 (0)