def body

bend-kit-llm@0.13.0.1 · llm.bend:87

import bend-kit-llm@0.13.0.1/llm.bend as Llm
import Base
import bend-kit-json@0.7.0.0/json.bend as Json

87# The request body for api. stream asks for SSE.
88def body(api: Api, req: Req, stream: Bool) -> Json.Val:
89  match api:
90    case Anthropic{}:
91      Req{model, +system, ms, max} = req
92      obj(Con{kv("model", str(model)), Con{kv("max_tokens", num(max)),
93        when(Bool.not(String.is_empty(system)), kv("system", str(system)),
94          Con{kv("messages", Json.Arr{msgs(ms)}), when(stream, kv("stream", Json.Flag{True{}}), Nil{})})}})
95    case OpenAI{}:
96      Req{model, +system, ms, max} = req
97      obj(Con{kv("model", str(model)), Con{kv("max_completion_tokens", num(max)),
98        Con{kv("messages", Json.Arr{sys(Bool.not(String.is_empty(system)), system, msgs(ms))}),
99          when(stream, kv("stream", Json.Flag{True{}}), Nil{})}}})

Uses (14)

Used by (2)