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:
- Declare — domain/pipeline.go, no adapter imports: an api/llm.Call (system prompt + input/output codecs) wrapped in a ports.IOPort.
- 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.
- 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