Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sklinkert committed Jan 5, 2025
1 parent 4b39887 commit 5117dcf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
6 changes: 3 additions & 3 deletions tools/perplexity/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// }
//
// // Create a new Perplexity instance
// perpl, err := perplexity.NewPerplexity(
// perpl, err := perplexity.New(
// perplexity.WithModel(perplexity.ModelLlamaSonarSmall),
// perplexity.WithAPIKey("your-api-key"), // Optional: defaults to PERPLEXITY_API_KEY env var
// )
Expand All @@ -30,11 +30,11 @@
// }
//
// // Create and use the agent
// agent := agents.NewOneShotAgent(llm,
// toolAgent := agents.NewOneShotAgent(llm,
// agentTools,
// agents.WithMaxIterations(2),
// )
// executor := agents.NewExecutor(agent)
// executor := agents.NewExecutor(toolAgent)
//
// answer, err := chains.Run(context.Background(), executor, "your question here")
package perplexity
51 changes: 24 additions & 27 deletions tools/perplexity/perplexity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,46 @@ import (
)

func TestNew(t *testing.T) {
t.Parallel()

tests := []struct {
name string
setup func(*testing.T) []Option
apiKey string
opts []Option
wantErr bool
}{
{
name: "no api key",
setup: func(t *testing.T) []Option {
t.Setenv("PERPLEXITY_API_KEY", "")
return nil
},
name: "no api key",
apiKey: "",
wantErr: true,
},
{
name: "with env api key",
setup: func(t *testing.T) []Option {
t.Setenv("PERPLEXITY_API_KEY", "test-key")
return nil
},
name: "with env api key",
apiKey: "test-key",
wantErr: false,
},
{
name: "with option api key",
setup: func(t *testing.T) []Option {
t.Setenv("PERPLEXITY_API_KEY", "")
return []Option{WithAPIKey("test-key")}
},
name: "with option api key",
apiKey: "",
opts: []Option{WithAPIKey("test-key")},
wantErr: false,
},
{
name: "with custom model",
setup: func(t *testing.T) []Option {
t.Setenv("PERPLEXITY_API_KEY", "test-key")
return []Option{WithModel(ModelLlamaSonarLarge)}
},
name: "with custom model",
apiKey: "test-key",
opts: []Option{WithModel(ModelLlamaSonarLarge)},
wantErr: false,
},
}

for _, tt := range tests {
tt := tt
tt := tt // capture range variable

Check failure on line 46 in tools/perplexity/perplexity_test.go

View workflow job for this annotation

GitHub Actions / Lint

The copy of the 'for' variable "tt" can be deleted (Go 1.22+) (copyloopvar)
t.Run(tt.name, func(t *testing.T) {
opts := tt.setup(t)

tool, err := New(opts...)
t.Parallel()

t.Setenv("PERPLEXITY_API_KEY", tt.apiKey)

tool, err := New(tt.opts...)
if tt.wantErr {
assert.Error(t, err)
assert.Nil(t, tool)
Expand All @@ -67,15 +62,17 @@ func TestNew(t *testing.T) {
}

func TestTool_Integration(t *testing.T) {
if os.Getenv("PERPLEXITY_API_KEY") == "" {
t.Parallel()

apiKey := os.Getenv("PERPLEXITY_API_KEY")
if apiKey == "" {
t.Skip("PERPLEXITY_API_KEY not set")
}

tool, err := New()
require.NoError(t, err)
require.NotNil(t, tool)

// Test Name and Description
assert.Equal(t, "PerplexityAI", tool.Name())
assert.NotEmpty(t, tool.Description())

Expand Down

0 comments on commit 5117dcf

Please sign in to comment.