Documentation
¶
Index ¶
Constants ¶
const ( SchemaVersionV2 string = "v2" DefaultSchemaVersion string = SchemaVersionV2 )
SchemaVersion is the version of the schema, used for backwards compatibility.
const ObjectTypeDefault string = "llm_proxy_traffic_log"
ObjectTypeDefault is the default object type for the log dump container, used for identifying the file type when loading various objects from json files.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIProvider ¶ added in v2.4.1
type APIProvider struct {
// contains filtered or unexported fields
}
APIProvider holds the various pricing and model data for a single API provider, e.g., OpenAI.com
func (*APIProvider) String ¶ added in v2.4.1
func (cc *APIProvider) String() string
type AuditOutput ¶
type AuditOutput struct {
URL string `JSON:"url"`
Model string `JSON:"model"`
InputCost string `JSON:"inputCost"`
OutputCost string `JSON:"outputCost"`
TotalReqCost string `JSON:"totalReqCost"`
GrandTotal string `JSON:"grandTotal"`
}
AuditOutput is a struct that holds the output data (cost totals) from a single transaction
func (*AuditOutput) String ¶
func (output *AuditOutput) String() string
type CostCounter ¶
type CostCounter struct {
// contains filtered or unexported fields
}
CostCounter is a struct that holds the state of the cost counter
func NewCostCounter ¶
func NewCostCounter(currencyLocale string) *CostCounter
NewCostCounter creates an object that _should_ be a singleton, in the Addon layer. currencyLocale is the locale for the currency formatter, e.g., "en-US" formatString is the output format string, e.g., OutputFormatFull or OutputFormatShort
func NewCostCounterDefaults ¶
func NewCostCounterDefaults() *CostCounter
NewCostCounterDefaults creates a new CostCounter object with reasonable defaults
func (*CostCounter) Add ¶
func (cc *CostCounter) Add(req ProxyRequest, resp ProxyResponse) (*AuditOutput, error)
Add is the primary method for working with this object, it takes a proxy req/resp and calculates the cost of the transaction, returning a struct with the output data
func (*CostCounter) String ¶
func (cc *CostCounter) String() string
type LogDumpContainer ¶
type LogDumpContainer struct {
ObjectType string `json:"object_type,omitempty"`
SchemaVersion string `json:"schema,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
ConnectionStats *ProxyConnectionStats `json:"connection_stats,omitempty"`
Request *ProxyRequest `json:"request,omitempty"`
Response *ProxyResponse `json:"response,omitempty"`
// contains filtered or unexported fields
}
LogDumpContainer holds the request and response data for a given flow
func NewLogDumpContainer ¶
func NewLogDumpContainer( f proxyadapters.FlowReaderAdapter, logSources config.LogSourceConfig, doneAt int64, filterReqHeaders, filterRespHeaders *config.HeaderFilterGroup, ) (*LogDumpContainer, error)
NewLogDumpContainer returns a LogDumpContainer with *only* the fields requested in logSources populated
func UnmarshalLogDumpContainer ¶ added in v2.4.1
func UnmarshalLogDumpContainer(data []byte) (*LogDumpContainer, error)
UnmarshalLogDumpContainer unmarshals JSON data into a LogDumpContainer
func (*LogDumpContainer) UnmarshalJSON ¶ added in v2.4.1
func (ldc *LogDumpContainer) UnmarshalJSON(data []byte) error
type ProxyConnectionStats ¶ added in v2.2.0
type ProxyConnectionStats struct {
ClientAddress string `json:"client_address"`
URL string `json:"url"`
Duration int64 `json:"duration_ms"`
ProxyID string `json:"proxy_id,omitempty"`
}
ProxyConnectionStats is a struct that holds the output data (connection stats) from a single transaction
func NewProxyConnectionStatsWithDuration ¶ added in v2.2.0
func NewProxyConnectionStatsWithDuration(cs proxyadapters.ConnectionStatsReaderAdapter, doneAt int64) *ProxyConnectionStats
NewProxyConnectionStatsWithDuration is a slightly leaky abstraction, the doneAt param is for logging the entire session length, and comes from the proxy addon layer.
func (*ProxyConnectionStats) ToJSON ¶ added in v2.2.0
func (obj *ProxyConnectionStats) ToJSON() []byte
ToJSON converts the ProxyConnectionStats object to a JSON byte slice
func (*ProxyConnectionStats) ToJSONstr ¶ added in v2.2.0
func (obj *ProxyConnectionStats) ToJSONstr() string
ToJSONstr converts the ProxyConnectionStats object to a JSON string
type ProxyRequest ¶
type ProxyRequest struct {
Method string `json:"method,omitempty"`
URL *url.URL `json:"url,omitempty"`
Proto string `json:"proto,omitempty"`
Header http.Header `json:"header"`
Body string `json:"body"`
// contains filtered or unexported fields
}
ProxyRequest is a struct that represents a request to be proxied
func NewProxyRequest ¶ added in v2.2.0
func NewProxyRequest(req proxyadapters.RequestReaderAdapter, headerFilter *config.HeaderFilterGroup) (*ProxyRequest, error)
NewProxyRequest creates a new ProxyRequest from a MITM proxy request object
func (*ProxyRequest) HeaderString ¶
func (pReq *ProxyRequest) HeaderString() string
HeaderString returns the headers as a flat string
func (*ProxyRequest) MarshalJSON ¶
func (pReq *ProxyRequest) MarshalJSON() ([]byte, error)
MarshalJSON dumps this ProxyRequest into a byte array containing JSON
func (*ProxyRequest) UnmarshalJSON ¶
func (pReq *ProxyRequest) UnmarshalJSON(data []byte) error
UnmarshalJSON performs a non-threadsafe load of json data into THIS ProxyRequest
type ProxyResponse ¶
type ProxyResponse struct {
Status int `json:"status,omitempty"`
Header http.Header `json:"header"`
Body string `json:"body"`
// contains filtered or unexported fields
}
ProxyResponse is a struct that represents a response from a proxied request
func NewProxyResponse ¶ added in v2.2.0
func NewProxyResponse(req proxyadapters.ResponseReaderAdapter, headerFilter *config.HeaderFilterGroup) (*ProxyResponse, error)
NewProxyResponse creates a new ProxyRequest from a MITM proxy request object
func NewProxyResponseFromJSONBytes ¶
func NewProxyResponseFromJSONBytes(data []byte) (*ProxyResponse, error)
NewProxyResponseFromJSONBytes unmarshals a JSON object into a TrafficObject. Headers must be filtered later.
func (*ProxyResponse) GetBodyBytes ¶ added in v2.2.0
func (pRes *ProxyResponse) GetBodyBytes() []byte
GetBodyBytes returns the body as a byte slice
func (*ProxyResponse) GetHeaders ¶ added in v2.2.0
func (pRes *ProxyResponse) GetHeaders() http.Header
GetHeaders returns the headers in the ProxyResponse object
func (*ProxyResponse) GetStatusCode ¶ added in v2.2.0
func (pRes *ProxyResponse) GetStatusCode() int
GetStatusCode returns the status code in the ProxyResponse object
func (*ProxyResponse) HeaderString ¶
func (pRes *ProxyResponse) HeaderString() string
HeaderString returns the headers as a flat string
func (*ProxyResponse) UnmarshalJSON ¶
func (pRes *ProxyResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON performs a non-threadsafe load of json data into THIS ProxyResponse