MCPcopy Index your code
hub / github.com/coder/coder / TestSimple

Function TestSimple

aibridge/internal/integrationtest/bridge_internal_test.go:803–997  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

801}
802
803func TestSimple(t *testing.T) {
804 t.Parallel()
805
806 getAnthropicResponseID := func(streaming bool, resp *http.Response) (string, error) {
807 if streaming {
808 decoder := ssestream.NewDecoder(resp)
809 stream := ssestream.NewStream[anthropic.MessageStreamEventUnion](decoder, nil)
810 var message anthropic.Message
811 for stream.Next() {
812 event := stream.Current()
813 if err := message.Accumulate(event); err != nil {
814 return "", xerrors.Errorf("accumulate event: %w", err)
815 }
816 }
817 if stream.Err() != nil {
818 return "", xerrors.Errorf("stream error: %w", stream.Err())
819 }
820 return message.ID, nil
821 }
822
823 body, err := io.ReadAll(resp.Body)
824 if err != nil {
825 return "", xerrors.Errorf("read body: %w", err)
826 }
827
828 var message anthropic.Message
829 if err := json.Unmarshal(body, &message); err != nil {
830 return "", xerrors.Errorf("unmarshal response: %w", err)
831 }
832 return message.ID, nil
833 }
834
835 getOpenAIResponseID := func(streaming bool, resp *http.Response) (string, error) {
836 if streaming {
837 // Parse the response stream.
838 decoder := oaissestream.NewDecoder(resp)
839 stream := oaissestream.NewStream[openai.ChatCompletionChunk](decoder, nil)
840 var message openai.ChatCompletionAccumulator
841 for stream.Next() {
842 chunk := stream.Current()
843 message.AddChunk(chunk)
844 }
845 if stream.Err() != nil {
846 return "", xerrors.Errorf("stream error: %w", stream.Err())
847 }
848 return message.ID, nil
849 }
850
851 // Parse & unmarshal the response.
852 body, err := io.ReadAll(resp.Body)
853 if err != nil {
854 return "", xerrors.Errorf("read body: %w", err)
855 }
856
857 var message openai.ChatCompletion
858 if err := json.Unmarshal(body, &message); err != nil {
859 return "", xerrors.Errorf("unmarshal response: %w", err)
860 }

Callers

nothing calls this directly

Calls 15

ParseFunction · 0.92
newFixtureResponseFunction · 0.85
newBridgeTestServerFunction · 0.85
ErrMethod · 0.80
receivedRequestsMethod · 0.80
NotEmptyMethod · 0.80
RecordedPromptUsagesMethod · 0.80
RecordedTokenUsagesMethod · 0.80
RecordedInterceptionsMethod · 0.80
newMockUpstreamFunction · 0.70
NextMethod · 0.65

Tested by

no test coverage detected