Skip to content

Commit

Permalink
refactor: updated json encoder to gabs library
Browse files Browse the repository at this point in the history
  • Loading branch information
kingmariano committed Jul 20, 2024
1 parent 39062b9 commit 92a6d52
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion convertToMp3.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ConvertToMP3Params struct {
}

// convert to mp3 function accepts the request parameters converts either the URL string or audio file to mp3 and then returns the result clouding direct url.
func (c *Client) ConvertToMP3(ctx context.Context, req ConvertToMP3Params) (*ResponseMsg, error) {
func (c *Client) ConvertToMP3(ctx context.Context, req ConvertToMP3Params) (*GabsContainer, error) {
if req.URL == "" && req.File == nil {
return nil, ErrConvertToMP3NoURLOrFile
}
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/kingmariano/omnicron-go

go 1.22.4

require github.com/stretchr/testify v1.9.0
require (
github.com/Jeffail/gabs/v2 v2.7.0
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Jeffail/gabs/v2 v2.7.0 h1:Y2edYaTcE8ZpRsR2AtmPu5xQdFDIthFG0jYhu5PY8kg=
github.com/Jeffail/gabs/v2 v2.7.0/go.mod h1:dp5ocw1FvBBQYssgHsG7I1WYsiLRtkUaB1FEtSwvNUw=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
2 changes: 1 addition & 1 deletion groqcompletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type GroqChatCompletionParams struct {
User string `json:"user,omitempty"`
}

func (c *Client) GroqChatCompletion(ctx context.Context, req *GroqChatCompletionParams) (*ResponseMsg, error) {
func (c *Client) GroqChatCompletion(ctx context.Context, req *GroqChatCompletionParams) (*GabsContainer, error) {
if len(req.Messages) == 0 {
return nil, ErrGroqChatCompletionNoMessage
}
Expand Down
4 changes: 2 additions & 2 deletions imageGeneration.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type HighImageGenerationModelAndParams struct {
}

// LowImageGeneration handles the low image generation request for models that do not support image-to-image processing.
func (c *Client) LowImageGeneration(ctx context.Context, req LowImageGenerationModelAndParams) (*ResponseMsg, error) {
func (c *Client) LowImageGeneration(ctx context.Context, req LowImageGenerationModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand All @@ -88,7 +88,7 @@ func (c *Client) LowImageGeneration(ctx context.Context, req LowImageGenerationM
}

// HighImageGeneration handles the high image generation request for models that support image-to-image processing.
func (c *Client) HighImageGeneration(ctx context.Context, req HighImageGenerationModelAndParams) (*ResponseMsg, error) {
func (c *Client) HighImageGeneration(ctx context.Context, req HighImageGenerationModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand Down
4 changes: 2 additions & 2 deletions imageUpscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type HighImageUpscaleGenerationModelAndParams struct {
Parameters HighImageUpscaleGenerationParams
}

func (c *Client) LowImageUpscaling(ctx context.Context, req LowImageUpscaleGenerationModelAndParams) (*ResponseMsg, error) {
func (c *Client) LowImageUpscaling(ctx context.Context, req LowImageUpscaleGenerationModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand All @@ -76,7 +76,7 @@ func (c *Client) LowImageUpscaling(ctx context.Context, req LowImageUpscaleGener
return lowImageUpscaleResponse, nil
}

func (c *Client) HighImageUpscaling(ctx context.Context, req HighImageUpscaleGenerationModelAndParams) (*ResponseMsg, error) {
func (c *Client) HighImageUpscaling(ctx context.Context, req HighImageUpscaleGenerationModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand Down
4 changes: 2 additions & 2 deletions musicGeneration.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type HighMusicGenerationModelAndParams struct {
Parameters HighMusicGenerationParams
}

func (c *Client) LowMusicGeneration(ctx context.Context, req LowMusicGenerationModelAndParams) (*ResponseMsg, error) {
func (c *Client) LowMusicGeneration(ctx context.Context, req LowMusicGenerationModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand All @@ -75,7 +75,7 @@ func (c *Client) LowMusicGeneration(ctx context.Context, req LowMusicGenerationM
}
return lowMusicGenResponse, nil
}
func (c *Client) HighMusicGeneration(ctx context.Context, req HighMusicGenerationModelAndParams) (*ResponseMsg, error) {
func (c *Client) HighMusicGeneration(ctx context.Context, req HighMusicGenerationModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand Down
23 changes: 11 additions & 12 deletions response.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package omnicron

import "encoding/json"

type ResponseMsg struct {
Response interface{} `json:"response"`
}

func unmarshalJSONResponse(body []byte) (*ResponseMsg, error) {
var responseParams ResponseMsg
if err := json.Unmarshal(body, &responseParams); err != nil {
return nil, err
}
return &responseParams, nil
import (
"github.com/Jeffail/gabs/v2"
)
//using the gabs library for dynamic JSON handling
type GabsContainer = gabs.Container
func unmarshalJSONResponse(body []byte) (*GabsContainer, error) {
container, err := gabs.ParseJSON(body)
if err!= nil {
return nil, err
}
return container, nil
}
4 changes: 2 additions & 2 deletions stt.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type HighSTTModelAndParams struct {
}

// speech to text generation function
func (c *Client) LowSTTGeneration(ctx context.Context, req LowSTTModelAndParams) (*ResponseMsg, error) {
func (c *Client) LowSTTGeneration(ctx context.Context, req LowSTTModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand All @@ -59,7 +59,7 @@ func (c *Client) LowSTTGeneration(ctx context.Context, req LowSTTModelAndParams)
}
return lowSTTGenResponse, nil
}
func (c *Client) HighSTTGeneration(ctx context.Context, req HighSTTModelAndParams) (*ResponseMsg, error) {
func (c *Client) HighSTTGeneration(ctx context.Context, req HighSTTModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand Down
6 changes: 3 additions & 3 deletions tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type HighTTSModelAndParams struct {
Parameters HighTTSParams
}

func (c *Client) LowTTSGeneration(ctx context.Context, req LowTTSModelAndParams) (*ResponseMsg, error) {
func (c *Client) LowTTSGeneration(ctx context.Context, req LowTTSModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand All @@ -86,7 +86,7 @@ func (c *Client) LowTTSGeneration(ctx context.Context, req LowTTSModelAndParams)
return lowTTSGenResponse, nil
}

func (c *Client) MediumTTSGeneration(ctx context.Context, req MediumTTSModelAndParams) (*ResponseMsg, error) {
func (c *Client) MediumTTSGeneration(ctx context.Context, req MediumTTSModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand All @@ -101,7 +101,7 @@ func (c *Client) MediumTTSGeneration(ctx context.Context, req MediumTTSModelAndP
return mediumTTSGenResponse, nil
}

func (c *Client) HighTTSGeneration(ctx context.Context, req HighTTSModelAndParams) (*ResponseMsg, error) {
func (c *Client) HighTTSGeneration(ctx context.Context, req HighTTSModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand Down
2 changes: 1 addition & 1 deletion videoGeneration.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type HighVideoGenerationModelAndParams struct {
Parameters HighVideoGenerationParams
}

func (c *Client) VideoGeneration(ctx context.Context, req HighVideoGenerationModelAndParams) (*ResponseMsg, error) {
func (c *Client) VideoGeneration(ctx context.Context, req HighVideoGenerationModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
Expand Down
2 changes: 1 addition & 1 deletion videodownloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type VideoDownloadParams struct {
}

// this download video function downloads the video url from any of the supported sites uploads to cloudinary and returns the direct download url
func (c *Client) DownloadVideo(ctx context.Context, req *VideoDownloadParams) (*ResponseMsg, error) {
func (c *Client) DownloadVideo(ctx context.Context, req *VideoDownloadParams) (*GabsContainer, error) {
if req.URL == "" {
return nil, ErrVideoDownloadNoURLProvided
}
Expand Down

0 comments on commit 92a6d52

Please sign in to comment.