diff --git a/README.md b/README.md index 67ab9d2e..56ec04c0 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Zep enhances your AI agent's knowledge through continuous learning from user int 2. Zep intelligently integrates new information into the user's Knowledge Graph, updating existing context as needed. 3. Retrieve relevant facts from Zep for subsequent interactions or events. -Zep's temporal Knowledge Graph maintains contextual information about facts, enabling reasoning about state changes and providing data provenance insights. Each fact includes valid_at and invalid_at dates, allowing agents to track changes in user preferences, traits, or environment. +Zep's temporal Knowledge Graph maintains contextual information about facts, enabling reasoning about state changes and providing data provenance insights. Each fact includes `valid_at` and `invalid_at` dates, allowing agents to track changes in user preferences, traits, or environment. ### Zep is fast @@ -66,8 +66,8 @@ Please see the [Zep Quick Start Guide](https://help.getzep.com/ce/quickstart) fo ./zep up ``` > [!NOTE] -> Make sure to set the `secret` value in the `zep.yaml` configuration file. -> +> Make sure to set the `secret` value in the `zep.yaml` configuration file. +> > Additionally, make sure that you expose an `OPENAI_API_KEY` environment variable either in a local .env file or by running > ```bash > export OPENAI_API_KEY=your_openai_api_key diff --git a/docker-compose.ce.yaml b/docker-compose.ce.yaml index 809d98ec..5f94ac75 100644 --- a/docker-compose.ce.yaml +++ b/docker-compose.ce.yaml @@ -89,4 +89,4 @@ volumes: zep-db: networks: zep-network: - driver: bridge + driver: bridge \ No newline at end of file diff --git a/src/lib/config/env_template.go b/src/lib/config/env_template.go new file mode 100644 index 00000000..e6f9c619 --- /dev/null +++ b/src/lib/config/env_template.go @@ -0,0 +1,39 @@ +package config + +import ( + "fmt" + "os" + "strings" + "text/template" +) + +func parseConfigTemplate(data []byte) ([]byte, error) { //nolint:unused // this is only called in CE + var missingVars []string + + tmpl, err := template.New("config").Funcs(template.FuncMap{ + "Env": func(key string) string { + val := os.Getenv(key) + if val == "" { + missingVars = append(missingVars, key) + } + + return val + }, + }).Parse(string(data)) + if err != nil { + return nil, err + } + + var result strings.Builder + + err = tmpl.Execute(&result, nil) + if err != nil { + return nil, err + } + + if len(missingVars) > 0 { + return nil, fmt.Errorf("missing environmentvariables: %s", strings.Join(missingVars, ", ")) + } + + return []byte(result.String()), nil +} diff --git a/src/lib/config/load_ce.go b/src/lib/config/load_ce.go index 6cd3734a..3952d455 100644 --- a/src/lib/config/load_ce.go +++ b/src/lib/config/load_ce.go @@ -27,6 +27,11 @@ func Load() { panic(fmt.Errorf("config file could not be read: %w", err)) } + data, err = parseConfigTemplate(data) + if err != nil { + panic(fmt.Errorf("error processing config file: %w", err)) + } + config := defaultConfig if err := yaml.Unmarshal(data, &config); err != nil { panic(fmt.Errorf("config file contains invalid yaml: %w", err)) diff --git a/src/lib/telemetry/events.go b/src/lib/telemetry/events.go index 5a0c2c84..f553fc56 100644 --- a/src/lib/telemetry/events.go +++ b/src/lib/telemetry/events.go @@ -15,4 +15,7 @@ const ( Event_CreateSession Event = "session_create" Event_DeleteSession Event = "session_delete" Event_SearchSessions Event = "sessions_search" + + Event_CEStart Event = "ce_start" + Event_CEStop Event = "ce_stop" ) diff --git a/src/lib/telemetry/telemetry_ce.go b/src/lib/telemetry/telemetry_ce.go index c890a5e7..bd7fbc64 100644 --- a/src/lib/telemetry/telemetry_ce.go +++ b/src/lib/telemetry/telemetry_ce.go @@ -55,6 +55,10 @@ func (s *service) TrackEvent(req Request, event Event, metadata ...map[string]an return } + if !isCEEvent(event) { + return + } + ev := CEEvent{ Event: event, } @@ -127,3 +131,7 @@ func createInstallID() string { return id } + +func isCEEvent(event Event) bool { + return event == Event_CEStart || event == Event_CEStop +} diff --git a/src/setup_ce.go b/src/setup_ce.go index 0c6c722a..1af7a81c 100644 --- a/src/setup_ce.go +++ b/src/setup_ce.go @@ -7,15 +7,20 @@ import ( "github.com/getzep/zep/lib/config" "github.com/getzep/zep/lib/graphiti" + "github.com/getzep/zep/lib/telemetry" "github.com/getzep/zep/models" "github.com/getzep/zep/store" ) func setup(as *models.AppState) { graphiti.Setup() + + telemetry.I().TrackEvent(nil, telemetry.Event_CEStart) } -func gracefulShutdown() {} +func gracefulShutdown() { + telemetry.I().TrackEvent(nil, telemetry.Event_CEStop) +} func initializeDB(ctx context.Context, as *models.AppState) { err := store.MigrateSchema(ctx, as.DB, config.Postgres().SchemaName)