Back to all Bounties
Earn 3,600 ($36.00)
due 10 months ago
Completed
Streaming JSON Parser
jxnl
Details
Applications
5
Discussion
This Bounty has been completed!
@jxnl's review of @VikasGola
4.7
Communication 4/5, Quality 5/5, Timeliness 5/5Bounty Description
Problem Description
I want to stream chunked json which contains a list of tasks in the key 'tasks' want to return each item as they are streamed in that means when you run this the yield tasks must be shown between yield chunks.
You must not delete the print lines.
And you must only update the function that yields tasks.
More details here:
https://github.com/jxnl/openai_function_call/issues/31
Acceptance Criteria
- PR to this repo that addresses the issue (notebook is fine)
OR 2) Replit with a set of test cases
Technical Details
from pydantic import BaseModelclass Task(BaseModel):id: inttitle: str# This is your existing generator that yields chunks of JSON string do not edit thisdef json_chunks(json_string):for i in range(0, len(json_string), 5): # replace 5 with the chunk size you wantchunk = json_string[i:i+5]print("yield chunk:", chunk)yield chunkdef tasks_from_chunks(json_chunks: Generator[str, None, None]):# do something to get a single task_jsontask = Task.parse_raw(**task_json)print("yield task", task)yield taskjson_string = '{"tasks":[{"id":1,"title":"task1"},{"id":2,"title":"task2"},{"id":3,"title":"task3"}]}'for task in tasks_from_chunks(json_chunks(json_string)):print(task)