-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from sugarshop/develop
Develop
- Loading branch information
Showing
11 changed files
with
167 additions
and
6 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,22 @@ | ||
package db | ||
|
||
import ( | ||
postgrest "github.com/nedpals/postgrest-go/pkg" | ||
supa "github.com/nedpals/supabase-go" | ||
) | ||
|
||
// Init 数据库初始化连接 | ||
func Init() { | ||
supabaseUrl := "https://sfisgjpeqptcluzmtbup.supabase.co" | ||
supabaseKey := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNmaXNnanBlcXB0Y2x1em10YnVwIiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODM5MzAyMzAsImV4cCI6MTk5OTUwNjIzMH0.eHhleg3ev4YGA1yHosohWwzxOZxNEh4hP1PavfMF-X0" | ||
supabase := supa.CreateClient(supabaseUrl, supabaseKey) | ||
completionDB = supabase.DB | ||
} | ||
|
||
// completion DB | ||
var completionDB *postgrest.Client | ||
|
||
// CompletionDB completion DB | ||
func CompletionDB() *postgrest.Client { | ||
return completionDB | ||
} |
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,12 @@ | ||
package db | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestInit(t *testing.T) { | ||
Init() | ||
res := CompletionDB() | ||
assert.NotNil(t, res) | ||
} |
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
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
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
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
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
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
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,28 @@ | ||
package model | ||
|
||
import ( | ||
"github.com/sugarshop/asgard-gateway/db" | ||
"log" | ||
"time" | ||
) | ||
|
||
type Completion struct { | ||
ID int64 `json:"id,omitempty"` | ||
CreatedAt time.Time `json:"created_at"` | ||
ChatID string `json:"chat_id"` | ||
Model string `json:"model"` | ||
Content string `json:"content"` | ||
Role string `json:"role"` | ||
} | ||
|
||
func (s *Completion) Save() error { | ||
// set Now Time() | ||
s.CreatedAt = time.Now() | ||
var results []Completion | ||
err := db.CompletionDB().From("completion").Insert(s).Execute(&results) | ||
if err != nil { | ||
log.Printf("[Save]: err :%+v", err) | ||
return err | ||
} | ||
return nil | ||
} |
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,20 @@ | ||
package model | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"github.com/sugarshop/asgard-gateway/db" | ||
"testing" | ||
) | ||
|
||
func TestCompletion_Save(t *testing.T) { | ||
db.Init() | ||
compl := Completion{ | ||
ChatID: "chat-001", | ||
Model: "gpt-3.5-turbo-0301", | ||
Content: "i love u", | ||
Role: "test", | ||
} | ||
err := compl.Save() | ||
|
||
assert.Nil(t, err) | ||
} |
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