(t *testing.T)
| 95 | } |
| 96 | |
| 97 | func TestAdvisorRunStreamsAdviceDeltas(t *testing.T) { |
| 98 | t.Parallel() |
| 99 | |
| 100 | var deltas []string |
| 101 | runtime, err := chatadvisor.NewRuntime(chatadvisor.RuntimeConfig{ |
| 102 | Model: &chattest.FakeModel{ |
| 103 | ProviderName: "test-provider", |
| 104 | ModelName: "test-model", |
| 105 | StreamFn: func(_ context.Context, _ fantasy.Call) (fantasy.StreamResponse, error) { |
| 106 | return streamFromParts([]fantasy.StreamPart{ |
| 107 | {Type: fantasy.StreamPartTypeTextStart, ID: "text-1"}, |
| 108 | {Type: fantasy.StreamPartTypeTextDelta, ID: "text-1", Delta: "Use "}, |
| 109 | {Type: fantasy.StreamPartTypeTextDelta, ID: "text-1", Delta: "the smaller "}, |
| 110 | {Type: fantasy.StreamPartTypeTextDelta, ID: "text-1", Delta: "diff."}, |
| 111 | {Type: fantasy.StreamPartTypeTextEnd, ID: "text-1"}, |
| 112 | {Type: fantasy.StreamPartTypeFinish, FinishReason: fantasy.FinishReasonStop}, |
| 113 | }), nil |
| 114 | }, |
| 115 | }, |
| 116 | MaxUsesPerRun: 2, |
| 117 | MaxOutputTokens: 128, |
| 118 | }) |
| 119 | require.NoError(t, err) |
| 120 | |
| 121 | result, err := runtime.RunAdvisor(t.Context(), "what should I do?", nil, &chatadvisor.RunAdvisorOptions{ |
| 122 | OnAdviceDelta: func(delta string) { |
| 123 | deltas = append(deltas, delta) |
| 124 | }, |
| 125 | }) |
| 126 | require.NoError(t, err) |
| 127 | require.Equal(t, []string{"Use ", "the smaller ", "diff."}, deltas) |
| 128 | require.Equal(t, chatadvisor.ResultTypeAdvice, result.Type) |
| 129 | require.Equal(t, "Use the smaller diff.", result.Advice) |
| 130 | require.Equal(t, 1, result.RemainingUses) |
| 131 | } |
| 132 | |
| 133 | func TestAdvisorRunResetsAdviceDeltasOnRetry(t *testing.T) { |
| 134 | t.Parallel() |
nothing calls this directly
no test coverage detected