-
Notifications
You must be signed in to change notification settings - Fork 161
Draft: AIP Filtering implementation #3951
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,24 +17,32 @@ namespace LLMCost; | |
| * TODO: This is a temporary solution to support the filter API. | ||
| */ | ||
| @friendlyName("FilterSingleString") | ||
| // @useRef("../../../../common/definitions/aip_filters.yaml#/components/schemas/StringFieldFilter") | ||
| model FilterSingleString { | ||
| /** | ||
| * The field must match the provided value. | ||
| */ | ||
| @extension("x-omitempty", true) | ||
| eq?: string; | ||
|
|
||
| /** | ||
| * The field must match the provided value. This is an "override" filter that can be used when the default `eq` filter is not sufficient, e.g. when filtering by `model_name` where the name can have multiple variants for the same model ID. | ||
| */ | ||
| oeq?: string; | ||
|
|
||
| /** | ||
| * The field must not match the provided value. | ||
| */ | ||
| @extension("x-omitempty", true) | ||
| neq?: string; | ||
|
|
||
| /** | ||
| * The field must contain the provided value. | ||
| */ | ||
| @extension("x-omitempty", true) | ||
| contains?: string; | ||
|
|
||
| /** | ||
| * The field must contain the provided value. This is an "override" filter that can be used when the default `contains` filter is not sufficient. | ||
| */ | ||
| ocontains?: string; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -44,16 +52,20 @@ model FilterSingleString { | |
| @friendlyName("ListLLMCostPricesParamsFilter") | ||
| model ListPricesParamsFilter { | ||
| /** Filter by provider. e.g. ?filter[provider][eq]=openai */ | ||
| provider?: FilterSingleString; | ||
| @extension("x-go-type", "FilterString") | ||
| provider?: string | FilterSingleString; | ||
|
|
||
| /** Filter by model ID. e.g. ?filter[model_id][eq]=gpt-4 */ | ||
| model_id?: FilterSingleString; | ||
| @extension("x-go-type", "FilterString") | ||
| model_id?: string | FilterSingleString; | ||
|
|
||
| /** Filter by model name. e.g. ?filter[model_name][contains]=gpt */ | ||
| model_name?: FilterSingleString; | ||
| @extension("x-go-type", "FilterString") | ||
| model_name?: string | FilterSingleString; | ||
|
|
||
| /** Filter by currency code. e.g. ?filter[currency][eq]=USD */ | ||
| currency?: FilterSingleString; | ||
| @extension("x-go-type", "FilterString") | ||
| currency?: string | FilterSingleString; | ||
|
Comment on lines
54
to
+68
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. The new shorthand form should be documented too. These filters now accept As per coding guidelines "The declared API should be accurate, in parity with the actual implementation, and easy to understand for the user." 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| /** | ||
|
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,35 @@ | ||
| //go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=codegen.yaml ./openapi.yaml | ||
| package v3 | ||
|
|
||
| import ( | ||
| "net/http" | ||
| ) | ||
|
|
||
| // FilterString A filter for a string field. | ||
| type FilterString struct { | ||
| // Contains The field must contain the provided value. | ||
| Contains *string `json:"contains,omitempty"` | ||
|
|
||
| // Eq The field must match the provided value. | ||
| Eq *string `json:"eq,omitempty"` | ||
|
|
||
| // Neq The field must not match the provided value. | ||
| Neq *string `json:"neq,omitempty"` | ||
|
|
||
| // Ocontains asd | ||
| Ocontains *string `json:"ocontains,omitempty"` | ||
|
|
||
| // Oeq aasd | ||
| Oeq *string `json:"oeq,omitempty"` | ||
| } | ||
|
|
||
| func (f *FilterString) ParseEq(name string, r *http.Request) { | ||
| if f == nil { | ||
| f = &FilterString{} | ||
| } | ||
| query := r.URL.Query() | ||
| eq := query.Get(name) | ||
| if eq != "" { | ||
| f.Eq = &eq | ||
| } | ||
| } | ||
|
Comment on lines
+26
to
+35
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Inspect the helper and the current call sites.
sed -n '20,40p' api/v3/api.go
rg -n --type=go -C2 '\.ParseEq\(' api/v3Repository: openmeterio/openmeter Length of output: 1989 🏁 Script executed: # Find the Filter type definition
fd -t f "\.go$" api/v3 -x grep -l "type.*Filter" {} \;
# Look for the structure that contains Provider, ModelId, etc.
rg -A 20 "type.*Filter.*struct" api/v3 --type=go | head -100
# Check how params.Filter is initialized
rg -B 5 -A 5 "params.Filter\s*=" api/v3/handlers/llmcost --type=goRepository: openmeterio/openmeter Length of output: 5053 🏁 Script executed: # Find the Filter type that contains Provider, ModelId, ModelName, Currency
rg -B 5 "Provider.*Filter" api/v3/handlers/llmcost/list_overrides.go --type=go | head -30
# Search for the struct definition with these fields
rg "type.*struct" api/v3 --type=go -A 10 | grep -A 15 "Provider"Repository: openmeterio/openmeter Length of output: 1771 🏁 Script executed: # Find the handler function signature in list_overrides.go
rg -B 20 "params.Filter.Provider.ParseEq" api/v3/handlers/llmcost/list_overrides.go --type=go | head -50
# Look for the type definition of the params variable
rg "type.*Override.*struct|type.*ListOverrides.*struct" api/v3 --type=go -A 20Repository: openmeterio/openmeter Length of output: 2697 🏁 Script executed: # Find the ListLLMCostPricesParamsFilter struct definition
rg "type ListLLMCostPricesParamsFilter struct" api/v3 --type=go -A 20Repository: openmeterio/openmeter Length of output: 1320 ParseEq doesn't update the caller's field when it starts nil. These filter fields ( Consider initializing these filter fields upfront, returning the initialized struct from 🤖 Prompt for AI Agents |
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.