-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Moved vendors into their own directory + homogized their implementation
Showing
12 changed files
with
114 additions
and
104 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,60 @@ | ||
package openai | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/baalimago/clai/internal/models" | ||
"github.com/baalimago/clai/internal/text" | ||
"github.com/baalimago/clai/internal/tools" | ||
"github.com/baalimago/go_away_boilerplate/pkg/ancli" | ||
"github.com/baalimago/go_away_boilerplate/pkg/misc" | ||
) | ||
|
||
var defaultGpt = ChatGPT{ | ||
Model: "gpt-4-turbo-preview", | ||
Temperature: 1.0, | ||
TopP: 1.0, | ||
Url: ChatURL, | ||
} | ||
|
||
func loadQuerier(loadFrom, model string) (*ChatGPT, error) { | ||
apiKey := os.Getenv("OPENAI_API_KEY") | ||
if apiKey == "" { | ||
return nil, fmt.Errorf("environment variable 'OPENAI_API_KEY' not set") | ||
} | ||
defaultCpy := defaultGpt | ||
defaultCpy.Model = model | ||
defaultCpy.Url = ChatURL | ||
// Load config based on model, allowing for different configs for each model | ||
gptQuerier, err := tools.LoadConfigFromFile[ChatGPT](loadFrom, fmt.Sprintf("openai_gpt_%v.json", model), nil, &defaultCpy) | ||
if misc.Truthy(os.Getenv("DEBUG")) { | ||
ancli.PrintOK(fmt.Sprintf("ChatGPT config: %+v\n", gptQuerier)) | ||
} | ||
if err != nil { | ||
ancli.PrintWarn(fmt.Sprintf("failed to load config for model: %v, error: %v\n", model, err)) | ||
} | ||
gptQuerier.client = &http.Client{} | ||
gptQuerier.apiKey = apiKey | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to load config: %w", err) | ||
} | ||
return &gptQuerier, nil | ||
} | ||
|
||
// NewTextQuerier returns a new ChatGPT querier using the textconfigurations to load | ||
// the correct model. API key is fetched via environment variable | ||
func NewTextQuerier(conf text.Configurations) (models.ChatQuerier, error) { | ||
home, _ := os.UserConfigDir() | ||
querier, err := loadQuerier(home, conf.Model) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to load querier of model: %v, error: %w", conf.Model, err) | ||
} | ||
if misc.Truthy(os.Getenv("DEBUG")) { | ||
querier.debug = true | ||
} | ||
querier.chat = conf.InitialPrompt | ||
querier.Raw = conf.Raw | ||
return querier, nil | ||
} |
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
File renamed without changes.