Skip to content

Commit

Permalink
created additional makefiles to handle repository specific targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-Gabriel-Susman committed Oct 22, 2023
1 parent 0eb6c7d commit 57a34d7
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "delphi-build-utils"]
path = delphi-build-utils
url = https://github.com/Max-Gabriel-Susman/delphi-build-utils
Empty file added Makefile.project
Empty file.
Empty file added Makefile.vars
Empty file.
1 change: 1 addition & 0 deletions delphi-build-utils
Submodule delphi-build-utils added at a325ac
1 change: 1 addition & 0 deletions internal/inference/inference.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package inference
1 change: 1 addition & 0 deletions internal/inference/inference_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package inference_test
1 change: 1 addition & 0 deletions internal/server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package server
1 change: 1 addition & 0 deletions internal/server/server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package server_test
8 changes: 4 additions & 4 deletions internal/textgeneration/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ type Server interface {
Decode(context.Context, *pb.HelloRequest) (*pb.HelloReply, error)
}

type TextGenerationServer struct {
Server server
}

type server struct {
pb.UnimplementedGreeterServer
OpenAIClient *openai.Client
}

type TextGenerationServer struct {
Server server
}

func NewTextGenerationServer(openaiClient *openai.Client) *TextGenerationServer {
return &TextGenerationServer{
Server: server{
Expand Down
147 changes: 81 additions & 66 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,29 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ssm"

"github.com/Max-Gabriel-Susman/delphi-inferential-service/internal/clients/openai"
tg "github.com/Max-Gabriel-Susman/delphi-inferential-service/internal/textgeneration"
pb "github.com/Max-Gabriel-Susman/delphi-inferential-service/textgeneration"
)

/*
TODOs:
META:
* start a documentation direcory
* start implementing testing coverage
* work more on readme
* abstract what we can to delphi-go-kit (e.g. logging, tracing, etc.)
* determine what logging tracing solutions I want to use long term(probably just something within aws honestly)
* refactor rootlevel protobuf/grpc logic into corresponding
internal directories
* refactor main.go to cmd/delphi-x-service/main.go
* clean up Make targets and keep them up to date
* abstract build logic execution into submodule delphi build-utils
* we may want to drop the db directory, not sure if it really belongs in the
current iteration of this service anymore
MESA:
*/

const (
exitCodeErr = 1
exitCodeInterrupt = 2
Expand Down Expand Up @@ -58,17 +73,17 @@ func run(ctx context.Context, _ []string) error {
// return errors.Wrap(err, "could not create aws sdk config")
// }

var cfg struct {
OpenAI struct {
APIKey string `env:""`
APIOrg string ``
}
}
if err := env.Parse(&cfg); err != nil {
return errors.Wrap(err, "parsing configuration")
}
// apiKey := os.Getenv("api-key") // we'll want to get from SSM later
// organization := os.Getenv("api-org")
// var cfg struct {
// OpenAI struct {
// APIKey string `env:""`
// APIOrg string ``
// }
// }
// if err := env.Parse(&cfg); err != nil {
// return errors.Wrap(err, "parsing configuration")
// }
apiKey := os.Getenv("api-key") // we'll want to get from SSM later
organization := os.Getenv("api-org")
openaiClient := openai.NewClient(apiKey, organization)

// Start GRPC Service
Expand Down Expand Up @@ -96,60 +111,60 @@ func run(ctx context.Context, _ []string) error {
return nil
}

func Sessions() (*session.Session, error) {
sess, err := session.NewSession()
svc := session.Must(sess, err)
return svc, err
}

func NewSSMClient() *SSM {
// Create AWS Session
sess, err := Sessions()
if err != nil {
log.Println(err)
return nil
}
ssmsvc := &SSM{ssm.New(sess)}
// Return SSM client
return ssmsvc
}

type Param struct {
Name string
WithDecryption bool
ssmsvc *SSM
}
// func Sessions() (*session.Session, error) {
// sess, err := session.NewSession()
// svc := session.Must(sess, err)
// return svc, err
// }

//Param creates the struct for querying the param store
func (s *SSM) Param(name string, decryption bool) *Param {
return &Param{
Name: name,
WithDecryption: decryption,
ssmsvc: s,
}
}
// func NewSSMClient() *SSM {
// // Create AWS Session
// sess, err := Sessions()
// if err != nil {
// log.Println(err)
// return nil
// }
// ssmsvc := &SSM{ssm.New(sess)}
// // Return SSM client
// return ssmsvc
// }

func (p *Param) GetValue() (string, error) {
ssmsvc := p.ssmsvc.client
parameter, err := ssmsvc.GetParameter(&ssm.GetParameterInput{
Name: &p.Name,
WithDecryption: &p.WithDecryption,
})
if err != nil {
return "", err
}
value := *parameter.Parameter.Value
return value, nil
}
// type Param struct {
// Name string
// WithDecryption bool
// ssmsvc *SSM
// }

// ssmsvc := NewSSMClient()
// apiKey, err := ssmsvc.Param("myparam", true).GetValue()
// if err != nil {
// log.Println(err)
// //Param creates the struct for querying the param store
// func (s *SSM) Param(name string, decryption bool) *Param {
// return &Param{
// Name: name,
// WithDecryption: decryption,
// ssmsvc: s,
// }
// }
// log.Println(apiKey)
// organization, err := ssmsvc.Param("myparam", true).GetValue()
// if err != nil {
// log.Println(err)

// func (p *Param) GetValue() (string, error) {
// ssmsvc := p.ssmsvc.client
// parameter, err := ssmsvc.GetParameter(&ssm.GetParameterInput{
// Name: &p.Name,
// WithDecryption: &p.WithDecryption,
// })
// if err != nil {
// return "", err
// }
// value := *parameter.Parameter.Value
// return value, nil
// }
// log.Println(organization)

// // ssmsvc := NewSSMClient()
// // apiKey, err := ssmsvc.Param("myparam", true).GetValue()
// // if err != nil {
// // log.Println(err)
// // }
// // log.Println(apiKey)
// // organization, err := ssmsvc.Param("myparam", true).GetValue()
// // if err != nil {
// // log.Println(err)
// // }
// // log.Println(organization)

0 comments on commit 57a34d7

Please sign in to comment.