openai

The OpenAI Chat Completions form, as pure functions (llm-openai-compatible §OCP-W2).

In the namespace octomy::llm::wire.

Detailed description

OpenAI, Google's OpenAI compatibility, OpenRouter, Groq, llama.cpp, Ollama, LM Studio and vLLM speak this form. These functions build the request and read each answer. They have no network and no state, so each rule of §OCP-W3 to §OCP-W7 has a unit test that calls them directly. OpenAIChatClient and its session facet only send, receive and emit.

Function documentation

chatRequest

QByteArray openai::chatRequest(const octomy::llm::wire::openai::ChatRequest &request, QString *error)

The body of request (§OCP-W3). Empty, with error, when a file of the last user turn has no part in this form: a PDF.

maxTokensField

QString openai::maxTokensField(OnlineProviderKind kind)

The name of the maximum for kind: `max_completion_tokens` for OpenAI, which deprecates `max_tokens` and whose o-series models refuse it, and `max_tokens` for every other kind, because Ollama and LM Studio read only that name (§OCP-W3, §OCP-R1, §OCP-R5).

readCompletion

octomy::llm::wire::openai::Completion openai::readCompletion(const QByteArray &body)

Read body, a response that is not a stream: `choices[0].message.content`, its finish reason and the usage.

readError

octomy::llm::wire::openai::ApiError openai::readError(int httpStatus, const QByteArray &body, int retryAfterSeconds, const QString &provider)

Read an error answer of httpStatus with body (§OCP-W7). `code` is a string at OpenAI and Ollama, and a number at llama.cpp and OpenRouter. A body that is not this JSON gives its first 500 characters. retryAfterSeconds is the `Retry-After` header, or -1. provider names the provider in the user's text.

readStreamEvent

octomy::llm::wire::openai::StreamStep openai::readStreamEvent(const QString &data)

Read data, the data of one event of a stream (§OCP-W4): `[DONE]`, an error object, text, reasoning by either of its names, a finish reason, and the usage. Anything else gives nothing: an unknown field is not an error.

systemRole

QString openai::systemRole(OnlineProviderKind kind)

The role of the system prompt for kind: `developer` for OpenAI, which asks for it from its o1 models on, and `system` for every other kind, because other servers do not all know `developer` (§OCP-W3).

In this section