Skip to content

Commit

Permalink
Fix indentation and formatting issues in multiple files.
Browse files Browse the repository at this point in the history
  • Loading branch information
swuecho committed Sep 13, 2024
1 parent b0db0b8 commit 39ea534
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 36 deletions.
50 changes: 25 additions & 25 deletions api/chat_main_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,31 +546,33 @@ func (h *ChatHandler) chatStream(w http.ResponseWriter, chatSession sqlc_queries
if regenerate {
answer_id = chatUuid
}

for {
response, err := stream.Recv()
if errors.Is(err, io.EOF) {
// send the last message
if len(answer) > 0 {
final_resp := constructChatCompletionStreamReponse(answer_id, answer)
data, _ := json.Marshal(final_resp)
fmt.Fprintf(w, "data: %v\n\n", string(data))
flusher.Flush()
}
if chatSession.Debug {
req_j, _ := json.Marshal(openai_req)
log.Println(string(req_j))
answer = answer + "\n" + string(req_j)
req_as_resp := constructChatCompletionStreamReponse(answer_id, answer)
data, _ := json.Marshal(req_as_resp)
fmt.Fprintf(w, "data: %v\n\n", string(data))
flusher.Flush()
}
break
}
if err != nil {
RespondWithError(w, http.StatusInternalServerError, fmt.Sprintf("Stream error: %v", err), nil)
return "", "", true
if errors.Is(err, io.EOF) {
// send the last message
if len(answer) > 0 {
final_resp := constructChatCompletionStreamReponse(answer_id, answer)
data, _ := json.Marshal(final_resp)
fmt.Fprintf(w, "data: %v\n\n", string(data))
flusher.Flush()
}
if chatSession.Debug {
req_j, _ := json.Marshal(openai_req)
log.Println(string(req_j))
answer = answer + "\n" + string(req_j)
req_as_resp := constructChatCompletionStreamReponse(answer_id, answer)
data, _ := json.Marshal(req_as_resp)
fmt.Fprintf(w, "data: %v\n\n", string(data))
flusher.Flush()
}
return answer, answer_id, false
} else {
log.Printf("%v", err)
RespondWithError(w, http.StatusInternalServerError, fmt.Sprintf("Stream error: %v", err), nil)
return "", "", true
}
}
textIdx := response.Choices[0].Index
delta := response.Choices[0].Delta.Content
Expand All @@ -592,7 +594,6 @@ func (h *ChatHandler) chatStream(w http.ResponseWriter, chatSession sqlc_queries
flusher.Flush()
}
}
return answer, answer_id, false
}

func (h *ChatHandler) CompletionStream(w http.ResponseWriter, chatSession sqlc_queries.ChatSession, chat_compeletion_messages []models.Message, chatUuid string, regenerate bool, streamOutput bool) (string, string, bool) {
Expand All @@ -617,7 +618,6 @@ func (h *ChatHandler) CompletionStream(w http.ResponseWriter, chatSession sqlc_q
return "", "", true
}


client := openai.NewClientWithConfig(config)
// latest message contents
prompt := chat_compeletion_messages[len(chat_compeletion_messages)-1].Content
Expand Down Expand Up @@ -1466,7 +1466,7 @@ func (h *ChatHandler) chatStreamGemini(w http.ResponseWriter, chatSession sqlc_q
if err != nil {
if errors.Is(err, io.EOF) {
fmt.Println("End of stream reached")
break
return answer, answer_id, false
} else {
fmt.Printf("Error while reading response: %+v", err)
return "", "", true
Expand Down
2 changes: 1 addition & 1 deletion api/chat_snapshot_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (h *ChatSnapshotHandler) CreateChatSnapshot(w http.ResponseWriter, r *http.
RespondWithError(w, http.StatusInternalServerError, err.Error(), err)
return
}
uuid, err := h.service.CreateChatSnapshot(r.Context(), chatSessionUuid, user_id)
uuid, err := h.service.CreateChatSnapshot(r.Context(), chatSessionUuid, user_id)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, err.Error(), err)
}
Expand Down
1 change: 0 additions & 1 deletion api/chat_snapshot_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (s *ChatSnapshotService) CreateChatSnapshot(ctx context.Context, chatSessio

}


func (s *ChatSnapshotService) CreateChatBot(ctx context.Context, chatSessionUuid string, userId int32) (string, error) {
chatSession, err := s.q.GetChatSessionByUUID(ctx, chatSessionUuid)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions api/llm/gemini/gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func (p PartBlob) toPart() string {
return fmt.Sprintf("data:%s;base64,%s", b.MIMEType, b.Data)
}


// from https://github.com/google/generative-ai-go/blob/main/genai/generativelanguagepb_veneer.gen.go#L56
// Blob contains raw media bytes.
//
Expand All @@ -65,8 +64,6 @@ func ImageData(mimeType string, data []byte) Blob {
}
}



type GeminiMessage struct {
Role string `json:"role"`
Parts []Part `json:"parts"`
Expand Down Expand Up @@ -169,7 +166,7 @@ func GenGemminPayload(chat_compeletion_messages []models.Message, chatFiles []sq
if imageExt.Contains(chatFile.MimeType) {
return &PartBlob{Blob: ImageData(chatFile.MimeType, chatFile.Data)}
} else {
return &PartString{Text: "file: " + chatFile.Name + "\n<<<"+ string(chatFile.Data) + ">>>\n"}
return &PartString{Text: "file: " + chatFile.Name + "\n<<<" + string(chatFile.Data) + ">>>\n"}
}
})
fmt.Printf("partsFromFiles: %+v\n", partsFromFiles)
Expand Down
8 changes: 4 additions & 4 deletions api/middleware_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func AdminOnlyHandlerFunc(handlerFunc http.HandlerFunc) http.HandlerFunc {

func IsAuthorizedMiddleware(handler http.Handler) http.Handler {
noAuthPaths := map[string]bool{
"/": true,
"/": true,
"/favicon.ico": true,
"/api/login": true,
"/api/signup": true,
"/api/tts": true,
"/api/login": true,
"/api/signup": true,
"/api/tts": true,
}
jwtSigningKey := []byte(jwtSecretAndAud.Secret)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
1 change: 0 additions & 1 deletion api/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ func (m *Message) SetTokenCount(tokenCount int32) *Message {
m.tokenCount = tokenCount
return m
}

0 comments on commit 39ea534

Please sign in to comment.