MCPcopy Index your code
hub / github.com/SMNETSTUDIO/Groq2API / ChatCompletions

Function ChatCompletions

pkg/groq/request.go:95–119  ·  view source on GitHub ↗
(client tls_client.HttpClient, api_request groq.APIRequest, api_key string, organization string, proxy string)

Source from the content-addressed store, hash-verified

93 return base64.StdEncoding.EncodeToString([]byte(prefix))
94}
95func ChatCompletions(client tls_client.HttpClient, api_request groq.APIRequest, api_key string, organization string, proxy string) (*http.Response, error) {
96 if proxy != "" {
97 client.SetProxy(proxy)
98 }
99 body_json, _ := json.Marshal(api_request)
100 header := baseHeader()
101 header.Set("authorization", "Bearer "+api_key)
102 header.Set("groq-app", "chat")
103 header.Set("groq-organization", organization)
104 //response, err := client.Request("POST", "https://api.groq.com/openai/v1/chat/completions", header, nil, bytes.NewBuffer(body_json))
105 req, err := http.NewRequest(http.MethodPost, "https://api.groq.com/openai/v1/chat/completions", bytes.NewBuffer(body_json))
106 req.Header = header
107 if err != nil {
108 return nil, err
109 }
110 response, err := client.Do(req)
111 if err != nil {
112 return nil, err
113 }
114 if response.StatusCode != 200 {
115
116 return nil, errors.New("response status code is not 200")
117 }
118 return response, nil
119}
120func GetModels(client tls_client.HttpClient, api_key string, organization string, proxy string) (*http.Response, error) {
121 header := baseHeader()
122 header.Set("authorization", "Bearer "+api_key)

Callers

nothing calls this directly

Calls 3

baseHeaderFunction · 0.85
SetProxyMethod · 0.80
SetMethod · 0.80

Tested by

no test coverage detected