- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: add AI Bridge request logs model filter#21340
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes fromall commits
417aac70eeb490efbf1782a85911803ea8eac38fc6e6b20c70186385b9121731399a6c63dd6925254cf512a013ed2050bcedbe5c8c5446712e307e5887c1d117504662db553a1399fea772a703a85868620dc29b975106c4df901702cbcd4ff120fe9dd08eb366cca9be933cefb141673ea068f175261d379b418File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -768,6 +768,7 @@ func (q *sqlQuerier) CountAuthorizedConnectionLogs(ctx context.Context, arg Coun | ||
| type aibridgeQuerier interface { | ||
| ListAuthorizedAIBridgeInterceptions(ctx context.Context, arg ListAIBridgeInterceptionsParams, prepared rbac.PreparedAuthorized) ([]ListAIBridgeInterceptionsRow, error) | ||
| CountAuthorizedAIBridgeInterceptions(ctx context.Context, arg CountAIBridgeInterceptionsParams, prepared rbac.PreparedAuthorized) (int64, error) | ||
| ListAuthorizedAIBridgeModels(ctx context.Context, arg ListAIBridgeModelsParams, prepared rbac.PreparedAuthorized) ([]string, error) | ||
| } | ||
| func (q *sqlQuerier) ListAuthorizedAIBridgeInterceptions(ctx context.Context, arg ListAIBridgeInterceptionsParams, prepared rbac.PreparedAuthorized) ([]ListAIBridgeInterceptionsRow, error) { | ||
| @@ -866,6 +867,35 @@ func (q *sqlQuerier) CountAuthorizedAIBridgeInterceptions(ctx context.Context, a | ||
| return count, nil | ||
| } | ||
| func (q *sqlQuerier) ListAuthorizedAIBridgeModels(ctx context.Context, arg ListAIBridgeModelsParams, prepared rbac.PreparedAuthorized) ([]string, error) { | ||
| authorizedFilter, err := prepared.CompileToSQL(ctx, regosql.ConvertConfig{ | ||
| VariableConverter: regosql.AIBridgeInterceptionConverter(), | ||
| }) | ||
| if err != nil { | ||
| return nil, xerrors.Errorf("compile authorized filter: %w", err) | ||
| } | ||
| filtered, err := insertAuthorizedFilter(listAIBridgeModels, fmt.Sprintf(" AND %s", authorizedFilter)) | ||
| if err != nil { | ||
| return nil, xerrors.Errorf("insert authorized filter: %w", err) | ||
| } | ||
| query := fmt.Sprintf("-- name: ListAIBridgeModels :many\n%s", filtered) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nit: | ||
| rows, err := q.db.QueryContext(ctx, query, arg.Model, arg.Offset, arg.Limit) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer rows.Close() | ||
| var items []string | ||
| for rows.Next() { | ||
| var model string | ||
| if err := rows.Scan(&model); err != nil { | ||
| return nil, err | ||
| } | ||
| items = append(items, model) | ||
| } | ||
| return items, nil | ||
| } | ||
| func insertAuthorizedFilter(query string, replaceWith string) (string, error) { | ||
| if !strings.Contains(query, authorizedQueryPlaceholder) { | ||
| return "", xerrors.Errorf("query does not contain authorized replace string, this is not an authorized query") | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -366,3 +366,25 @@ SELECT ( | ||
| (SELECT COUNT(*) FROM user_prompts) + | ||
| (SELECT COUNT(*) FROM interceptions) | ||
| )::bigint as total_deleted; | ||
| -- name: ListAIBridgeModels :many | ||
| SELECT | ||
| model | ||
| FROM | ||
| aibridge_interceptions | ||
| WHERE | ||
| ended_at IS NOT NULL | ||
| -- Filter model | ||
| AND CASE | ||
| WHEN @model::text != '' THEN aibridge_interceptions.model ILIKE '%' || @model::text || '%' | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm a bit confused why we would want to filter model by model name? There shouldn't be that many unique models? Could we return all models and filter in the frontend (in doogfood there are distinct 28 models now)? Problem with filtering by text in backend is efficiency, or different index needs to be created:https://www.postgresql.org/docs/current/pgtrgm.html#PGTRGM-INDEX Also if I understand correctly authorization will add some WHERE initiator_id = "..." clause. There is no composite index but I don't think it matters that much in this case as there are single column indexes on both initiator_id and model columns. | ||
| ELSE true | ||
| END | ||
| -- We use an `@authorize_filter` as we are attempting to list models that are relevant | ||
| -- to the user and what they are allowed to see. | ||
| -- Authorize Filter clause will be injected below in ListAIBridgeModelsAuthorized | ||
| -- @authorize_filter | ||
| GROUP BY | ||
| model | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nit: SELECT DISTINCT model could be used instead of GROUP BY model | ||
| LIMIT COALESCE(NULLIF(@limit_::integer, 0), 100) | ||
| OFFSET @offset_ | ||
| ; | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.