-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update index.md (#764) * test(go): add live tests to go ollama plugin (#720) * test(go): add ollama live test * test(go): retrieve port info for test container * chore(go): refactor ollama plugin live test * test(go): remove docker from ollama live test * fix context array (#777) * Update to pnpm v9.7.1 (#786) --------- Co-authored-by: Peter Friese <peter@peterfriese.de> Co-authored-by: Jacob Cable <32874567+cabljac@users.noreply.github.com> Co-authored-by: ssbushi <66321939+ssbushi@users.noreply.github.com> Co-authored-by: Anthony Barone <tonybaroneee@gmail.com>
- Loading branch information
1 parent
0d3d51e
commit 516e6c1
Showing
7 changed files
with
97 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ollama_test | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"testing" | ||
|
||
"github.com/firebase/genkit/go/ai" | ||
ollamaPlugin "github.com/firebase/genkit/go/plugins/ollama" | ||
) | ||
|
||
var serverAddress = flag.String("server-address", "http://localhost:11434", "Ollama server address") | ||
var modelName = flag.String("model-name", "tinyllama", "model name") | ||
var testLive = flag.Bool("test-live", false, "run live tests") | ||
|
||
/* | ||
To run this test, you need to have the Ollama server running. You can set the server address using the OLLAMA_SERVER_ADDRESS environment variable. | ||
If the environment variable is not set, the test will default to http://localhost:11434 (the default address for the Ollama server). | ||
*/ | ||
func TestLive(t *testing.T) { | ||
|
||
if !*testLive { | ||
t.Skip("skipping go/plugins/ollama live test") | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
// Initialize the Ollama plugin | ||
err := ollamaPlugin.Init(ctx, &ollamaPlugin.Config{ | ||
ServerAddress: *serverAddress, | ||
}) | ||
if err != nil { | ||
t.Fatalf("failed to initialize Ollama plugin: %s", err) | ||
} | ||
|
||
// Define the model | ||
ollamaPlugin.DefineModel(ollamaPlugin.ModelDefinition{Name: *modelName}, nil) | ||
|
||
// Use the Ollama model | ||
m := ollamaPlugin.Model(*modelName) | ||
if m == nil { | ||
t.Fatalf(`failed to find model: %s`, *modelName) | ||
} | ||
|
||
// Generate a response from the model | ||
resp, err := m.Generate(ctx, | ||
ai.NewGenerateRequest( | ||
&ai.GenerationCommonConfig{Temperature: 1}, | ||
ai.NewUserTextMessage("I'm hungry, what should I eat?")), | ||
nil) | ||
if err != nil { | ||
t.Fatalf("failed to generate response: %s", err) | ||
} | ||
|
||
if resp == nil { | ||
t.Fatalf("response is nil") | ||
} | ||
|
||
// Get the text from the response | ||
text := resp.Text() | ||
// log.Println("Response:", text) | ||
|
||
// Assert that the response text is as expected | ||
if text == "" { | ||
t.Fatalf("expected non-empty response, got: %s", text) | ||
} | ||
} |
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