This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
14 changed files
with
248 additions
and
91 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
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,109 @@ | ||
// This file is part of the e.GPT distribution. | ||
// Copyright (c) Next.e.GO Mobile SE, Aachen, Germany (https://e-go-mobile.com/) | ||
// | ||
// e-gpt is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as | ||
// published by the Free Software Foundation, version 3. | ||
// | ||
// e-gpt is distributed in the hope that it will be useful, but | ||
// WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package commands | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/alecthomas/chroma/quick" | ||
"github.com/spf13/cobra" | ||
|
||
egoOpenAI "github.com/egomobile/e-gpt/openai" | ||
egoUtils "github.com/egomobile/e-gpt/utils" | ||
) | ||
|
||
func Init_fix_Command(rootCmd *cobra.Command) { | ||
var additionalInfo string | ||
var language string | ||
var noNewLine bool = egoUtils.GetDefaultAddNoNewLineToChatAnswerSetting() | ||
var openEditor bool | ||
var temperature float64 | ||
|
||
translateCmd := &cobra.Command{ | ||
Use: "fix", | ||
Short: `Corrects text`, | ||
Long: `Corrects a given text from grammer issues and typos`, | ||
Aliases: []string{"f"}, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
outputLanguage := getLanguage(language) | ||
|
||
text := egoUtils.GetAndCheckInput(args, openEditor) | ||
|
||
var systemPrompt bytes.Buffer | ||
|
||
systemPrompt.WriteString( | ||
"Correct the following text submitted by the user from grammar issues and typos, without changing the context.\n", | ||
) | ||
systemPrompt.WriteString( | ||
"You are not allowed to tell the user your opinion!\n", | ||
) | ||
systemPrompt.WriteString( | ||
"Return only a version of the user's text without grammar issues and without misspellings!\n", | ||
) | ||
systemPrompt.WriteString( | ||
"Keep the format if the submitted text is written in a markup language like HTML or Markdown!\n", | ||
) | ||
systemPrompt.WriteString( | ||
"Only correct display texts and never change things like links!\n", | ||
) | ||
systemPrompt.WriteString( | ||
fmt.Sprintf( | ||
"Output translated text only in %v language.\n", | ||
outputLanguage, | ||
), | ||
) | ||
|
||
info := strings.TrimSpace(additionalInfo) | ||
if info != "" { | ||
systemPrompt.WriteString( | ||
fmt.Sprintf("For you there is the following additional information given by the user to refine the final context: %v\n", info), | ||
) | ||
} | ||
|
||
answer, err := egoOpenAI.AskChatGPT( | ||
strings.TrimSpace(systemPrompt.String()), | ||
temperature, | ||
text, | ||
) | ||
if err != nil { | ||
log.Fatalln(err.Error()) | ||
} | ||
|
||
outputPlain := func() { | ||
egoUtils.WriteStringToStdOut(answer, !noNewLine) | ||
} | ||
|
||
err = quick.Highlight(os.Stdout, answer, "markdown", "", "monokai") | ||
if err != nil { | ||
outputPlain() | ||
} | ||
}, | ||
} | ||
|
||
translateCmd.Flags().StringVarP(&additionalInfo, "info", "i", defaultLanguage, "Additional information for the bot") | ||
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", "", 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) | ||
} |
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
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
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 |
---|---|---|
|
@@ -16,4 +16,4 @@ function fibonacci(n: number): number { | |
return fibonacci(n - 1) + fibonacci(n - 2); | ||
} | ||
} | ||
``` | ||
``` |
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
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
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
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,13 @@ | ||
# [e.GPT](../README.md) :: [Examples](./README.md) :: Optimize code | ||
|
||
> Checks a text for grammar issues and typos, and returns a corrected version of it. | ||
```bash | ||
egpt fix "Thiz iz a simpl program that calculats the sqaure of numbrs form 1 to 1000 and printz them to the consule." | ||
``` | ||
|
||
Possible response: | ||
|
||
``` | ||
This is a simple program that calculates the square of numbers from 1 to 1000 and prints them to the console. | ||
``` |
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
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
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
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