MCPcopy Create free account
hub / github.com/bytebase/bytebase / doHTTPRequest

Function doHTTPRequest

backend/api/v1/ai_service.go:693–711  ·  view source on GitHub ↗

doHTTPRequest executes an HTTP request and returns the response body.

(_ context.Context, httpReq *http.Request, provider string)

Source from the content-addressed store, hash-verified

691
692// doHTTPRequest executes an HTTP request and returns the response body.
693func doHTTPRequest(_ context.Context, httpReq *http.Request, provider string) ([]byte, error) {
694 client := &http.Client{}
695 httpResp, err := client.Do(httpReq)
696 if err != nil {
697 return nil, errors.Errorf("failed to send HTTP request to %s: %s", provider, err)
698 }
699 defer httpResp.Body.Close()
700
701 body, err := io.ReadAll(httpResp.Body)
702 if err != nil {
703 return nil, errors.Errorf("failed to read %s response body: %s", provider, err)
704 }
705
706 if httpResp.StatusCode != http.StatusOK {
707 return nil, errors.Errorf("%s API returned status %d: %s", provider, httpResp.StatusCode, string(body))
708 }
709
710 return body, nil
711}
712
713// chatMessageRoleToOpenAI converts a proto role enum to OpenAI role string.
714func chatMessageRoleToOpenAI(role v1pb.AIChatMessageRole) string {

Callers 3

chatOpenAIMethod · 0.85
chatClaudeMethod · 0.85
chatGeminiMethod · 0.85

Calls 3

DoMethod · 0.80
ErrorfMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected