From f477bcf405ff0a234ae1a28dee4ee02d30f32e69 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Fri, 17 Nov 2023 16:38:53 +0000 Subject: [PATCH] Avoid time.DateOnly It looks like the github action build environment for this repo uses a go 1.19.x environment which does not have time.DateOnly. Replace with local constant until this is upgraded. (cherry picked from commit 22886dd75f40ccedfe708877085a6ba95c790c38) (cherry picked from commit 5225542b81ff52703e2a649acbb9c014c7af06af) (cherry picked from commit fbaa1f16b0cfb6fc68974f068b6120caf8d29a21) (cherry picked from commit 46091ed224a81d6d18f82572ba95e4a340d3f002) --- billing.go | 8 ++++++-- billing_test.go | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/billing.go b/billing.go index 33f3ce9bf..d98087088 100644 --- a/billing.go +++ b/billing.go @@ -31,6 +31,10 @@ type BillingUsageResponse struct { httpHeader } +// @todo remove this and replace w/ time.DateOnly once github build +// environment is upgraded to a more recent go toolchain. +const DateOnly = "2006-01-02" + // currently the OpenAI usage API is not publicly documented and will explictly // reject requests using an API key authorization. however, it can be utilized // logging into https://platform.openai.com/usage and retrieving your session @@ -43,8 +47,8 @@ var ( // GetBillingUsage — API call to Get billing usage details. func (c *Client) GetBillingUsage(ctx context.Context, startDate time.Time, endDate time.Time) (response BillingUsageResponse, err error) { - startDateArg := fmt.Sprintf("start_date=%v", startDate.Format(time.DateOnly)) - endDateArg := fmt.Sprintf("end_date=%v", endDate.Format(time.DateOnly)) + startDateArg := fmt.Sprintf("start_date=%v", startDate.Format(DateOnly)) + endDateArg := fmt.Sprintf("end_date=%v", endDate.Format(DateOnly)) queryParams := fmt.Sprintf("%v&%v", startDateArg, endDateArg) urlSuffix := fmt.Sprintf("%v?%v", billingUsageSuffix, queryParams) diff --git a/billing_test.go b/billing_test.go index a61decec8..339ee4d54 100644 --- a/billing_test.go +++ b/billing_test.go @@ -28,9 +28,9 @@ func TestBillingUsageAPIKey(t *testing.T) { ctx := context.Background() - endDate, err := time.Parse(time.DateOnly, TestEndDate) + endDate, err := time.Parse(openai.DateOnly, TestEndDate) checks.NoError(t, err) - startDate, err := time.Parse(time.DateOnly, TestStartDate) + startDate, err := time.Parse(openai.DateOnly, TestStartDate) checks.NoError(t, err) _, err = client.GetBillingUsage(ctx, startDate, endDate) @@ -43,9 +43,9 @@ func TestBillingUsageSessKey(t *testing.T) { server.RegisterHandler("/dashboard/billing/usage", handleBillingEndpoint) ctx := context.Background() - endDate, err := time.Parse(time.DateOnly, TestEndDate) + endDate, err := time.Parse(openai.DateOnly, TestEndDate) checks.NoError(t, err) - startDate, err := time.Parse(time.DateOnly, TestStartDate) + startDate, err := time.Parse(openai.DateOnly, TestStartDate) checks.NoError(t, err) resp, err := client.GetBillingUsage(ctx, startDate, endDate) @@ -82,7 +82,7 @@ func handleBillingEndpoint(w http.ResponseWriter, r *http.Request) { dailyCosts := make([]openai.DailyCostResponse, 0) - d, _ := time.Parse(time.DateOnly, TestStartDate) + d, _ := time.Parse(openai.DateOnly, TestStartDate) d = d.Add(24 * time.Hour) dailyCosts = append(dailyCosts, openai.DailyCostResponse{ TimestampRaw: float64(d.Unix()),