-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into releases/0.0.50
- Loading branch information
Showing
40 changed files
with
539 additions
and
678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { StreamReponseObject } from '@onlook/models/chat'; | ||
import { type DeepPartial } from 'ai'; | ||
import { Allow, parse } from 'partial-json'; | ||
import { z } from 'zod'; | ||
import { zodToJsonSchema } from 'zod-to-json-schema'; | ||
|
||
export function parseObjectFromText( | ||
text: string, | ||
): DeepPartial<z.infer<typeof StreamReponseObject>> { | ||
const cleanedText = stripFullText(text); | ||
return parse(cleanedText, Allow.ALL) as DeepPartial<z.infer<typeof StreamReponseObject>>; | ||
} | ||
|
||
export function getFormatString() { | ||
const jsonFormat = JSON.stringify(zodToJsonSchema(StreamReponseObject)); | ||
return `\nReturn your response only in this JSON format: <format>${jsonFormat}</format>`; | ||
} | ||
|
||
export function stripFullText(fullText: string) { | ||
let text = fullText; | ||
|
||
if (text.startsWith('```')) { | ||
text = text.slice(3); | ||
} | ||
|
||
if (text.startsWith('```json\n')) { | ||
text = text.slice(8); | ||
} | ||
|
||
if (text.endsWith('```')) { | ||
text = text.slice(0, -3); | ||
} | ||
return text; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
import type { MessageParam } from '@anthropic-ai/sdk/resources/messages'; | ||
import { MainChannels } from '@onlook/models/constants'; | ||
import type { CoreMessage } from 'ai'; | ||
import { ipcMain } from 'electron'; | ||
import Chat from '../chat'; | ||
import { MainChannels } from '@onlook/models/constants'; | ||
|
||
export function listenForChatMessages() { | ||
ipcMain.handle(MainChannels.SEND_CHAT_MESSAGES, (e: Electron.IpcMainInvokeEvent, args) => { | ||
const messages = args as MessageParam[]; | ||
return Chat.send(messages); | ||
}); | ||
|
||
ipcMain.handle( | ||
MainChannels.SEND_CHAT_MESSAGES_STREAM, | ||
(e: Electron.IpcMainInvokeEvent, args) => { | ||
const { messages, requestId } = args as { messages: MessageParam[]; requestId: string }; | ||
return Chat.stream(messages, requestId); | ||
const { messages, requestId } = args as { messages: CoreMessage[]; requestId: string }; | ||
return Chat.stream(messages); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.