Support Retrieve model API (#340) (#341)

* Support Retrieve model API (#340)

* Test for GetModel error cases. (#340)

* Reduce the cognitive complexity of TestClientReturnsRequestBuilderErrors (#340)
This commit is contained in:
渡邉祐一 / Yuichi Watanabe
2023-06-05 23:37:08 +09:00
committed by GitHub
parent 1394329e44
commit 6830e00406
3 changed files with 127 additions and 94 deletions

View File

@@ -2,6 +2,7 @@ package openai
import (
"context"
"fmt"
"net/http"
)
@@ -48,3 +49,16 @@ func (c *Client) ListModels(ctx context.Context) (models ModelsList, err error)
err = c.sendRequest(req, &models)
return
}
// GetModel Retrieves a model instance, providing basic information about
// the model such as the owner and permissioning.
func (c *Client) GetModel(ctx context.Context, modelID string) (model Model, err error) {
urlSuffix := fmt.Sprintf("/models/%s", modelID)
req, err := c.requestBuilder.Build(ctx, http.MethodGet, c.fullURL(urlSuffix), nil)
if err != nil {
return
}
err = c.sendRequest(req, &model)
return
}