~/bend-docscommunity

pure.bend checks

raw source on the hub · import bend-kit-llm@0.17.0.0/pure.bend as Pure

5 imports
import Base
import ./sse.bend as Sse
import bend-kit-json@0.7.3.0/json.bend as Json
import bend-kit-bytes@0.3.3.1/bytes.bend as Bytes
import bend-kit-encoding@0.5.0.1/encoding.bend as Enc

Types

type Api source · line 8 · raw

Data

Anthropic: POST {base}/v1/messages. OpenAI: POST {base}/chat/completions, which many other providers serve too.

type Role source · line 12 · raw

Data

type Msg source · line 16 · raw

Data

type Req source · line 20 · raw

Data

system: "" for none. max: the most tokens to write.

type Reply source · line 24 · raw

Data

stop: the API's reason, as "end_turn" or "stop". input and output count tokens.

type Err source · line 27 · raw

Data

type Leaf source · line 91 · raw

Data

A JSON leaf: its path, as "content.0.text", and its text.

type Ev source · line 205 · raw

Data

A text piece, the end, an error, or an event with no text.

Definitions

def str source · line 33 · raw

@s:String -> 0x419ec39802735c4664960ab4b9d962e5/json.Val

def kv source · line 36 · raw

@k:String -> @v:0x419ec39802735c4664960ab4b9d962e5/json.Val -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0x419ec39802735c4664960ab4b9d962e5/json.Val)

def num source · line 39 · raw

@+n:U32 -> 0x419ec39802735c4664960ab4b9d962e5/json.Val

def obj source · line 42 · raw

@kvs:List<&1, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0x419ec39802735c4664960ab4b9d962e5/json.Val)> -> 0x419ec39802735c4664960ab4b9d962e5/json.Val

def when source · line 45 · raw

@on:Bool -> @x:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0x419ec39802735c4664960ab4b9d962e5/json.Val) -> @xs:List<&1, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0x419ec39802735c4664960ab4b9d962e5/json.Val)> -> List<&1, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0x419ec39802735c4664960ab4b9d962e5/json.Val)>

def role source · line 52 · raw

@r:Role -> String

def msg source · line 59 · raw

@+r:String -> @t:String -> 0x419ec39802735c4664960ab4b9d962e5/json.Val

def msgs source · line 62 · raw

@xs:List<&2, Msg> -> List<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val>

def sys source · line 69 · raw

@on:Bool -> @s:String -> @xs:List<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> List<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val>

def body source · line 77 · raw

@api:Api -> @req:Req -> @stream:Bool -> 0x419ec39802735c4664960ab4b9d962e5/json.Val

The request body for api. stream asks for SSE.

def path source · line 94 · raw

@+p:String -> @+k:String -> String

def push.arr source · line 97 · raw

@xs:List<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> @+p:String -> @+i:U32 -> @t:List<&1, Pair(String, 0x419ec39802735c4664960ab4b9d962e5/json.Val)> -> List<&1, Pair(String, 0x419ec39802735c4664960ab4b9d962e5/json.Val)>

def push.obj source · line 104 · raw

@kvs:List<&1, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0x419ec39802735c4664960ab4b9d962e5/json.Val)> -> @+p:String -> @t:List<&1, Pair(String, 0x419ec39802735c4664960ab4b9d962e5/json.Val)> -> List<&1, Pair(String, 0x419ec39802735c4664960ab4b9d962e5/json.Val)>

def flat source · line 112 · raw

@f:Nat -> @stack:List<&1, Pair(String, 0x419ec39802735c4664960ab4b9d962e5/json.Val)> -> @acc:List<&2, Leaf> -> List<&2, Leaf>

The leaves under the stack's values, last first. f: at least the values left.

def doc.of source · line 135 · raw

@+n:U32 -> @m:Maybe<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> Maybe<&2, List<&2, Leaf>>

def doc source · line 144 · raw

@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Maybe<&2, List<&2, Leaf>>

Every non-null leaf of a JSON text in document order, keyed by its path, as ("content.0.text", "Hi"). Strings are decoded; numbers keep their text. None when b is not JSON. Each value takes a byte, so n + 1 steps suffice.

def look source · line 149 · raw

@d:List<&2, Leaf> -> @+k:String -> String

The first value at path k, or "".

def count source · line 156 · raw

@s:String -> U32

def dots source · line 159 · raw

@s:String -> @+n:U32 -> U32

def block source · line 167 · raw

@+p:String -> Bool

Is p the text of a content block, "content.<i>.text"?

def blocks source · line 171 · raw

@d:List<&2, Leaf> -> String

The text blocks of an Anthropic message, joined.

def reply.of source · line 178 · raw

@api:Api -> @+d:List<&2, Leaf> -> Reply

def reply.got source · line 187 · raw

@api:Api -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @m:Maybe<&2, List<&2, Leaf>> -> Result<&1, &1, Err, Reply>

def reply.copy source · line 194 · raw

@api:Api -> @r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> Result<&1, &1, Err, Reply>

def reply source · line 199 · raw

@api:Api -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Result<&1, &1, Err, Reply>

A 2xx response body as a Reply.

def ev.text source · line 211 · raw

@+s:String -> Ev

def ev.doc source · line 214 · raw

@m:Maybe<&2, List<&2, Leaf>> -> List<&2, Leaf>

def ev.anthropic source · line 217 · raw

@+name:String -> @data:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Ev

def ev.openai source · line 223 · raw

@+s:String -> Ev

def ev source · line 230 · raw

@api:Api -> @e:0x991882b40a34430d1ce9f56190dc09ff/sse.Message -> Ev

What one SSE event of api means.

def ok source · line 241 · raw

@+s:U32 -> Bool

def again.status source · line 245 · raw

@+s:U32 -> Bool

Statuses a later try may clear: 408, 409, 429, and 5xx, which holds Anthropic's 529.