Skip to content

Commit

Permalink
feat(search): add explicit query flag
Browse files Browse the repository at this point in the history
  • Loading branch information
japelsin committed Mar 2, 2024
1 parent 08d1bdf commit 6d3f428
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ Usage:
pplx search [flags]
Flags:
-f, --frequency_penalty int Penalize token frequency
-l, --max_tokens int Token limit per request (default 1000)
-m, --model string Model to use (default "sonar-small-online")
-p, --presence_penalty int Penalize token presence [-2, 2]
-t, --temperature int Response randomness [0, 2]
-K, --top_k int Number of tokens to sample from [0, 2048]
-P, --top_p int Probability cutoff for token selection [0, 1]
-f, --frequency_penalty float Token frequency penalty [0, 1.0]
-l, --max_tokens int Token limit per request (default 1000)
-m, --model string Model to use (default "sonar-small-online")
-p, --presence_penalty float Token presence penalty [-2.0, 2.0]
-q, --query string Your query
-t, --temperature float Response randomness [0, 2.0]
-K, --top_k int Number of tokens to sample from [0, 2048]
-P, --top_p float Probability cutoff for token selection [0, 1.0]
```

The API reference can be found [here](https://docs.perplexity.ai/reference/post_chat_completions).
Expand Down
13 changes: 10 additions & 3 deletions cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type perplexityResult struct {
} `json:"choices"`
}

var query = ""

var searchCmd = &cobra.Command{
Use: "search",
Short: "Search using Perplexity",
Expand All @@ -54,8 +56,12 @@ var searchCmd = &cobra.Command{
// Parse argument & flags
// ****************************************************

query, err := utils.Prompt("Query")
cobra.CheckErr(err)
if query == "" {
promptQuery, err := utils.Prompt("Query")
cobra.CheckErr(err)

query = promptQuery
}

payload := perplexityPayload{}

Expand Down Expand Up @@ -127,12 +133,13 @@ func init() {
rootCmd.AddCommand(searchCmd)

searchCmd.Flags().IntP(utils.MaxTokensKey, "l", 1000, "Token limit per request")
searchCmd.Flags().Float64P(utils.TemperatureKey, "t", 0, "Response randomness [0, 2.0]")
searchCmd.Flags().Float64P(utils.TemperatureKey, "t", 0.7, "Response randomness [0, 2.0]")
searchCmd.Flags().IntP(utils.TopKKey, "K", 0, "Number of tokens to sample from [0, 2048]")
searchCmd.Flags().Float64P(utils.TopPKey, "P", 0, "Probability cutoff for token selection [0, 1.0]")
searchCmd.Flags().Float64P(utils.FrequencyPenaltyKey, "f", 0, "Token frequency penalty [0, 1.0]")
searchCmd.Flags().Float64P(utils.PresencePenaltyKey, "p", 0, "Token presence penalty [-2.0, 2.0]")
searchCmd.Flags().StringP(utils.ModelKey, "m", "sonar-small-online", "Model to use")
searchCmd.Flags().StringVarP(&query, utils.QueryKey, "q", "", "Your query")

viper.BindPFlag(utils.MaxTokensKey, searchCmd.Flags().Lookup(utils.MaxTokensKey))
viper.BindPFlag(utils.TemperatureKey, searchCmd.Flags().Lookup(utils.TemperatureKey))
Expand Down
7 changes: 4 additions & 3 deletions utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package utils

const (
ApiKeyKey = "api_key"
FrequencyPenaltyKey = "frequency_penalty"
MaxTokensKey = "max_tokens"
ModelKey = "model"
PresencePenaltyKey = "presence_penalty"
QueryKey = "query"
TemperatureKey = "temperature"
TopPKey = "top_p"
TopKKey = "top_k"
PresencePenaltyKey = "presence_penalty"
FrequencyPenaltyKey = "frequency_penalty"
TopPKey = "top_p"
)

var AvailableModels = []string{"sonar-small-chat", "sonar-small-online", "sonar-medium-chat", "sonar-medium-online", "llama-2-70b-chat", "codellama-34b-instruct", "codellama-70b-instruct", "mistral-7b-instruct", "mixtral-8x7b-instruct"}

0 comments on commit 6d3f428

Please sign in to comment.