Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Commit

Permalink
skip repeats
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed Jun 9, 2023
1 parent 85ab37b commit 919e4dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/chatgpt/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func Handler(c *gin.Context, response *http.Response, token string, translated_r
}
var finish_reason string
var original_response chatgpt_types.ChatGPTResponse
counter := 0
for {
line, err := reader.ReadString('\n')
if err != nil {
Expand All @@ -175,12 +176,18 @@ func Handler(c *gin.Context, response *http.Response, token string, translated_r

err = json.Unmarshal([]byte(line), &original_response)
if err != nil {
println("Failed to parse JSON")
continue
}
if original_response.Error != nil {
c.JSON(500, gin.H{"error": original_response.Error})
return "", nil
}
if original_response.Message.Author.Role != "assistant" || original_response.Message.Content.Parts == nil || original_response.Message.Metadata.Timestamp == "absolute" {
if original_response.Message.Author.Role != "assistant" || original_response.Message.Content.Parts == nil {
continue
}
if counter < 3 {
counter++
continue
}
response_string := chatgpt_response_converter.ConvertToString(&original_response)
Expand Down
2 changes: 2 additions & 0 deletions typings/chatgpt/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Metadata struct {
Timestamp string `json:"timestamp_"`
MessageType string `json:"message_type"`
FinishDetails *FinishDetails `json:"finish_details"`
ModelSlug string `json:"model_slug"`
Recipient string `json:"recipient"`
}

type FinishDetails struct {
Expand Down

0 comments on commit 919e4dd

Please sign in to comment.