mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-09-07 17:58:55 +08:00
Port agent PRs to GO - 5 (#16667)
### Summary Port https://github.com/infiniflow/ragflow/pull/15376 https://github.com/infiniflow/ragflow/pull/16401 https://github.com/infiniflow/ragflow/pull/15484 https://github.com/infiniflow/ragflow/pull/16685
This commit is contained in:
@@ -78,7 +78,7 @@ type OpenAICompletionResponse struct {
|
||||
PromptTokens int
|
||||
CompletionTokens int
|
||||
TotalTokens int
|
||||
Created int64
|
||||
Created *int64
|
||||
}
|
||||
|
||||
// OpenAIStreamEventKind discriminates stream events.
|
||||
@@ -434,7 +434,6 @@ func (s *OpenAIChatService) OpenAIChatCompletions(c *gin.Context, userID, chatID
|
||||
content := strings.TrimSpace(finalResult.Answer)
|
||||
completionTokens := tokenizer.NumTokensFromString(content)
|
||||
resp := &OpenAICompletionResponse{
|
||||
Created: time.Now().Unix(),
|
||||
Model: openaiReq.Model,
|
||||
Content: content,
|
||||
PromptTokens: promptTokens,
|
||||
@@ -473,7 +472,7 @@ func (s *OpenAIChatService) OpenAIChatCompletions(c *gin.Context, userID, chatID
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"id": completionID,
|
||||
"object": "chat.completion",
|
||||
"created": resp.Created,
|
||||
"created": getCreatedOrDefault(resp.Created),
|
||||
"model": resp.Model,
|
||||
"usage": gin.H{
|
||||
"prompt_tokens": resp.PromptTokens,
|
||||
@@ -836,3 +835,10 @@ func (s *OpenAIChatService) writeArgError(c *gin.Context, msg string) {
|
||||
func (s *OpenAIChatService) writeDataError(c *gin.Context, msg string) {
|
||||
common.ResponseWithCodeData(c, common.CodeDataError, nil, msg)
|
||||
}
|
||||
|
||||
func getCreatedOrDefault(created *int64) int64 {
|
||||
if created != nil {
|
||||
return *created
|
||||
}
|
||||
return time.Now().Unix()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user