Skip to content
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 cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&global.Verbose, "verbose", "v", false, "verbose error output (with stack trace) (optional)")
rootCmd.PersistentFlags().StringVarP(&global.VoiceflowAPIKey, "voiceflow-api-key", "x", "", "Voiceflow API Key (optional)")
rootCmd.PersistentFlags().StringVarP(&global.OpenAIAPIKey, "open-api-key", "z", "", "Open API Key (optional)")
rootCmd.PersistentFlags().StringVar(&global.OpenAIBaseURL, "openai-base-url", "", "OpenAI API base URL override, e.g. https://eu.api.openai.com/v1 (optional)")
rootCmd.PersistentFlags().StringVarP(&global.VoiceflowSubdomain, "voiceflow-subdomain", "b", "", "Voiceflow Base URL (optional). Default: empty")
rootCmd.PersistentFlags().BoolVarP(&global.SkipUpdate, "skip-update-check", "u", false, "Skip the check for updates check run before every command (optional)")
rootCmd.PersistentFlags().StringVarP(&global.Output, "output-format", "o", "text", "Output Format. Options: text, json. Default: text (optional)")
Expand Down
1 change: 1 addition & 0 deletions cmd/test/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var executeCmd = &cobra.Command{
suite := args[0]
voiceflow.SetVoiceflowAPIKey()
openai.SetOpenAIAPIKey()
openai.SetOpenAIBaseURL()
if err := test.ExecuteSuite(suite); err != nil {
global.Log.Errorf("%s", err.Error())
os.Exit(1)
Expand Down
17 changes: 16 additions & 1 deletion docs/docs/overview/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,19 @@ The base URL for the Voiceflow API is `https://<api>.<subdomain>.voiceflow.com`.

## Open AI PI Key
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Typo in section heading: "Open AI PI Key" → "OpenAI API Key".

Pre-existing typo, but worth fixing since you're already editing this section.

📝 Proposed fix
-## Open AI PI Key
+## OpenAI API Key
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Open AI PI Key
## OpenAI API Key
🤖 Prompt for AI Agents
In `@docs/docs/overview/authentication.md` at line 13, Fix the typo in the
markdown heading by replacing the incorrect heading text "## Open AI PI Key"
with the corrected "## OpenAI API Key" so the section title reads properly;
locate the heading string "## Open AI PI Key" in the
docs/overview/authentication.md content and update it to "## OpenAI API Key".


`voiceflow-cli` uses Open AI APIs. To interact with Open AI you will need an API Key. You can get your API Key in your Open AI account. You can pass the API Key to the CLI using the `--openai-api-key` flag or by setting the `OPENAI_API_KEY` environment variable. `voiceflow-cli` also works with `.env` files. You can create a `.env` file in the root of your project and add the `OPENAI_API_KEY` variable to it.
`voiceflow-cli` uses Open AI APIs. To interact with Open AI you will need an API Key. You can get your API Key in your Open AI account. You can pass the API Key to the CLI using the `--openai-api-key` flag or by setting the `OPENAI_API_KEY` environment variable. `voiceflow-cli` also works with `.env` files. You can create a `.env` file in the root of your project and add the `OPENAI_API_KEY` variable to it.

## OpenAI Base URL (optional)

If you need to target a different OpenAI endpoint (for example EU data residency), you can override the base URL by using:

- CLI flag: `--openai-base-url`
- Environment variable: `OPENAI_BASE_URL`

Example:

```sh
voiceflow test execute evals --openai-base-url https://eu.api.openai.com/v1
```

If not provided, `voiceflow-cli` defaults to `https://api.openai.com/v1`.
1 change: 1 addition & 0 deletions internal/global/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Log logrus.Logger

var VoiceflowAPIKey string
var OpenAIAPIKey string
var OpenAIBaseURL string
var VoiceflowSubdomain string
var VersionString string
var Output string
Expand Down
19 changes: 19 additions & 0 deletions internal/openai/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package openai

import (
"os"
"strings"

"github.com/xavidop/voiceflow-cli/internal/global"
)
Expand All @@ -12,3 +13,21 @@ func SetOpenAIAPIKey() {
global.OpenAIAPIKey = os.Getenv("OPENAI_API_KEY")
}
}

func SetOpenAIBaseURL() {
if global.OpenAIBaseURL == "" {
global.OpenAIBaseURL = os.Getenv("OPENAI_BASE_URL")
}

// Keep current behavior as default while allowing region-specific overrides.
if global.OpenAIBaseURL == "" {
global.OpenAIBaseURL = "https://api.openai.com/v1"
}

global.OpenAIBaseURL = strings.TrimRight(global.OpenAIBaseURL, "/")
}

func GetChatCompletionsURL() string {
SetOpenAIBaseURL()
return global.OpenAIBaseURL + "/chat/completions"
}
3 changes: 2 additions & 1 deletion pkg/openai/similarity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"

"github.com/xavidop/voiceflow-cli/internal/global"
openaiauth "github.com/xavidop/voiceflow-cli/internal/openai"
"github.com/xavidop/voiceflow-cli/internal/types/tests"
"github.com/xavidop/voiceflow-cli/internal/utils"
)
Expand All @@ -18,7 +19,7 @@ func OpenAICheckSimilarity(message string, s []string, similarityConfig tests.Si
}

// OpenAI API endpoint
apiURL := "https://api.openai.com/v1/chat/completions"
apiURL := openaiauth.GetChatCompletionsURL()

// Prepare the prompt for similarity comparison
prompt := fmt.Sprintf(
Expand Down
3 changes: 2 additions & 1 deletion pkg/test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/xavidop/voiceflow-cli/internal/global"
openaiauth "github.com/xavidop/voiceflow-cli/internal/openai"
"github.com/xavidop/voiceflow-cli/internal/types/tests"
"github.com/xavidop/voiceflow-cli/internal/types/voiceflow/interact"
"github.com/xavidop/voiceflow-cli/internal/utils"
Expand Down Expand Up @@ -169,7 +170,7 @@ Has the goal been achieved? Respond with only "YES" or "NO".`, goal, conversatio

// CallOpenAI makes a request to the OpenAI API
func (br *BaseRunner) CallOpenAI(messages []ChatMessage) (string, error) {
apiURL := "https://api.openai.com/v1/chat/completions"
apiURL := openaiauth.GetChatCompletionsURL()

// Set default values
model := "gpt-4o"
Expand Down
Loading