Documentation
¶
Overview ¶
Package testllm is a fake model service for tests: the model-list endpoint and a scripted, streaming chat endpoint for each protocol (openai, openai-responses, anthropic). Requests a real service would reject get a 400 and are marked.
Index ¶
- type Call
- type Request
- type Server
- func (s *Server) Advance()
- func (s *Server) Headers() []http.Header
- func (s *Server) Release()
- func (s *Server) Requests() []Request
- func (s *Server) RequireKey(k string)
- func (s *Server) Script(turns ...Turn)
- func (s *Server) SetDisplayNames(n map[string]string)
- func (s *Server) SetHidden(m ...string)
- func (s *Server) SetListStatus(code int)
- func (s *Server) SetModels(m ...string)
- type Turn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Request ¶
type Request struct {
System, Messages, Tools json.RawMessage
Header http.Header
Model, Path, Invalid string
Body json.RawMessage
}
Request is the raw JSON of one chat request. For openai-responses System is the instructions and Messages the input. Invalid says why the fake rejected it with a 400; empty means it was answered from the script.
type Server ¶
type Server struct {
URL string // base URL, as a user would enter it
Mux *http.ServeMux
// contains filtered or unexported fields
}
func (*Server) Advance ¶
func (s *Server) Advance()
Advance drops the current turn, e.g. a Status turn that keeps answering.
func (*Server) Release ¶
func (s *Server) Release()
Release lets hanging turns finish. It is safe to call more than once.
func (*Server) RequireKey ¶
func (*Server) SetDisplayNames ¶ added in v1.1.0
SetDisplayNames lists models the way a ChatGPT subscription token sees them: models[].slug with display_name.
func (*Server) SetListStatus ¶
SetListStatus makes the model list answer with that HTTP status; 0 restores it.
type Turn ¶
type Turn struct {
Text []string
Calls []Call
Hang bool
Status int
Code string // openai-responses: the error.code a Status turn's body carries
Finish string
Reasoning string
Fail string
FailCode string
Incomplete bool
Truncate bool
Refusal string // openai-responses: the reply is this refusal, not text
}
Turn is one scripted model response. Status != 0 answers with that HTTP error (its body echoes the key the request carried). Hang streams the text, then waits for Release or the client to go away. Finish, if set, is the raw finish reason sent (OpenAI finish_reason, Anthropic stop_reason).
openai-responses only: Reasoning adds a reasoning item with that encrypted_content; Fail ends with response.failed carrying that message, FailCode sets its error.code (default server_error), Incomplete with response.incomplete, Truncate with no terminal event. A Status turn keeps answering (the SDK's retries) until Advance or the next Script call.