y3iz+LnmZ0?puLem+VbTk- 0Zb_9}8
zgCL
+1taZv8Sh}
zj~VT3tgRVwb*QEhpVa>>G5F39y;AHtt;fi5-u8Zpb5t7(w
z@LA9dlCDQbM?W;=a&r*gS{_$_c
YU%4^
z2D6Q2BXd7~pbA>O&DU;K{QK#P*PUw5{)BTM=a6(tl>bZ%xA;=&HF)gOyDx;*
zz>jbBuMY+c1Kp5q6|_|ApKo>A00O)G=;RK?KacUxVp>kUW>+tpzoy%cZ!5m)17Ofr
ZAIbA?kF;^gc2R&o9hiXz`i9+;{{ZWAsF?r&
literal 0
HcmV?d00001
diff --git a/pkg/azureopenai/azureopenai.go b/pkg/azureopenai/azureopenai.go
new file mode 100644
index 0000000..f61d017
--- /dev/null
+++ b/pkg/azureopenai/azureopenai.go
@@ -0,0 +1,58 @@
+/*
+https://learn.microsoft.com/zh-cn/azure/cognitive-services/openai/chatgpt-quickstart
+
+curl $AZURE_OPENAI_ENDPOINT/openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-03-15-preview \
+ -H "Content-Type: application/json" \
+ -H "api-key: $AZURE_OPENAI_KEY" \
+ -d '{
+ "model": "gpt-3.5-turbo",
+ "messages": [{"role": "user", "content": "你好"}]
+ }'
+
+*/
+
+package azureopenai
+
+import (
+ "encoding/json"
+ "net/http"
+)
+
+var (
+ ENDPOINT string
+ API_KEY string
+ DEPLOYMENT_NAME string
+)
+
+type ModelsList struct {
+ Data []struct {
+ ScaleSettings struct {
+ ScaleType string `json:"scale_type"`
+ } `json:"scale_settings"`
+ Model string `json:"model"`
+ Owner string `json:"owner"`
+ ID string `json:"id"`
+ Status string `json:"status"`
+ CreatedAt int `json:"created_at"`
+ UpdatedAt int `json:"updated_at"`
+ Object string `json:"object"`
+ } `json:"data"`
+ Object string `json:"object"`
+}
+
+func Models(endpoint, apikey string) (*ModelsList, error) {
+ var modelsl ModelsList
+ req, _ := http.NewRequest(http.MethodGet, endpoint+"/openai/deployments?api-version=2022-12-01", nil)
+ req.Header.Set("api-key", apikey)
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ return nil, err
+ }
+ defer resp.Body.Close()
+ err = json.NewDecoder(resp.Body).Decode(&modelsl)
+ if err != nil {
+ return nil, err
+ }
+ return &modelsl, nil
+
+}
diff --git a/router/router.go b/router/router.go
index 2fc507b..43643a5 100644
--- a/router/router.go
+++ b/router/router.go
@@ -413,7 +413,7 @@ func HandleProy(c *gin.Context) {
if resp.StatusCode == 200 && localuser {
if isStream {
- contentCh := fetchResponseContent(writer, reader)
+ contentCh := fetchResponseContent(c, reader)
var buffer bytes.Buffer
for content := range contentCh {
buffer.WriteString(content)
@@ -536,15 +536,18 @@ func HandleUsage(c *gin.Context) {
c.JSON(200, usage)
}
-func fetchResponseContent(w *bufio.Writer, responseBody *bufio.Reader) <-chan string {
+func fetchResponseContent(ctx *gin.Context, responseBody *bufio.Reader) <-chan string {
contentCh := make(chan string)
go func() {
defer close(contentCh)
for {
line, err := responseBody.ReadString('\n')
if err == nil {
- w.WriteString(line)
- w.Flush()
+ lines := strings.Split(line, "")
+ for _, word := range lines {
+ ctx.Writer.WriteString(word)
+ ctx.Writer.Flush()
+ }
if line == "\n" {
continue
}
diff --git a/store/keydb.go b/store/keydb.go
index 3d623fe..05f6d9c 100644
--- a/store/keydb.go
+++ b/store/keydb.go
@@ -3,12 +3,15 @@ package store
import "time"
type Key struct {
- ID uint `gorm:"primarykey" json:"id,omitempty"`
- Key string `gorm:"unique;not null" json:"key,omitempty"`
- Name string `gorm:"unique;not null" json:"name,omitempty"`
- UserId string `json:"-,omitempty"`
- CreatedAt time.Time `json:"createdAt,omitempty"`
- UpdatedAt time.Time `json:"updatedAt,omitempty"`
+ ID uint `gorm:"primarykey" json:"id,omitempty"`
+ Key string `gorm:"unique;not null" json:"key,omitempty"`
+ Name string `gorm:"unique;not null" json:"name,omitempty"`
+ UserId string `json:"-,omitempty"`
+ KeyType string
+ EndPoint string
+ DeploymentName string
+ CreatedAt time.Time `json:"createdAt,omitempty"`
+ UpdatedAt time.Time `json:"updatedAt,omitempty"`
}
func GetKeyrByName(name string) (*Key, error) {