Slight cleanup to openai
Remove /v1 from base url, removed some slight repetition
This commit is contained in:
parent
11402c5534
commit
677cfcfebf
@ -185,7 +185,17 @@ func createChatCompletionRequest(
|
|||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OpenAIClient) sendRequest(req *http.Request) (*http.Response, error) {
|
func (c *OpenAIClient) sendRequest(ctx context.Context, r ChatCompletionRequest) (*http.Response, error) {
|
||||||
|
jsonData, err := json.Marshal(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "POST", c.BaseURL+"/v1/chat/completions", bytes.NewBuffer(jsonData))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("Authorization", "Bearer "+c.APIKey)
|
req.Header.Set("Authorization", "Bearer "+c.APIKey)
|
||||||
|
|
||||||
@ -213,17 +223,8 @@ func (c *OpenAIClient) CreateChatCompletion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
req := createChatCompletionRequest(params, messages)
|
req := createChatCompletionRequest(params, messages)
|
||||||
jsonData, err := json.Marshal(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
httpReq, err := http.NewRequestWithContext(ctx, "POST", c.BaseURL+"/chat/completions", bytes.NewBuffer(jsonData))
|
resp, err := c.sendRequest(ctx, req)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := c.sendRequest(httpReq)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -273,17 +274,7 @@ func (c *OpenAIClient) CreateChatCompletionStream(
|
|||||||
req := createChatCompletionRequest(params, messages)
|
req := createChatCompletionRequest(params, messages)
|
||||||
req.Stream = true
|
req.Stream = true
|
||||||
|
|
||||||
jsonData, err := json.Marshal(req)
|
resp, err := c.sendRequest(ctx, req)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
httpReq, err := http.NewRequestWithContext(ctx, "POST", c.BaseURL+"/chat/completions", bytes.NewBuffer(jsonData))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := c.sendRequest(httpReq)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ func (c *Context) GetModelProvider(model string) (string, api.ChatCompletionProv
|
|||||||
BaseURL: url,
|
BaseURL: url,
|
||||||
}, nil
|
}, nil
|
||||||
case "openai":
|
case "openai":
|
||||||
url := "https://api.openai.com/v1"
|
url := "https://api.openai.com"
|
||||||
if p.BaseURL != nil {
|
if p.BaseURL != nil {
|
||||||
url = *p.BaseURL
|
url = *p.BaseURL
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user