Skip to content

ChatCompletion->create_async #56

Closed Answered by pkusunjy
asnagni asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @asnagni ,

Perhaps you need to pass your own callback function to the stream parameter in create_async, and here is a tiny demo illustrating how it works.

// define your own callback function
auto callback = [](std::string data, intptr_t ptr) -> bool {
    std::cout << data << '\n';
    return true;
};

// pass it to stream
xxx.create_async(model, conversation, std::nullopt, std::nullopt, std::nullopt, callback);

The stream will return streaming messages with data: {somejsondata} and be closed by a data: [DONE] message.

Hope this may help you.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@asnagni
Comment options

Answer selected by D7EAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants