exchange

package
v0.1.92 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package exchange maps GoModel's core request and response types to the unified pluginapi types plugins see, and applies plugin edits back.

Message identity: messages built from a request get IDs "m<index>" (the 0-based position in the original message or input list); a Responses instructions field becomes the message with ID "instructions"; completion choices are keyed "choice:<index>". Apply-back consults Prompt.Changes and Completion.Changes: untouched messages are copied from the original typed value verbatim, edited ones have only the touched parts rewritten inside their original structure, inserted ones are encoded from the unified form, and removed ones are dropped.

Index

Constants

View Source
const InstructionsMessageID = "instructions"

InstructionsMessageID is the ID of the message built from a Responses request's instructions field.

Variables

This section is empty.

Functions

func ApplyToChatRequest

func ApplyToChatRequest(original *core.ChatRequest, p *pluginapi.Prompt) (*core.ChatRequest, error)

ApplyToChatRequest returns a copy of original with the prompt's edits applied. Untouched messages are copied verbatim; edited ones keep their envelope with only the touched parts rewritten; inserted ones are encoded from the unified form. Changing "model" or "stream" is an error because routing has already happened.

func ApplyToChatResponse

func ApplyToChatResponse(original *core.ChatResponse, c *pluginapi.Completion) (*core.ChatResponse, error)

ApplyToChatResponse returns a copy of original with the completion's edits applied. Edited choices have their text rewritten in place and their finish reason updated; replaced choices get a plain string content. Extra fields (reasoning_content, refusal) are kept.

func ApplyToResponsesRequest

func ApplyToResponsesRequest(original *core.ResponsesRequest, p *pluginapi.Prompt) (*core.ResponsesRequest, error)

ApplyToResponsesRequest returns a copy of original with the prompt's edits applied. The instructions message writes back to Instructions (a removed one clears it; a system message inserted at position 0 when there was no instructions message sets it). The input keeps its original container shape and a string input stays a string while it is a single text message. Changing "model" or "stream" is an error.

func ApplyToResponsesResponse

func ApplyToResponsesResponse(original *core.ResponsesResponse, c *pluginapi.Completion) (*core.ResponsesResponse, error)

ApplyToResponsesResponse returns a copy of original with the completion's edits applied. Edited text parts are rewritten in their output_text items; a replaced choice keeps a single output_text in the first message item and drops the other text items. The response status and the finish reason are left unchanged: Responses has no finish_reason field, and the host renders a "content_filter" decision through headers instead.

func ChatRequestFromMessages

func ChatRequestFromMessages(model string, msgs []pluginapi.Message, maxTokens int, temperature *float64) *core.ChatRequest

ChatRequestFromMessages builds the chat request for a plugin's internal inference call. Parts a chat message cannot carry are reduced to their text.

func CompletionToChatResponse

func CompletionToChatResponse(c *pluginapi.Completion, model string) *core.ChatResponse

CompletionToChatResponse synthesizes a chat response from a completion, for "respond" decisions on chat endpoints.

func CompletionToResponsesResponse

func CompletionToResponsesResponse(c *pluginapi.Completion, model string) *core.ResponsesResponse

CompletionToResponsesResponse synthesizes a Responses response from a completion, for "respond" decisions on the Responses endpoint. Only the first choice is rendered.

func FromChatRequest

func FromChatRequest(req *core.ChatRequest) (*pluginapi.Prompt, error)

FromChatRequest builds the unified prompt for a chat completion request. Message IDs are "m<index>".

func FromChatResponse

func FromChatResponse(resp *core.ChatResponse) (*pluginapi.Completion, error)

FromChatResponse builds the unified completion for a chat response. Each choice's parts are, in order: reasoning_content, content text, refusal, tool calls. Choice messages get the ID "choice:<index>".

func FromResponsesRequest

func FromResponsesRequest(req *core.ResponsesRequest) (*pluginapi.Prompt, error)

FromResponsesRequest builds the unified prompt for a Responses request. A non-empty instructions field becomes a leading system message with ID "instructions"; input items get IDs "m<index>" (a string input is "m0"). Items the mapper does not model (reasoning, item references, hosted tool items) become assistant messages with one opaque part.

func FromResponsesResponse

func FromResponsesResponse(resp *core.ResponsesResponse) (*pluginapi.Completion, error)

FromResponsesResponse builds the unified completion for a Responses response: one choice whose parts follow the output items in order. output_text content becomes text, refusal content a refusal part, function_call items tool calls, reasoning items reasoning parts (summary text), and everything else opaque parts. The finish reason is derived: "tool_calls" when a function call is present, else "stop" for a completed response, "length" for an incomplete one, otherwise the status.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL