Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow alternate OpenAI API URL with --openaiurl #29

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Flags:
--model string model to be used for responses e.g., gpt-4 (default "gpt-4")
-n, --nick string bot's nickname on the irc server (default "soulshack")
--openaikey string openai api key
--openaiurl string alternative base url to use instead of openai
-p, --port int irc server port (default 6667)
--prompt string initial system prompt for the ai (default "respond in a short text:")
-s, --server string irc server address (default "localhost")
Expand Down
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func init() {
root.PersistentFlags().String("openaikey", "", "openai api key")
root.PersistentFlags().Int("maxtokens", 512, "maximum number of tokens to generate")
root.PersistentFlags().String("model", ai.GPT4, "model to be used for responses (e.g., gpt-4)")
root.PersistentFlags().String("openaiurl", "", "alternative base url to use instead of openai")

// timeouts and behavior
root.PersistentFlags().BoolP("addressed", "a", true, "require bot be addressed by nick for response")
Expand Down Expand Up @@ -87,7 +88,7 @@ func initConfig() {

func verifyConfig(v *vip.Viper) error {
for _, varName := range v.AllKeys() {
if varName == "admins" || varName == "saslnick" || varName == "saslpass" {
if varName == "admins" || varName == "openaiurl" || varName == "saslnick" || varName == "saslpass" {
continue
}
value := v.GetString(varName)
Expand Down
9 changes: 8 additions & 1 deletion soulshack.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ var root = &cobra.Command{

func run(r *cobra.Command, _ []string) {

aiClient := ai.NewClient(vip.GetString("openaikey"))
aiConfig := ai.DefaultConfig(vip.GetString("openaikey"))

if vip.GetString("openaiurl") != "" {
log.Println("using alternate OpenAI API URL:", vip.GetString("openaiurl"))
aiConfig.BaseURL = vip.GetString("openaiurl")
}

aiClient := ai.NewClientWithConfig(aiConfig)

if err := verifyConfig(vip.GetViper()); err != nil {
log.Fatal(err)
Expand Down