adapters-openai

command
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package adapters-openai demonstrates go-codex CALLING an LLM — the other direction from examples/adapters-mcp (which lets an LLM call go-codex).

Three steps, mirroring every other ports boundary in this library:

  1. Declare — domain/pipeline.go, no adapter imports: an api/llm.Call (system prompt + input/output codecs) wrapped in a ports.IOPort.
  2. Plug in — main.go: ports.LLMPattern registers the Call (against an llm.Builder, so its LLMSpec catalog is available afterward) and returns a typed *llm.CallHandle.
  3. Bind — main.go: openai.CallAdapter supplies the OpenAI wire format.

This example runs against a local httptest.Server (no real API key or network access needed) that returns an intentionally INVALID completion on the first request and a valid one on the second — demonstrating CallAdapterOptions.MaxRetries' re-prompt-on-invalid-completion loop firing exactly once.

It also demonstrates render/openaitools: once Summarize is plugged into SummarizePattern, llmBuilder.LLMSpec() returns the accumulated catalog of every declared Call, and openaitools.FromLLMSpec/Render converts it into the OpenAI "tools" JSON array shape — letting this SAME LLM-backed Call be exposed as a callable tool to a DIFFERENT orchestrating LLM/agent, with no additional declaration.

Running

go run ./examples/adapters-openai

Jump to

Keyboard shortcuts

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