record whisper response
This commit is contained in:
27
process.go
27
process.go
@@ -31,7 +31,12 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
|
||||
return err
|
||||
}
|
||||
|
||||
remote.Path = upstream.URL.Path + strings.TrimPrefix(c.Request.URL.Path, "/v1")
|
||||
path := strings.TrimPrefix(c.Request.URL.Path, "/v1")
|
||||
// recoognize whisper url
|
||||
if strings.HasPrefix(path, "/audio/transcriptions") || strings.HasPrefix(path, "/audio/translations") {
|
||||
record.Model = "whisper"
|
||||
}
|
||||
remote.Path = upstream.URL.Path + path
|
||||
log.Println("[proxy.begin]:", remote)
|
||||
log.Println("[proxy.begin]: shouldResposne:", shouldResponse)
|
||||
|
||||
@@ -59,19 +64,16 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
|
||||
// record chat message from user
|
||||
record.Body = string(inBody)
|
||||
requestBody, requestBodyOK := ParseRequestBody(inBody)
|
||||
// if there allow list and unknown body, return error
|
||||
if len(upstream.Allow) > 0 && requestBodyOK != nil {
|
||||
errCtx = append(errCtx, errors.New("[proxy.rewrite]: allow list but unknown model"))
|
||||
return
|
||||
}
|
||||
// record if parse success
|
||||
if requestBodyOK == nil {
|
||||
if requestBodyOK == nil && record.Model != "" {
|
||||
record.Model = requestBody.Model
|
||||
}
|
||||
|
||||
// check allow list
|
||||
if len(upstream.Allow) > 0 {
|
||||
isAllow := false
|
||||
for _, allow := range upstream.Allow {
|
||||
if allow == requestBody.Model {
|
||||
if allow == record.Model {
|
||||
isAllow = true
|
||||
break
|
||||
}
|
||||
@@ -84,13 +86,12 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
|
||||
// check block list
|
||||
if len(upstream.Deny) > 0 {
|
||||
for _, deny := range upstream.Deny {
|
||||
if deny == requestBody.Model {
|
||||
if deny == record.Model {
|
||||
errCtx = append(errCtx, errors.New("[proxy.rewrite]: model denied"))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set timeout, default is 60 second
|
||||
timeout := 60 * time.Second
|
||||
@@ -178,7 +179,7 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
|
||||
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
|
||||
haveResponse = true
|
||||
record.ResponseTime = time.Now().Sub(record.CreatedAt)
|
||||
log.Println("[proxy.errorHandler]", err, upstream.SK, upstream.Endpoint)
|
||||
log.Println("[proxy.errorHandler]", err, upstream.SK, upstream.Endpoint, errCtx)
|
||||
|
||||
errCtx = append(errCtx, err)
|
||||
|
||||
@@ -248,6 +249,10 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
|
||||
}
|
||||
record.Response += chunk.Choices[0].Delta.Content
|
||||
}
|
||||
} else if strings.HasPrefix(contentType, "text") && strings.HasPrefix(record.Model, "whisper") {
|
||||
// whisper model response
|
||||
record.Response = string(resp)
|
||||
record.Body = ""
|
||||
} else if strings.HasPrefix(contentType, "application/json") {
|
||||
var fetchResp FetchModeResponse
|
||||
err := json.Unmarshal(resp, &fetchResp)
|
||||
|
||||
Reference in New Issue
Block a user