Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
CHAT_ANSWER_NO_NEW_LINE env var
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Aug 22, 2023
1 parent 1913c81 commit 9a94795
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log (e.GPT)

## 0.10.0

- add optional check of `CHAT_ANSWER_NO_NEW_LINE` environment variable to setup a default behavior

## 0.9.0

- new line string is added to answers automatically now by default ... added `no-new-line` flag to setup legacy behavior
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,18 @@ Keep in mind: The final prompt will be trimmed (start + end).

## Environment variables [<a href="#toc">↑</a>]

| Name | Description | Default value | Example |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | --------------------------------------------------------------------- |
| `CHAT_API_CLIENT_ID` | You must setup this, if you want to use a proxy API. | | `a816037f-cb72-4f67-8855-71be067637fc` |
| `CHAT_API_CLIENT_SECRET` | If you use a proxy API via [OAuth 2](https://oauth.net/2/). This requies `OAUTH2_GET_TOKEN_URL` to be set. | | `a816037f-cb72-4f67-8855-71be067637fc` |
| `CHAT_API_KEY` | If you use a proxy API with API key, submitted via `x-api-key` header. | | `ZIREUIcc` |
| `CHAT_API_TEMPERATURE` | What default [sampling temperature](https://platform.openai.com/docs/api-reference/chat/create#chat/create-temperature) to use, between 0 and 2. | `0.7` | `0.5` |
| `CHAT_API_URL` | Sets up the base URL for a proxy API usage. | | `https://api.example.com/v1/chat/completions` |
| `DATABASE_URL` | Required for [sql command](#sql-) execution. | | `postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full` |
| `EGO_EDITOR` | The custom text editor to use. | Windows: `notepad.exe`, Linux/Unix: `vi` | `nano` |
| `OAUTH2_GET_TOKEN_URL` | Base URL for [get OAuth 2 access token](https://oauth.net/2/access-tokens/). | | `https://api.example.com/auth/v1/oauth2/token` |
| `OPENAI_API_KEY` | If you want to use [OpenAI API]() driectly, you have to setup [the API key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key) here. | | |
| Name | Description | Default value | Example |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | --------------------------------------------------------------------- |
| `CHAT_API_CLIENT_ID` | You must setup this, if you want to use a proxy API. | | `a816037f-cb72-4f67-8855-71be067637fc` |
| `CHAT_API_CLIENT_SECRET` | If you use a proxy API via [OAuth 2](https://oauth.net/2/). This requies `OAUTH2_GET_TOKEN_URL` to be set. | | `a816037f-cb72-4f67-8855-71be067637fc` |
| `CHAT_API_KEY` | If you use a proxy API with API key, submitted via `x-api-key` header. | | `ZIREUIcc` |
| `CHAT_API_TEMPERATURE` | What default [sampling temperature](https://platform.openai.com/docs/api-reference/chat/create#chat/create-temperature) to use, between 0 and 2. | `0.7` | `0.5` |
| `CHAT_API_URL` | Sets up the base URL for a proxy API usage. | | `https://api.example.com/v1/chat/completions` |
| `CHAT_ANSWER_NO_NEW_LINE` | Add no new line at the end of each chat message automatically. | `false` | `true` |
| `DATABASE_URL` | Required for [sql command](#sql-) execution. | | `postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full` |
| `EGO_EDITOR` | The custom text editor to use. | Windows: `notepad.exe`, Linux/Unix: `vi` | `nano` |
| `OAUTH2_GET_TOKEN_URL` | Base URL for [get OAuth 2 access token](https://oauth.net/2/access-tokens/). | | `https://api.example.com/auth/v1/oauth2/token` |
| `OPENAI_API_KEY` | If you want to use [OpenAI API]() driectly, you have to setup [the API key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key) here. | | |

## Examples [<a href="#toc">↑</a>]

Expand Down
6 changes: 3 additions & 3 deletions commands/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func Init_ask_Command(rootCmd *cobra.Command) {
var noAdditionalInfo bool
var noNewLine bool
var noNewLine bool = egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting()
var noSysInfo bool
var noTime bool
var openEditor bool
Expand Down Expand Up @@ -138,8 +138,8 @@ func Init_ask_Command(rootCmd *cobra.Command) {
askCmd.Flags().BoolVarP(&shouldOutputAsPlainText, "pt", "", false, "Output as plain text")
askCmd.Flags().BoolVarP(&openEditor, "editor", "e", false, "Open editor for input")
askCmd.Flags().Float64VarP(&temperature, "temperature", "t", getDefaultTemperature(), "Custom temperature between 0 and 2")
askCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", false, "Do not add new line at the end")
askCmd.Flags().BoolVarP(&noNewLine, "nnl", "", false, "Do not add new line at the end")
askCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")
askCmd.Flags().BoolVarP(&noNewLine, "nnl", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")

rootCmd.AddCommand(askCmd)
}
6 changes: 3 additions & 3 deletions commands/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func Init_code_Command(rootCmd *cobra.Command) {
var noNewLine bool
var noNewLine bool = egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting()
var openEditor bool
var temperature float64

Expand Down Expand Up @@ -72,8 +72,8 @@ If the user does not specify a programming language you have to use TypeScript f

codeCmd.Flags().BoolVarP(&openEditor, "editor", "e", false, "Open editor for input")
codeCmd.Flags().Float64VarP(&temperature, "temperature", "t", getDefaultTemperature(), "Custom temperature between 0 and 2")
codeCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", false, "Do not add new line at the end")
codeCmd.Flags().BoolVarP(&noNewLine, "nnl", "", false, "Do not add new line at the end")
codeCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")
codeCmd.Flags().BoolVarP(&noNewLine, "nnl", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")

rootCmd.AddCommand(codeCmd)
}
6 changes: 3 additions & 3 deletions commands/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func Init_describe_Command(rootCmd *cobra.Command) {
var noNewLine bool
var noNewLine bool = egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting()
var openEditor bool
var temperature float64

Expand Down Expand Up @@ -95,8 +95,8 @@ If you need to store any data, assume it will be stored in the chat.

describeCmd.Flags().BoolVarP(&openEditor, "editor", "e", false, "Open editor for input")
describeCmd.Flags().Float64VarP(&temperature, "temperature", "t", getDefaultTemperature(), "Custom temperature between 0 and 2")
describeCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", false, "Do not add new line at the end")
describeCmd.Flags().BoolVarP(&noNewLine, "nnl", "", false, "Do not add new line at the end")
describeCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")
describeCmd.Flags().BoolVarP(&noNewLine, "nnl", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")

rootCmd.AddCommand(describeCmd)
}
6 changes: 3 additions & 3 deletions commands/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func Init_explain_Command(rootCmd *cobra.Command) {
var language string
var noNewLine bool
var noNewLine bool = egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting()
var openEditor bool
var temperature float64

Expand Down Expand Up @@ -81,8 +81,8 @@ Ignore any potential risk of errors or confusion`,
explainCmd.Flags().StringVarP(&language, "language", "l", defaultProgrammingLanguage, "Custom programming language")
explainCmd.Flags().BoolVarP(&openEditor, "editor", "e", false, "Open editor for input")
explainCmd.Flags().Float64VarP(&temperature, "temperature", "t", getDefaultTemperature(), "Custom temperature between 0 and 2")
explainCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", false, "Do not add new line at the end")
explainCmd.Flags().BoolVarP(&noNewLine, "nnl", "", false, "Do not add new line at the end")
explainCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")
explainCmd.Flags().BoolVarP(&noNewLine, "nnl", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")

rootCmd.AddCommand(explainCmd)
}
6 changes: 3 additions & 3 deletions commands/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func Init_optimize_Command(rootCmd *cobra.Command) {
var language string
var noNewLine bool
var noNewLine bool = egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting()
var openEditor bool
var temperature float64

Expand Down Expand Up @@ -89,8 +89,8 @@ Ignore any potential risk of errors or confusion.%v`, "\n"),
optimizeCmd.Flags().StringVarP(&language, "language", "l", "", "Explicit programming language")
optimizeCmd.Flags().BoolVarP(&openEditor, "editor", "e", false, "Open editor for input")
optimizeCmd.Flags().Float64VarP(&temperature, "temperature", "t", getDefaultTemperature(), "Custom temperature between 0 and 2")
optimizeCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", false, "Do not add new line at the end")
optimizeCmd.Flags().BoolVarP(&noNewLine, "nnl", "", false, "Do not add new line at the end")
optimizeCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")
optimizeCmd.Flags().BoolVarP(&noNewLine, "nnl", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")

rootCmd.AddCommand(optimizeCmd)
}
6 changes: 3 additions & 3 deletions commands/summarize.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
func Init_summarize_Command(rootCmd *cobra.Command) {
var language string
var maxSize int32
var noNewLine bool
var noNewLine bool = egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting()
var openEditor bool
var temperature float64

Expand Down Expand Up @@ -90,8 +90,8 @@ func Init_summarize_Command(rootCmd *cobra.Command) {
summarizeCmd.Flags().Int32VarP(&maxSize, "ml", "", 1000, "Maximum number of characters")
summarizeCmd.Flags().BoolVarP(&openEditor, "editor", "e", false, "Open editor for input")
summarizeCmd.Flags().Float64VarP(&temperature, "temperature", "t", getDefaultTemperature(), "Custom temperature between 0 and 2")
summarizeCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", false, "Do not add new line at the end")
summarizeCmd.Flags().BoolVarP(&noNewLine, "nnl", "", false, "Do not add new line at the end")
summarizeCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")
summarizeCmd.Flags().BoolVarP(&noNewLine, "nnl", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")

rootCmd.AddCommand(summarizeCmd)
}
6 changes: 3 additions & 3 deletions commands/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func Init_translate_Command(rootCmd *cobra.Command) {
var language string
var noNewLine bool
var noNewLine bool = egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting()
var openEditor bool
var temperature float64

Expand Down Expand Up @@ -84,8 +84,8 @@ func Init_translate_Command(rootCmd *cobra.Command) {
translateCmd.Flags().StringVarP(&language, "language", "l", defaultLanguage, "Custom output language")
translateCmd.Flags().BoolVarP(&openEditor, "editor", "e", false, "Open editor for input")
translateCmd.Flags().Float64VarP(&temperature, "temperature", "t", getDefaultTemperature(), "Custom temperature between 0 and 2")
translateCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", false, "Do not add new line at the end")
translateCmd.Flags().BoolVarP(&noNewLine, "nnl", "", false, "Do not add new line at the end")
translateCmd.Flags().BoolVarP(&noNewLine, "no-new-line", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")
translateCmd.Flags().BoolVarP(&noNewLine, "nnl", "", egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting(), "Do not add new line at the end")

rootCmd.AddCommand(translateCmd)
}
22 changes: 22 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ func GetEnvFilePath() (string, error) {
return path.Join(homeDir, ".egpt/.env"), nil
}

// GetDefaultAddNoNewLineToChatAnswerSetting gets the default value for the setting, NOT adding
// a new line to each answer of a chat to STDOUT
func GetDefaultAddNoNewLineToChatAnswerSetting() bool {
return IsTruthy(os.Getenv("CHAT_ANSWER_NO_NEW_LINE"))
}

// GetInput function retrieves user input from the command-line arguments, standard input, or an editor
func GetInput(args []string, openEditor bool) (string, error) {
// first add arguments from CLI
Expand Down Expand Up @@ -426,6 +432,22 @@ func GetUISettingsFilePath() (string, error) {
return path.Join(homeDir, ".egpt/settings.ui.json"), nil
}

// IsTruthy checks if a string value is a "truthy" value like: "true", "t", "1", "y", "yes", "yeah", "✅", "👍"
func IsTruthy(val string) bool {
val = strings.TrimSpace(strings.ToLower(val))

truthyVals := make([]string, 0)
truthyVals = append(truthyVals, "true", "t", "1", "y", "yes", "yeah", "✅", "👍")

for _, item := range truthyVals {
if item == val {
return true
}
}

return false
}

// RemoveMarkdownCode removes the beginning and ending backticks from the given string.
func RemoveMarkdownCode(str string) string {
// remove beginning `
Expand Down

0 comments on commit 9a94795

Please sign in to comment.