Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertHeadersToHttp(headers []Header) http.Header
- func ConvertQueriesToUrl(queries []Query, url url.Values) url.Values
- func Cookies(client HttpClient) map[string]string
- func IsStreamPreset(p string) bool
- func New() *http.Client
- func SendRequest(client HttpClient, req *Request) (*http.Response, error)
- func SendRequestWithContext(ctx context.Context, client HttpClient, req *Request) (*http.Response, error)
- func WithoutRedirects(ctx context.Context) context.Context
- type Header
- type HttpClient
- type Query
- type Request
- type Response
- func SendRequestAndConvert(client HttpClient, req *Request, exampleID idwrap.IDWrap) (Response, error)
- func SendRequestAndConvertStream(ctx context.Context, client HttpClient, req *Request, exampleID idwrap.IDWrap, ...) (Response, error)
- func SendRequestAndConvertWithContext(ctx context.Context, client HttpClient, req *Request, exampleID idwrap.IDWrap) (Response, error)
- type ResponseVar
- type StreamEvent
- type StreamOptions
- type StreamResult
Constants ¶
const ( StreamPresetOpenAI = "openai" StreamPresetAnthropic = "anthropic" StreamPresetVercelAI = "vercel-ai" // StreamPresetSSE is raw Server-Sent Events: the text is every data payload. StreamPresetSSE = "sse" )
Stream presets: how a streamed response's text is assembled from its events.
const DefaultStreamTimeout = 30 * time.Second
DefaultStreamTimeout bounds how long a stream may stay open.
const MaxStreamEvents = 10000
MaxStreamEvents bounds the events kept per response; EventCount still counts all of them.
const TimeoutRequest = 60 * time.Second
Variables ¶
var StreamPresets = []string{StreamPresetOpenAI, StreamPresetAnthropic, StreamPresetVercelAI, StreamPresetSSE}
StreamPresets lists every preset.
Functions ¶
func ConvertHeadersToHttp ¶
func Cookies ¶
func Cookies(client HttpClient) map[string]string
Cookies returns the latest value of every cookie the client has received, by name. Empty for a client that doesn't use a recording jar.
func IsStreamPreset ¶
IsStreamPreset reports whether p names a preset.
func SendRequest ¶
func SendRequest(client HttpClient, req *Request) (*http.Response, error)
func SendRequestWithContext ¶
func WithoutRedirects ¶
WithoutRedirects marks a request context so a client from New returns a 30x response as is instead of following it (the yamlflow request option follow_redirects: false). Other requests on the same client still follow redirects.
Types ¶
type Header ¶
type Response ¶
type Response struct {
StatusCode int `json:"statusCode"`
Body []byte `json:"body"`
Headers []Header `json:"headers"`
// URL is the URL the response came from, after any redirects; Redirects is how many
// redirects were followed to get there.
URL string `json:"url,omitempty"`
Redirects int `json:"redirects,omitempty"`
// Stream is set when the response was read as a stream (see SendRequestAndConvertStream).
Stream *StreamResult `json:"stream,omitempty"`
}
func SendRequestAndConvert ¶
func SendRequestAndConvertStream ¶
func SendRequestAndConvertStream(ctx context.Context, client HttpClient, req *Request, exampleID idwrap.IDWrap, opts *StreamOptions) (Response, error)
SendRequestAndConvertStream sends a request and converts the response. The body is read as a stream when opts is set or the response is text/event-stream; otherwise it is read whole, as SendRequestAndConvertWithContext does.
func SendRequestAndConvertWithContext ¶
func SendRequestAndConvertWithContext(ctx context.Context, client HttpClient, req *Request, exampleID idwrap.IDWrap) (Response, error)
SendRequestAndConvertWithContext sends a request and converts the response. A text/event-stream response is read as a raw SSE stream (see SendRequestAndConvertStream).
type ResponseVar ¶
type ResponseVar struct {
StatusCode int `json:"status"`
Body any `json:"body"`
Headers map[string]string `json:"headers"`
Duration int32 `json:"duration"`
// URL is the final URL after redirects (response.url); Redirects how many were followed
// (response.redirects).
URL string `json:"url"`
Redirects int `json:"redirects"`
// Stream is the streamed response's result; StreamFields exposes it to expressions.
Stream *StreamResult `json:"-"`
}
func ConvertResponseToVar ¶
func ConvertResponseToVar(r Response) ResponseVar
func (ResponseVar) StreamFields ¶
func (r ResponseVar) StreamFields() map[string]any
StreamFields are the response fields a streamed response adds: text, events, event_count, ttft_ms (when a token arrived) and usage (when the stream reported it). Nil when the response was not streamed.
type StreamEvent ¶
type StreamEvent struct {
Event string `json:"event,omitempty"`
Data any `json:"data"`
ID string `json:"id,omitempty"`
}
StreamEvent is one event of a streamed response. Data is the parsed JSON when the payload is JSON, else the text.
type StreamOptions ¶
type StreamOptions struct {
// Preset assembles the text; "" is raw sse.
Preset string
// Timeout is the longest the stream may stay open; 0 is DefaultStreamTimeout.
Timeout time.Duration
}
StreamOptions asks for a response to be read as a stream.
type StreamResult ¶
type StreamResult struct {
Preset string `json:"preset"`
// Text is the message assembled by the preset.
Text string `json:"text"`
// Events are the first MaxStreamEvents events; EventCount counts all of them.
Events []StreamEvent `json:"events,omitempty"`
EventCount int `json:"event_count"`
// TTFT is the time from sending the request to the first event that added text (raw sse:
// the first data event). Nil when none did.
TTFT *time.Duration `json:"ttft,omitempty"`
// Usage is the token usage the stream reported, merged across events.
Usage map[string]any `json:"usage,omitempty"`
}
StreamResult is what a streamed response assembled.