Skip to content

Commit 46a80d4

Browse files
authored
Align artifact API docs and extend firstN edge-case tests (#747)
1 parent d277fb3 commit 46a80d4

5 files changed

Lines changed: 19 additions & 29 deletions

File tree

api/chat_session_service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestChatSessionService(t *testing.T) {
4646
}
4747

4848
// Check that updated chat session matches expected values
49-
// TODO: timezone time || !retrievedSession.UpdatedAt.Equal(updated_params.UpdatedAt)
49+
// UpdatedAt is generated by the database; verify updated fields instead of strict timestamp equality.
5050
if retrievedSession.Topic != updated_params.Topic {
5151
t.Errorf("chat session mismatch: expected Topic=%s, got Topic=%s ",
5252
updated_params.Topic, retrievedSession.Topic)

api/model_gemini_service.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ func (m *GeminiChatModel) Stream(w http.ResponseWriter, chatSession sqlc_queries
8383

8484
llmAnswer, err := gemini.HandleRegularResponse(*m.client.client, req)
8585
if err != nil {
86-
return nil, ErrInternalUnexpected.WithMessage("Failed to generate regular resposne").WithDebugInfo(err.Error())
86+
return nil, ErrInternalUnexpected.WithMessage("Failed to generate regular response").WithDebugInfo(err.Error())
8787
}
88-
if llmAnswer != nil {
89-
llmAnswer.AnswerId = answerID
88+
if llmAnswer == nil {
89+
return nil, ErrInternalUnexpected.WithMessage("Empty response from Gemini")
9090
}
91+
92+
llmAnswer.AnswerId = answerID
9193
response := constructChatCompletionStreamResponse(answerID, llmAnswer.Answer)
9294
data, _ := json.Marshal(response)
9395
fmt.Fprint(w, string(data))

api/util_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ func Test_firstN(t *testing.T) {
1414
}{
1515
{"01", args{"hello", 2}, "he"},
1616
{"02", args{"hello", 5}, "hello"},
17-
{"02", args{"hello", 50}, "hello"},
17+
{"03", args{"hello", 50}, "hello"},
18+
{"04", args{"你好世界", 2}, "你好"},
19+
{"05", args{"", 3}, ""},
20+
{"06", args{"hello", 0}, ""},
21+
{"07", args{"🙂🙃", 1}, "🙂"},
1822
}
1923
for _, tt := range tests {
2024
t.Run(tt.name, func(t *testing.T) {

docs/artifact_gallery_en.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,12 @@ The gallery integrates with the chat application's API:
233233

234234
```javascript
235235
// Example: Getting artifacts from a specific session
236-
const artifacts = await fetch(`/api/chat/sessions/${sessionId}/artifacts`);
236+
const messages = await fetch(`/api/uuid/chat_messages/chat_sessions/${sessionId}`);
237+
// Artifacts are included in each message payload as the `artifacts` field
237238

238239
// Example: Executing code artifact
239-
const result = await fetch(`/api/artifacts/${artifactId}/execute`, {
240-
method: 'POST',
241-
headers: {
242-
'Content-Type': 'application/json',
243-
'Authorization': `Bearer ${token}`
244-
},
245-
body: JSON.stringify({
246-
code: artifactContent,
247-
language: 'javascript'
248-
})
249-
});
240+
// Code execution is handled client-side in Artifact Editor/Sandbox components,
241+
// not by a dedicated backend `/api/artifacts/:id/execute` endpoint.
250242
```
251243

252244
## Future Enhancements

docs/artifact_gallery_zh.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,12 @@
233233

234234
```javascript
235235
// 示例:从特定会话获取制品
236-
const artifacts = await fetch(`/api/chat/sessions/${sessionId}/artifacts`);
236+
const messages = await fetch(`/api/uuid/chat_messages/chat_sessions/${sessionId}`);
237+
// 制品包含在每条消息的 `artifacts` 字段中
237238

238239
// 示例:执行代码制品
239-
const result = await fetch(`/api/artifacts/${artifactId}/execute`, {
240-
method: 'POST',
241-
headers: {
242-
'Content-Type': 'application/json',
243-
'Authorization': `Bearer ${token}`
244-
},
245-
body: JSON.stringify({
246-
code: artifactContent,
247-
language: 'javascript'
248-
})
249-
});
240+
// 代码执行由前端的 Artifact Editor/Sandbox 组件处理,
241+
// 后端没有独立的 `/api/artifacts/:id/execute` 接口。
250242
```
251243

252244
## 未来增强

0 commit comments

Comments
 (0)