From e6b0494d9047ca03eb48b60c8bac6a57f238c2cb Mon Sep 17 00:00:00 2001 From: sauceman40 Date: Wed, 1 Sep 2021 03:07:53 -0700 Subject: [PATCH] Add CreateCompletionWithFineTunedModel function (#10) * add fine-tuned completion function * add explanatory comment --- completion.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/completion.go b/completion.go index b688896..a8a7de1 100644 --- a/completion.go +++ b/completion.go @@ -73,3 +73,24 @@ func (c *Client) CreateCompletion(ctx context.Context, engineID string, request err = c.sendRequest(req, &response) return } + +// CreateCompletionWithFineTunedModel - API call to create a completion with a fine tuned model +// See https://beta.openai.com/docs/guides/fine-tuning/use-a-fine-tuned-model +// In this case, the model is specified in the CompletionRequest object. +func (c *Client) CreateCompletionWithFineTunedModel(ctx context.Context, request CompletionRequest) (response CompletionResponse, err error) { + var reqBytes []byte + reqBytes, err = json.Marshal(request) + if err != nil { + return + } + + urlSuffix := "/completions" + req, err := http.NewRequest("POST", c.fullURL(urlSuffix), bytes.NewBuffer(reqBytes)) + if err != nil { + return + } + + req = req.WithContext(ctx) + err = c.sendRequest(req, &response) + return +}