mirror of
https://github.com/ollama/ollama.git
synced 2026-12-04 00:21:20 +00:00
int: log thinking on failure (#20133)
Make sure test failures log thinking traces so we can detect thinking loops.
This commit is contained in:
1 parent
641fe1b18f
commit
6d9b5e76be
3 files changed
+30
No files matched your search
@@ -76,7 +76,9 @@ func runAPIGenerate(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
stallTimer := time.NewTimer(initialTimeout)
|
||||
var buf bytes.Buffer
|
||||
thinking := logThinkingOnFailure(t)
|
||||
fn := func(response api.GenerateResponse) error {
|
||||
thinking(response.Thinking)
|
||||
// Fields that must always be present
|
||||
if response.Model == "" {
|
||||
t.Errorf("response missing model: %#v", response)
|
||||
@@ -239,7 +241,9 @@ func runAPIChat(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
stallTimer := time.NewTimer(initialTimeout)
|
||||
var buf bytes.Buffer
|
||||
thinking := logThinkingOnFailure(t)
|
||||
fn := func(response api.ChatResponse) error {
|
||||
thinking(response.Message.Thinking)
|
||||
// Fields that must always be present
|
||||
if response.Model == "" {
|
||||
t.Errorf("response missing model: %#v", response)
|
||||
|
||||
@@ -54,7 +54,9 @@ func runLongInputContext(t *testing.T) {
|
||||
pullOrSkip(ctx, t, client, req.Model)
|
||||
|
||||
var response strings.Builder
|
||||
thinking := logThinkingOnFailure(t)
|
||||
err := client.Chat(ctx, &req, func(resp api.ChatResponse) error {
|
||||
thinking(resp.Message.Thinking)
|
||||
response.WriteString(resp.Message.Content)
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -398,12 +398,34 @@ func ChatTestHelper(ctx context.Context, t *testing.T, req api.ChatRequest, anyR
|
||||
DoChat(ctx, t, client, req, anyResp, 30*time.Second, 10*time.Second)
|
||||
}
|
||||
|
||||
// logThinkingOnFailure collects streamed thinking separately from answer checks.
|
||||
func logThinkingOnFailure(t *testing.T) func(string) {
|
||||
var mu sync.Mutex
|
||||
var thinking strings.Builder
|
||||
t.Cleanup(func() {
|
||||
if t.Failed() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if thinking.Len() > 0 {
|
||||
t.Logf("thinking output: %s", thinking.String())
|
||||
}
|
||||
}
|
||||
})
|
||||
return func(text string) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
thinking.WriteString(text)
|
||||
}
|
||||
}
|
||||
|
||||
func DoGenerate(ctx context.Context, t *testing.T, client *api.Client, genReq api.GenerateRequest, anyResp []string, initialTimeout, streamTimeout time.Duration) []int {
|
||||
thinking := logThinkingOnFailure(t)
|
||||
stallTimer := time.NewTimer(initialTimeout)
|
||||
var buf bytes.Buffer
|
||||
var context []int
|
||||
fn := func(response api.GenerateResponse) error {
|
||||
// fmt.Print(".")
|
||||
thinking(response.Thinking)
|
||||
buf.Write([]byte(response.Response))
|
||||
if !stallTimer.Reset(streamTimeout) {
|
||||
return errors.New("stall was detected while streaming response, aborting")
|
||||
@@ -539,11 +561,13 @@ func summarizeMessages(msgs []api.Message) string {
|
||||
}
|
||||
|
||||
func DoChat(ctx context.Context, t *testing.T, client *api.Client, req api.ChatRequest, anyResp []string, initialTimeout, streamTimeout time.Duration) *api.Message {
|
||||
thinking := logThinkingOnFailure(t)
|
||||
stallTimer := time.NewTimer(initialTimeout)
|
||||
var buf bytes.Buffer
|
||||
role := "assistant"
|
||||
fn := func(response api.ChatResponse) error {
|
||||
// fmt.Print(".")
|
||||
thinking(response.Message.Thinking)
|
||||
role = response.Message.Role
|
||||
buf.Write([]byte(response.Message.Content))
|
||||
if !stallTimer.Reset(streamTimeout) {
|
||||
|
||||
Reference in new issue
Block a user