-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
135 additions
and
60 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,21 @@ | ||
package config | ||
|
||
type ClientConfig struct { | ||
OllamaConfig OllamaConfig `json:"ollama"` | ||
} | ||
|
||
type OllamaConfig struct { | ||
Host string `json:"host"` | ||
Model string `json:"model"` | ||
Stream bool `json:"stream"` | ||
} | ||
|
||
func NewClientConfig() *ClientConfig { | ||
return &ClientConfig{ | ||
OllamaConfig: OllamaConfig{ | ||
Host: getEnvAsString("OLLAMA_HOST", "http://localhost:11434/"), | ||
Model: getEnvAsString("OLLAMA_MODEL", "llama3"), | ||
Stream: getEnvAsBool("OLLAMA_STREAM", true), | ||
}, | ||
} | ||
} |
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,34 @@ | ||
package config | ||
|
||
import "os" | ||
|
||
const EnvPrefix string = "GRIMOIRE_" | ||
|
||
type EnvError struct { | ||
Key string | ||
} | ||
|
||
func (e *EnvError) Error() string { | ||
return "environment variable not found: " + e.Key | ||
} | ||
|
||
func getEnvAsString(key, defaultValue string) string { | ||
if value, exists := os.LookupEnv(EnvPrefix + key); exists { | ||
return value | ||
} | ||
return defaultValue | ||
} | ||
|
||
func getEnvAsApiKey(key string) (string, error) { | ||
if value, exists := os.LookupEnv(EnvPrefix + key); exists { | ||
return value, nil | ||
} | ||
return "", &EnvError{key} | ||
} | ||
|
||
func getEnvAsBool(key string, defaultValue bool) bool { | ||
if value, exists := os.LookupEnv(EnvPrefix + key); exists { | ||
return value == "true" | ||
} | ||
return defaultValue | ||
} |
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,51 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestGetEnvAsString(t *testing.T) { | ||
os.Setenv("GRIMOIRE_TEST_STRING", "test_value") | ||
defer os.Unsetenv("GRIMOIRE_TEST_STRING") | ||
|
||
value := getEnvAsString("TEST_STRING", "default_value") | ||
if value != "test_value" { | ||
t.Errorf("Expected 'test_value', got '%s'", value) | ||
} | ||
|
||
value = getEnvAsString("NON_EXISTENT_KEY", "default_value") | ||
if value != "default_value" { | ||
t.Errorf("Expected 'default_value', got '%s'", value) | ||
} | ||
} | ||
|
||
func TestGetEnvAsApiKey(t *testing.T) { | ||
os.Setenv("GRIMOIRE_TEST_API_KEY", "api_key_value") | ||
defer os.Unsetenv("GRIMOIRE_TEST_API_KEY") | ||
|
||
value, err := getEnvAsApiKey("TEST_API_KEY") | ||
if err != nil || value != "api_key_value" { | ||
t.Errorf("Expected 'api_key_value', got '%s' with error '%v'", value, err) | ||
} | ||
|
||
value, err = getEnvAsApiKey("NON_EXISTENT_KEY") | ||
if err == nil || value != "" { | ||
t.Errorf("Expected error and empty value, got '%s' with error '%v'", value, err) | ||
} | ||
} | ||
|
||
func TestGetEnvAsBool(t *testing.T) { | ||
os.Setenv("GRIMOIRE_TEST_BOOL", "true") | ||
defer os.Unsetenv("GRIMOIRE_TEST_BOOL") | ||
|
||
value := getEnvAsBool("TEST_BOOL", false) | ||
if value != true { | ||
t.Errorf("Expected 'true', got '%v'", value) | ||
} | ||
|
||
value = getEnvAsBool("NON_EXISTENT_KEY", false) | ||
if value != false { | ||
t.Errorf("Expected 'false', got '%v'", value) | ||
} | ||
} |
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,6 @@ | ||
package interfaces | ||
|
||
type Generate interface { | ||
Generate(prompt string) (string, error) | ||
GenerateStream(prompt string) (<-chan string, <-chan error) | ||
} |
This file was deleted.
Oops, something went wrong.