Skip to main content

sim_lib_openai_server/codec_openai/
mod.rs

1use sim_kernel::{CodecId, Lib, Linker, LoadCx, Result};
2
3/// Decoding of OpenAI request/response JSON into SIM transcript expressions.
4pub mod decode;
5/// Encoding of SIM transcript expressions into OpenAI request/response JSON.
6pub mod encode;
7/// Validated transcript and codec-option shapes for the OpenAI codec.
8pub mod shapes;
9/// Server-sent-event streaming of gateway events on OpenAI surfaces.
10pub mod streaming;
11
12pub use decode::{decode_openai_request, decode_openai_response};
13pub use encode::{encode_openai_request, encode_openai_response, encode_openai_responses_response};
14pub use shapes::{ChatTranscript, OpenAiCodecOptions, OpenAiRequestOptions};
15pub use sim_codec_chat::{OpenAiCodec, OpenAiCodecLib, openai_codec_symbol};
16pub use streaming::{
17    GatewayEventData, OpenAiSseSurface, StreamSink, encode_gateway_events_sse,
18    gateway_event_data_from_packet, gateway_event_data_kind, gateway_event_data_packets,
19};
20
21const OPENAI_CODEC_RUNTIME_ID: CodecId = CodecId(0);
22
23/// Registers the OpenAI codec with the linker, resolving its expression and
24/// options shapes and installing it as a runtime codec value.
25pub fn install_openai_codec(cx: &mut LoadCx, linker: &mut Linker<'_>) -> Result<()> {
26    OpenAiCodecLib::new(OPENAI_CODEC_RUNTIME_ID).load(cx, linker)
27}