Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e64fa48823 | ||
|
|
beff9282f6 |
@@ -246,7 +246,7 @@ func (h *APIHandlers) geminiCountTokens(c *gin.Context, rawJson []byte) {
|
|||||||
c.Header("Content-Type", "application/json")
|
c.Header("Content-Type", "application/json")
|
||||||
|
|
||||||
alt := h.getAlt(c)
|
alt := h.getAlt(c)
|
||||||
|
// orgRawJson := rawJson
|
||||||
modelResult := gjson.GetBytes(rawJson, "model")
|
modelResult := gjson.GetBytes(rawJson, "model")
|
||||||
modelName := modelResult.String()
|
modelName := modelResult.String()
|
||||||
cliCtx, cliCancel := context.WithCancel(context.Background())
|
cliCtx, cliCancel := context.WithCancel(context.Background())
|
||||||
@@ -273,8 +273,13 @@ func (h *APIHandlers) geminiCountTokens(c *gin.Context, rawJson []byte) {
|
|||||||
log.Debugf("Request use account: %s, project id: %s", cliClient.GetEmail(), cliClient.GetProjectID())
|
log.Debugf("Request use account: %s, project id: %s", cliClient.GetEmail(), cliClient.GetProjectID())
|
||||||
|
|
||||||
template := `{"request":{}}`
|
template := `{"request":{}}`
|
||||||
template, _ = sjson.SetRaw(template, "request", gjson.GetBytes(rawJson, "generateContentRequest").Raw)
|
if gjson.GetBytes(rawJson, "generateContentRequest").Exists() {
|
||||||
template, _ = sjson.Delete(template, "generateContentRequest")
|
template, _ = sjson.SetRaw(template, "request", gjson.GetBytes(rawJson, "generateContentRequest").Raw)
|
||||||
|
template, _ = sjson.Delete(template, "generateContentRequest")
|
||||||
|
} else if gjson.GetBytes(rawJson, "contents").Exists() {
|
||||||
|
template, _ = sjson.SetRaw(template, "request.contents", gjson.GetBytes(rawJson, "contents").Raw)
|
||||||
|
template, _ = sjson.Delete(template, "contents")
|
||||||
|
}
|
||||||
rawJson = []byte(template)
|
rawJson = []byte(template)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,6 +291,9 @@ func (h *APIHandlers) geminiCountTokens(c *gin.Context, rawJson []byte) {
|
|||||||
c.Status(err.StatusCode)
|
c.Status(err.StatusCode)
|
||||||
_, _ = c.Writer.Write([]byte(err.Error.Error()))
|
_, _ = c.Writer.Write([]byte(err.Error.Error()))
|
||||||
cliCancel()
|
cliCancel()
|
||||||
|
// log.Debugf(err.Error.Error())
|
||||||
|
// log.Debugf(string(rawJson))
|
||||||
|
// log.Debugf(string(orgRawJson))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -260,7 +260,9 @@ func (c *Client) APIRequest(ctx context.Context, endpoint string, body interface
|
|||||||
if alt == "" && stream {
|
if alt == "" && stream {
|
||||||
url = url + "?alt=sse"
|
url = url + "?alt=sse"
|
||||||
} else {
|
} else {
|
||||||
url = url + fmt.Sprintf("?$alt=%s", alt)
|
if alt != "" {
|
||||||
|
url = url + fmt.Sprintf("?$alt=%s", alt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if endpoint == "countTokens" {
|
if endpoint == "countTokens" {
|
||||||
@@ -272,7 +274,9 @@ func (c *Client) APIRequest(ctx context.Context, endpoint string, body interface
|
|||||||
if alt == "" && stream {
|
if alt == "" && stream {
|
||||||
url = url + "?alt=sse"
|
url = url + "?alt=sse"
|
||||||
} else {
|
} else {
|
||||||
url = url + fmt.Sprintf("?$alt=%s", alt)
|
if alt != "" {
|
||||||
|
url = url + fmt.Sprintf("?$alt=%s", alt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
jsonBody = []byte(gjson.GetBytes(jsonBody, "request").Raw)
|
jsonBody = []byte(gjson.GetBytes(jsonBody, "request").Raw)
|
||||||
systemInstructionResult := gjson.GetBytes(jsonBody, "systemInstruction")
|
systemInstructionResult := gjson.GetBytes(jsonBody, "systemInstruction")
|
||||||
@@ -285,6 +289,7 @@ func (c *Client) APIRequest(ctx context.Context, endpoint string, body interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log.Debug(string(jsonBody))
|
// log.Debug(string(jsonBody))
|
||||||
|
// log.Debug(url)
|
||||||
reqBody := bytes.NewBuffer(jsonBody)
|
reqBody := bytes.NewBuffer(jsonBody)
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, "POST", url, reqBody)
|
req, err := http.NewRequestWithContext(ctx, "POST", url, reqBody)
|
||||||
|
|||||||
Reference in New Issue
Block a user