-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,134 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//Package gpt3 provides access to the GPT3 completions Api | ||
//along with new beta APIs for classification, enhanced search, and question answering. | ||
// | ||
//The underlying structure is defined along a request / response interface pattern with a | ||
//singular call to the client. | ||
//The request is initialised as per required parameters an example being: | ||
// | ||
// req := gpt3.CompletionRequest{ | ||
// Prompt: string(query), | ||
// MaxTokens: 60, | ||
// TopP: 1, | ||
// Temperature: 0.3, | ||
// FrequencyPenalty: 0.5, | ||
// PresencePenalty: 0, | ||
// Stop: []string{"You:"}, | ||
// } | ||
// | ||
//The content filter endpoint is used to validate a prompt in order to safeguard responses ushered back to the enduser. | ||
//The request object should always have the following parameters: | ||
// | ||
// reformattedPrompt := fmt.Sprintf("<|endoftext|>[%s]\n--\nLabel:", string(query)) | ||
// | ||
// req := gpt3.ContentFilterRequest{ | ||
// Prompt: reformattedPrompt, | ||
// MaxTokens: 1, | ||
// TopP: 0, | ||
// Temperature: 0, | ||
// Logprobs: 10, | ||
// } | ||
// | ||
// The Response is the same format as that of the Completions request with the following entries: | ||
// | ||
// 0 => text is safe | ||
// 1 => This text is sensitive. This means that the text could be talking about a sensitive topic, something political, | ||
// religious, or talking about a protected class such as race or nationality. | ||
// 2 => This text is unsafe. This means that the text contains profane language, prejudiced or hateful language, | ||
// something that could be NSFW, or text that portrays certain groups/people in a harmful manner. | ||
// | ||
// Code Generation: | ||
// | ||
// Added to the completions API are the codex engines for code generation. | ||
// The Codex model series is a descendant of our base GPT-3 series that’s been trained on both | ||
// natural language and billions of lines of code. | ||
|
||
package gpt3_sdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package internal | ||
|
||
import ( | ||
"log" | ||
"os" | ||
) | ||
|
||
const ( | ||
baseUrl = "OPENAI_API_BASE_URL" | ||
defaultVersion = "OPENAI_API_VERSION" | ||
apiKeyName = "OPENAI_API_KEY" | ||
) | ||
|
||
var Config config | ||
|
||
type config struct { | ||
Gpt3BaseUrl string | ||
Gpt3ApiVersion string | ||
Gpt3ApiKey string | ||
} | ||
|
||
func init() { | ||
Config.Gpt3BaseUrl = os.Getenv(baseUrl) | ||
if Config.Gpt3BaseUrl == "" { | ||
Config.Gpt3BaseUrl = "https://api.openai.com" | ||
} | ||
|
||
Config.Gpt3ApiVersion = os.Getenv(defaultVersion) | ||
if Config.Gpt3ApiVersion == "" { | ||
Config.Gpt3ApiVersion = "v1" | ||
} | ||
|
||
Config.Gpt3ApiKey = os.Getenv(apiKeyName) | ||
if Config.Gpt3ApiKey == "" { | ||
log.Panicf("Api key required. Please ensure env variable %s is set.", apiKeyName) | ||
} | ||
} |
Oops, something went wrong.