Skip to content
    Back to all Bounties

    Earn 3,600 ($36.00)

    Time Remainingdue 10 months ago
    Completed

    Streaming JSON Parser

    jxnl
    jxnl
    Posted 10 months ago
    This Bounty has been completed!
    @jxnl's review of @VikasGola
    4.7
    Average Rating
    Communication 4/5, Quality 5/5, Timeliness 5/5

    Bounty 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

    1. 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 BaseModel
     
    class Task(BaseModel):
    id: int
    title: str
     
    # This is your existing generator that yields chunks of JSON string do not edit this
    def json_chunks(json_string):
    for i in range(0, len(json_string), 5): # replace 5 with the chunk size you want
    chunk = json_string[i:i+5]
    print("yield chunk:", chunk)
    yield chunk
     
    def tasks_from_chunks(json_chunks: Generator[str, None, None]):
    # do something to get a single task_json
    task = Task.parse_raw(**task_json)
    print("yield task", task)
    yield task
    json_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)

    Link to Project

    https://github.com/jxnl/openai_function_call/issues/31

    Copyright © 2024 Replit, Inc. All rights reserved.
    • twitter
    • tiktok
    • instagram
    • facebook

    Replit

    Programming languages

    • Python
    • JavaScript
    • TypeScript
    • Node.js
    • Nix
    • HTML, CSS, JS
    • C++
    • Golang