Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: new thread isn't automatically created on factory reset #4295

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/browser/extensions/engines/OAIEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
*/
override async inference(data: MessageRequest) {
if (!data.model?.id) {
events.emit(MessageEvent.OnMessageResponse, {

Check warning on line 59 in core/src/browser/extensions/engines/OAIEngine.ts

View workflow job for this annotation

GitHub Actions / coverage-check

59 line is not covered with tests
status: MessageStatus.Error,
content: [
{
Expand All @@ -68,10 +68,10 @@
},
],
})
return

Check warning on line 71 in core/src/browser/extensions/engines/OAIEngine.ts

View workflow job for this annotation

GitHub Actions / coverage-check

71 line is not covered with tests
}

const timestamp = Date.now()
const timestamp = Date.now() / 1000
const message: ThreadMessage = {
id: ulid(),
thread_id: data.threadId,
Expand Down Expand Up @@ -105,7 +105,7 @@
...model.parameters,
}
if (this.transformPayload) {
requestBody = this.transformPayload(requestBody)

Check warning on line 108 in core/src/browser/extensions/engines/OAIEngine.ts

View workflow job for this annotation

GitHub Actions / coverage-check

108 line is not covered with tests
}

requestInference(
Expand Down Expand Up @@ -133,9 +133,9 @@
},
error: async (err: any) => {
if (this.isCancelled || message.content.length) {
message.status = MessageStatus.Stopped
events.emit(MessageEvent.OnMessageUpdate, message)
return

Check warning on line 138 in core/src/browser/extensions/engines/OAIEngine.ts

View workflow job for this annotation

GitHub Actions / coverage-check

136-138 lines are not covered with tests
}
message.status = MessageStatus.Error
message.content[0] = {
Expand Down Expand Up @@ -163,6 +163,6 @@
* Headers for the inference request
*/
async headers(): Promise<HeadersInit> {
return {}

Check warning on line 166 in core/src/browser/extensions/engines/OAIEngine.ts

View workflow job for this annotation

GitHub Actions / coverage-check

166 line is not covered with tests
}
}
2 changes: 1 addition & 1 deletion extensions/assistant-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class JanAssistantExtension extends AssistantExtension {
thread_location: undefined,
id: 'jan',
object: 'assistant',
created_at: Date.now(),
created_at: Date.now() / 1000,
name: 'Jan',
description: 'A default assistant that can use all downloaded models',
model: '*',
Expand Down
3 changes: 3 additions & 0 deletions web/containers/Providers/ModelHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ export default function ModelHandler() {
if (updatedMessage) {
deleteMessage(message.id)
addNewMessage(updatedMessage)
setTokenSpeed((prev) =>
prev ? { ...prev, message: updatedMessage.id } : undefined
)
}
})()

Expand Down
3 changes: 2 additions & 1 deletion web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
const MessageContainer: React.FC<
ThreadMessage & { isCurrentMessage: boolean }
> = (props) => {
const isUser = props.role === ChatCompletionRole.User
const isSystem = props.role === ChatCompletionRole.System
const editMessage = useAtomValue(editMessageAtom)
const activeAssistant = useAtomValue(activeAssistantAtom)
const tokenSpeed = useAtomValue(tokenSpeedAtom)
const chatWidth = useAtomValue(chatWidthAtom)

Check warning on line 36 in web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

31-36 lines are not covered with tests

const text = useMemo(

Check warning on line 38 in web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

38 line is not covered with tests
() =>
props.content.find((e) => e.type === ContentType.Text)?.text?.value ?? '',

Check warning on line 40 in web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

40 line is not covered with tests
[props.content]
)

const image = useMemo(

Check warning on line 44 in web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

44 line is not covered with tests
() =>
props.content.find((e) => e.type === ContentType.Image)?.image_url?.url,

Check warning on line 46 in web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

46 line is not covered with tests
[props.content]
)

Expand Down Expand Up @@ -91,7 +91,8 @@
: (activeAssistant?.assistant_name ?? props.role)}
</div>
<p className="text-xs font-medium text-gray-400">
{props.created_at && displayDate(props.created_at ?? new Date())}
{props.created_at &&
displayDate(props.created_at ?? Date.now() / 1000)}
</p>
</div>

Expand Down
5 changes: 3 additions & 2 deletions web/screens/Thread/ThreadLeftPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const ThreadLeftPanel = () => {
useEffect(() => {
if (
threadDataReady &&
activeAssistant &&
assistants.length > 0 &&
threads.length === 0 &&
downloadedModels.length > 0
Expand All @@ -81,7 +80,9 @@ const ThreadLeftPanel = () => {
)
const selectedModel = model[0] || recommendedModel
requestCreateNewThread(
{ ...assistants[0], ...activeAssistant },
activeAssistant
? { ...assistants[0], ...activeAssistant }
: assistants[0],
selectedModel
)
} else if (threadDataReady && !activeThreadId) {
Expand Down
8 changes: 2 additions & 6 deletions web/utils/datetime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { isToday } from './datetime'
test("should return only time for today's timestamp", () => {
const today = new Date()
const timestamp = today.getTime()
const expectedTime = `${today.toLocaleDateString(undefined, {
day: '2-digit',
month: 'short',
year: 'numeric',
})}, ${today.toLocaleTimeString(undefined, {
const expectedTime = `${today.toLocaleTimeString(undefined, {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
Expand All @@ -24,5 +20,5 @@ test('should return N/A for undefined timestamp', () => {
test("should return true for today's timestamp", () => {
const today = new Date()
const timestamp = today.setHours(0, 0, 0, 0)
expect(isToday(timestamp)).toBe(true)
expect(isToday(timestamp / 1000)).toBe(true)
})
5 changes: 4 additions & 1 deletion web/utils/datetime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const isToday = (timestamp: number) => {
const today = new Date()
return today.setHours(0, 0, 0, 0) === new Date(timestamp).setHours(0, 0, 0, 0)
return (
today.setHours(0, 0, 0, 0) ===
new Date(timestamp * 1000).setHours(0, 0, 0, 0)
)
}

export const displayDate = (timestamp?: string | number | Date) => {
Expand Down
2 changes: 1 addition & 1 deletion web/utils/messageRequestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ulid } from 'ulidx'

import { Stack } from '@/utils/Stack'

import { FileInfo, FileType } from '@/types/file'
import { FileInfo } from '@/types/file'

export class MessageRequestBuilder {
msgId: string
Expand Down
2 changes: 1 addition & 1 deletion web/utils/threadMessageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ThreadMessageBuilder {
}

build(): ThreadMessage {
const timestamp = Date.now()
const timestamp = Date.now() / 1000
return {
id: this.messageRequest.msgId,
thread_id: this.messageRequest.thread.id,
Expand Down
Loading