This example shows how to generate a text embedding for a document using the OpenAI API.
#include "docwire.h"
int main(int argc, char* argv[])
{
std::vector<message_ptr> out_msgs;
try
{
std::filesystem::path(
"data_processing_definition.doc") | content_type::detector{} | office_formats_parser{} | plain_text_exporter() | openai::embed(environment::get(
"OPENAI_API_KEY").
value()) | out_msgs;
ensure(out_msgs[0]->is<ai::embedding>()) ==
true;
ensure(out_msgs[0]->get<ai::embedding>().values.size()) == 1536;
}
catch (const std::exception& e)
{
return 1;
}
return 0;
}
DOCWIRE_CORE_EXPORT std::string diagnostic_message(const std::exception &e)
Generates a diagnostic message for the given nested exceptions chain.
std::variant< std::nullptr_t, bool, std::int64_t, std::uint64_t, double, std::string, array, object > value
A variant type representing any serialized value.
The main namespace for the DocWire SDK.
ensure(const T &, const docwire::source_location &) -> ensure< T >
Deduction guide for the ensure class template.