Skip to contents

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

Jonathan Chassot

Examples

if (FALSE) {
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"
#
}