Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config template and telemetry fixes #377

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.ce.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ volumes:
zep-db:
networks:
zep-network:
driver: bridge
driver: bridge
39 changes: 39 additions & 0 deletions src/lib/config/env_template.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions src/lib/config/load_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions src/lib/telemetry/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
8 changes: 8 additions & 0 deletions src/lib/telemetry/telemetry_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -127,3 +131,7 @@ func createInstallID() string {

return id
}

func isCEEvent(event Event) bool {
return event == Event_CEStart || event == Event_CEStop
}
7 changes: 6 additions & 1 deletion src/setup_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading