-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* OpenAI Plugin MVP Signed-off-by: Alex Meijer <[email protected]> * code review fixes Signed-off-by: Alex Meijer <[email protected]> * add MAINTAINERS Signed-off-by: Alex Meijer <[email protected]> * only attempt to read if no error Signed-off-by: Alex Meijer <[email protected]> --------- Signed-off-by: Alex Meijer <[email protected]>
- Loading branch information
Showing
9 changed files
with
906 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# OpenCost Plugins Committers and Maintainers | ||
|
||
Official list of OpenCost Plugins Maintainers | ||
|
||
## Maintainers | ||
|
||
| Maintainer | GitHub ID | Affiliation | Email | | ||
| --------------- | --------- | ----------- | ----------- | | ||
| Nik Willwerth | @nik-kc | Kubecost | <[email protected]> | | ||
| Alex Meijer | @ameijer | Kubecost | <[email protected]> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
openaiplugin "github.com/opencost/opencost-plugins/pkg/plugins/openai/openaiplugin" | ||
"github.com/opencost/opencost/core/pkg/log" | ||
"github.com/opencost/opencost/core/pkg/model/pb" | ||
"github.com/opencost/opencost/core/pkg/util/timeutil" | ||
"golang.org/x/time/rate" | ||
"google.golang.org/protobuf/types/known/durationpb" | ||
"google.golang.org/protobuf/types/known/timestamppb" | ||
) | ||
|
||
func TestGetCustomCosts(t *testing.T) { | ||
// read necessary env vars. If any are missing, log warning and skip test | ||
oaiApiKey := os.Getenv("OAI_API_KEY") | ||
if oaiApiKey == "" { | ||
log.Warnf("OAI_API_KEY undefined, skipping test") | ||
t.Skip() | ||
return | ||
} | ||
|
||
//set up config | ||
config := openaiplugin.OpenAIConfig{ | ||
APIKey: oaiApiKey, | ||
} | ||
|
||
rateLimiter := rate.NewLimiter(1, 5) | ||
oaiCostSrc := OpenAICostSource{ | ||
rateLimiter: rateLimiter, | ||
config: &config, | ||
} | ||
|
||
windowStart := time.Date(2024, 10, 9, 0, 0, 0, 0, time.UTC) | ||
// query for qty 2 of 1 hour windows | ||
windowEnd := time.Date(2024, 10, 10, 0, 0, 0, 0, time.UTC) | ||
|
||
req := &pb.CustomCostRequest{ | ||
Start: timestamppb.New(windowStart), | ||
End: timestamppb.New(windowEnd), | ||
Resolution: durationpb.New(timeutil.Day), | ||
} | ||
|
||
log.SetLogLevel("debug") | ||
resp := oaiCostSrc.GetCustomCosts(req) | ||
|
||
if len(resp) == 0 { | ||
t.Fatalf("empty response") | ||
} | ||
} |
Oops, something went wrong.