-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add fakeai provider Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> * chore: add fakeai provider Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> * fix: name of openai provider Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> * fix: renamed fakeai backend to noopai Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> * fix: renamed fakeai backend to noopai Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> --------- Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
- Loading branch information
1 parent
1069f0c
commit e449cb6
Showing
3 changed files
with
72 additions
and
10 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,55 @@ | ||
package ai | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"fmt" | ||
"github.com/fatih/color" | ||
"github.com/spf13/viper" | ||
"strings" | ||
) | ||
|
||
type NoOpAIClient struct { | ||
client string | ||
language string | ||
model string | ||
} | ||
|
||
func (c *NoOpAIClient) Configure(token string, model string, language string) error { | ||
c.language = language | ||
c.client = fmt.Sprintf("I am a noop client with the token %s ", token) | ||
c.model = model | ||
return nil | ||
} | ||
|
||
func (c *NoOpAIClient) GetCompletion(ctx context.Context, prompt string) (string, error) { | ||
// Create a completion request | ||
response := "I am a noop response to the prompt " + prompt | ||
return response, nil | ||
} | ||
|
||
func (a *NoOpAIClient) Parse(ctx context.Context, prompt []string, nocache bool) (string, error) { | ||
// parse the text with the AI backend | ||
inputKey := strings.Join(prompt, " ") | ||
// Check for cached data | ||
sEnc := base64.StdEncoding.EncodeToString([]byte(inputKey)) | ||
|
||
response, err := a.GetCompletion(ctx, inputKey) | ||
if err != nil { | ||
color.Red("error getting completion: %v", err) | ||
return "", err | ||
} | ||
|
||
if !viper.IsSet(sEnc) { | ||
viper.Set(sEnc, base64.StdEncoding.EncodeToString([]byte(response))) | ||
if err := viper.WriteConfig(); err != nil { | ||
color.Red("error writing config: %v", err) | ||
return "", nil | ||
} | ||
} | ||
return response, nil | ||
} | ||
|
||
func (a *NoOpAIClient) GetName() string { | ||
return "noopai" | ||
} |
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