Skip to content

Commit

Permalink
OpenAI Plugin MVP (#38)
Browse files Browse the repository at this point in the history
* 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
ameijer authored Oct 10, 2024
1 parent 42d14e3 commit 0c42e1a
Show file tree
Hide file tree
Showing 9 changed files with 906 additions and 0 deletions.
10 changes: 10 additions & 0 deletions MAINTAINERS.md
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]> |
53 changes: 53 additions & 0 deletions pkg/plugins/openai/cmd/main/getcustomcosts_test.go
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")
}
}
Loading

0 comments on commit 0c42e1a

Please sign in to comment.