Prepare requests with captured conversation history
This commit is contained in:
38
exchange_test.go
Normal file
38
exchange_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package promptkit
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/promptkit/internal/domain"
|
||||
)
|
||||
|
||||
func TestExchangeDetailsAndRequestConversion(t *testing.T) {
|
||||
var nilExchange *Exchange
|
||||
if got := nilExchange.Details(); got.RunID != "" || got.Messages != nil {
|
||||
t.Fatalf("nil details = %#v", got)
|
||||
}
|
||||
if _, err := toDomainRunRequest(RunRequest{ContinueFrom: &Exchange{}}); err == nil {
|
||||
t.Fatal("empty exchange accepted")
|
||||
}
|
||||
history := domain.CaptureExchange(nil, "source", []domain.RenderedMessage{{Role: domain.RoleUser, Content: "private", CacheControl: &domain.CacheControl{Type: domain.CacheControlEphemeral, TTL: "1h"}}}, "answer")
|
||||
handle := &Exchange{internal: history}
|
||||
request, err := toDomainRunRequest(RunRequest{ContinueFrom: handle})
|
||||
if err != nil || request.ContinueFrom != history || !request.CaptureExchange {
|
||||
t.Fatalf("request = %#v, error = %v", request, err)
|
||||
}
|
||||
details := handle.Details()
|
||||
details.Messages[0].CacheControl.TTL = "changed"
|
||||
if handle.Details().Messages[0].CacheControl.TTL != "1h" {
|
||||
t.Fatal("details changed exchange")
|
||||
}
|
||||
if strings.Contains(fmt.Sprintf("%v %#v", handle, handle), "private") {
|
||||
t.Fatal("format exposed history")
|
||||
}
|
||||
encoded, err := json.Marshal(PreparedRun{ParentRunID: "source"})
|
||||
if err != nil || !strings.Contains(string(encoded), `"parent_run_id":"source"`) {
|
||||
t.Fatalf("prepared JSON = %s, %v", encoded, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user