parse_response {TheOpenAIR} | R Documentation |
Parse a Response From the API
Description
This function takes an input string containing both text and code blocks, and returns a list of blocks with their respective type, content, and language (if applicable). Each block is either of type 'text' or 'code'.
Usage
parse_response(input_string)
Arguments
input_string |
The response from the API |
Value
A list of blocks with type, content, and language (for code blocks)
Author(s)
Jonathan Chassot
Examples
## Not run:
parse_response("Hello world!")
# [[1]]
# [[1]]$type
# [1] "text"
#
# [[1]]$content
# [1] "Hello world!"
#
parse_response("```python\nprint('Hello world!')\n```")
# [[1]]
# [[1]]$type
# [1] "code"
#
# [[1]]$content
# [1] "print('Hello world!')"
#
# [[1]]$language
# [1] "python"
#
parse_response("Hello world!\n\n```python\nprint('Hello world!')\n```")
# [[1]]
# [[1]]$type
# [1] "text"
#
# [[1]]$content
# [1] "Hello world!"
#
# [[2]]
# [[2]]$type
# [1] "code"
#
# [[2]]$content
# [1] "print('Hello world!')"
#
# [[2]]$language
# [1] "python"
#
## End(Not run)
[Package TheOpenAIR version 0.1.0 Index]