diff --git a/api/chat_session_service_test.go b/api/chat_session_service_test.go index e3b4d408..76e22b6e 100644 --- a/api/chat_session_service_test.go +++ b/api/chat_session_service_test.go @@ -46,7 +46,7 @@ func TestChatSessionService(t *testing.T) { } // Check that updated chat session matches expected values - // TODO: timezone time || !retrievedSession.UpdatedAt.Equal(updated_params.UpdatedAt) + // UpdatedAt is generated by the database; verify updated fields instead of strict timestamp equality. if retrievedSession.Topic != updated_params.Topic { t.Errorf("chat session mismatch: expected Topic=%s, got Topic=%s ", updated_params.Topic, retrievedSession.Topic) diff --git a/api/model_gemini_service.go b/api/model_gemini_service.go index f7abcb5d..77acb371 100644 --- a/api/model_gemini_service.go +++ b/api/model_gemini_service.go @@ -83,11 +83,13 @@ func (m *GeminiChatModel) Stream(w http.ResponseWriter, chatSession sqlc_queries llmAnswer, err := gemini.HandleRegularResponse(*m.client.client, req) if err != nil { - return nil, ErrInternalUnexpected.WithMessage("Failed to generate regular resposne").WithDebugInfo(err.Error()) + return nil, ErrInternalUnexpected.WithMessage("Failed to generate regular response").WithDebugInfo(err.Error()) } - if llmAnswer != nil { - llmAnswer.AnswerId = answerID + if llmAnswer == nil { + return nil, ErrInternalUnexpected.WithMessage("Empty response from Gemini") } + + llmAnswer.AnswerId = answerID response := constructChatCompletionStreamResponse(answerID, llmAnswer.Answer) data, _ := json.Marshal(response) fmt.Fprint(w, string(data)) diff --git a/api/util_test.go b/api/util_test.go index d17a915d..51cc0012 100644 --- a/api/util_test.go +++ b/api/util_test.go @@ -14,7 +14,11 @@ func Test_firstN(t *testing.T) { }{ {"01", args{"hello", 2}, "he"}, {"02", args{"hello", 5}, "hello"}, - {"02", args{"hello", 50}, "hello"}, + {"03", args{"hello", 50}, "hello"}, + {"04", args{"你好世界", 2}, "你好"}, + {"05", args{"", 3}, ""}, + {"06", args{"hello", 0}, ""}, + {"07", args{"🙂🙃", 1}, "🙂"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/docs/artifact_gallery_en.md b/docs/artifact_gallery_en.md index 625ce0ed..75a3b394 100644 --- a/docs/artifact_gallery_en.md +++ b/docs/artifact_gallery_en.md @@ -233,20 +233,12 @@ The gallery integrates with the chat application's API: ```javascript // Example: Getting artifacts from a specific session -const artifacts = await fetch(`/api/chat/sessions/${sessionId}/artifacts`); +const messages = await fetch(`/api/uuid/chat_messages/chat_sessions/${sessionId}`); +// Artifacts are included in each message payload as the `artifacts` field // Example: Executing code artifact -const result = await fetch(`/api/artifacts/${artifactId}/execute`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${token}` - }, - body: JSON.stringify({ - code: artifactContent, - language: 'javascript' - }) -}); +// Code execution is handled client-side in Artifact Editor/Sandbox components, +// not by a dedicated backend `/api/artifacts/:id/execute` endpoint. ``` ## Future Enhancements diff --git a/docs/artifact_gallery_zh.md b/docs/artifact_gallery_zh.md index 1f3a2bea..4cf77c95 100644 --- a/docs/artifact_gallery_zh.md +++ b/docs/artifact_gallery_zh.md @@ -233,20 +233,12 @@ ```javascript // 示例:从特定会话获取制品 -const artifacts = await fetch(`/api/chat/sessions/${sessionId}/artifacts`); +const messages = await fetch(`/api/uuid/chat_messages/chat_sessions/${sessionId}`); +// 制品包含在每条消息的 `artifacts` 字段中 // 示例:执行代码制品 -const result = await fetch(`/api/artifacts/${artifactId}/execute`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${token}` - }, - body: JSON.stringify({ - code: artifactContent, - language: 'javascript' - }) -}); +// 代码执行由前端的 Artifact Editor/Sandbox 组件处理, +// 后端没有独立的 `/api/artifacts/:id/execute` 接口。 ``` ## 未来增强