Skip to content

Commit

Permalink
Help groq only return JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Apr 25, 2024
1 parent 8d90413 commit 0def6c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Return JSON object for each one:
{ "name": "Mercury", "position": 1, "description": "Mercury is ..." }
Between each response, say "NEXT" to clearly delineate each JSON response.
Don't say anything else except the JSON objects above.
```

The code in the repo uses the `NEXT` token to know when to process the JSON object.
Expand Down
4 changes: 3 additions & 1 deletion examples/streaming-to-json-objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
{ "name": "Mercury", "position": 1, "description": "Mercury is ..." }
Between each response, say "NEXT" to clearly delineate each JSON response.
Don't say anything else except the JSON objects above.
TEXT

# Handle each JSON object once it has been fully streamed
Expand All @@ -63,7 +65,7 @@ def call(content)
json = JSON.parse(@buffer)

# do something with JSON, e.g. save to database
pp json
puts json.to_json

# reset buffer
@buffer = ""
Expand Down

0 comments on commit 0def6c6

Please sign in to comment.