Add api client code
This commit is contained in:
43
engines.go
Normal file
43
engines.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package gogpt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Engine struct {
|
||||
ID string `json:"id"`
|
||||
Object string `json:"object"`
|
||||
Owner string `json:"owner"`
|
||||
Ready bool `json:"ready"`
|
||||
}
|
||||
|
||||
type EnginesList struct {
|
||||
Engines []Engine `json:"data"`
|
||||
}
|
||||
|
||||
// ListEngines Lists the currently available engines, and provides basic information about each option such as the owner and availability.
|
||||
func (c *Client) ListEngines(ctx context.Context) (engines EnginesList, err error) {
|
||||
req, err := http.NewRequest("GET", c.fullURL("/engines"), nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req = req.WithContext(ctx)
|
||||
err = c.sendRequest(req, &engines)
|
||||
return
|
||||
}
|
||||
|
||||
// GetEngine Retrieves an engine instance, providing basic information about the engine such as the owner and availability.
|
||||
func (c *Client) GetEngine(ctx context.Context, engineID string) (engine Engine, err error) {
|
||||
urlSuffix := fmt.Sprintf("/engines/%s", engineID)
|
||||
req, err := http.NewRequest("GET", c.fullURL(urlSuffix), nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req = req.WithContext(ctx)
|
||||
err = c.sendRequest(req, &engine)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user