From 8b486947eea787bce819f9aa2e65786e9c47b6b3 Mon Sep 17 00:00:00 2001 From: 0x9ef <0x9ef@tutanota.com> Date: Wed, 4 Jan 2023 20:49:46 +0200 Subject: [PATCH] chore: add more information to README --- readme.md | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/readme.md b/readme.md index ba248e4..0f115ce 100644 --- a/readme.md +++ b/readme.md @@ -6,23 +6,53 @@ An Golang native implementation to easily interacting with OpenAI API. You can use environment variable to store API secret key ``` -export OPENAPI_KEY=YOUR_KEY +export OPENAI_KEY=[YOUR_KEY] ``` To initialize engine, use this: ```go -e := openai.New(os.Getenv("OPENAPI_KEY")) +e := openai.New(os.Getenv("OPENAI_KEY")) ``` +### Tips + +#### Model +If you want to use the most powerful model to generate text outputs, ensure that you are using "text-davinci-003". This model is defined as constant `openai.ModelTextDavinci003`. + +#### Text edition +You can use the bundle Completion+Edit to regenerate the response based on the last context. +```go +e := openai.New(os.Getenv("OPENAI_KEY")) +ctx := context.Background() +completionResp, err := e.Completion(ctx, &openai.CompletionOptions{ + // Choose model, you can see list of available models in models.go file + Model: openai.ModelTextDavinci001, + // Number of completion tokens to generate response. By default - 1024 + MaxTokens: 1200, + // Text to completion + Prompt: []string{"Write a little bit of Wikipedia. What is that?"}, +}) + +editResp, err := e.Edit(ctx, &EditOptions{ + Model: ModelTextDavinci001, + Input: completionResp.Choices[0], + Instruction: "Please rewrite a bit more and add more information about Wikipedia in different aspects. Please build based on that for 4 topics", +}) +``` + ### Text completion example -Given a prompt, the model will return one or more predicted completions. +Given a prompt, the model will return one or more predicted completions. + +**Note**: the default number of completion tokens is 1024, if you want to increase or decrease this limit, you should change `MaxTokens` parameter. ```go -e := openai.New(os.Getenv("OPENAPI_KEY")) +e := openai.New(os.Getenv("OPENAI_KEY")) r, err := e.Completion(context.Background(), &openai.CompletionOptions{ - // Choose model, you can see list of available models in models.go file + // Choose model, you can see list of available models in models.go file Model: openai.ModelTextDavinci001, - // Text to completion + // Number of completion tokens to generate response. By default - 1024 + MaxTokens: 1200, + // Text to completion Prompt: []string{"Write a little bit of Wikipedia. What is that?"}, }) ``` @@ -70,7 +100,7 @@ import ( ) func main() { - e := openai.New(os.Getenv("OPENAPI_KEY")) + e := openai.New(os.Getenv("OPENAI_KEY")) r, err := e.Completion(context.Background(), &openai.CompletionOptions{ // Choose model, you can see list of available models in models.go file Model: openai.ModelTextDavinci001, @@ -93,7 +123,7 @@ func main() { Lists the currently available models, and provides basic information about each one such as the owner and availability. ```go -e := openai.New(os.Getenv("OPENAPI_KEY")) +e := openai.New(os.Getenv("OPENAI_KEY")) r, err := e.ListModels(context.Background()) if err != nil { log.Fatal(err) @@ -127,12 +157,12 @@ You will get the next output: ... ] } -``` +``` To retrieve information about specified model instead of all models, you can do this: ```go -e := openai.New(os.Getenv("OPENAPI_KEY")) +e := openai.New(os.Getenv("OPENAI_KEY")) r, err := e.RetrieveModel(context.Background(), &openai.RetrieveModelOptions{ ID: openai.ModelDavinci, })