In this repo, where does it make the AI requests, so that I can edit and make it…
- User
In this repo, where does it make the AI requests, so that I can edit and make it compatible with local models?
Assistant
Okay, let's trace where the AI requests are made in this repository. Based on the provided files, the core logic for sending messages to the AI and handling responses resides within the
ChatManagerclass, specifically thesendChatToAiandsendStreamRequestmethods.Here's a breakdown:
-
apps/studio/src/lib/editor/engine/chat/index.ts: This file contains theChatManagerclass, which is the central point for managing chat interactions.sendChatToAi()method: This method orchestrates the process of sending a message to the AI. It does the following:- Sets
isWaitingto true. - Retrieves the messages to send from the current conversation using
this.conversation.current.getMessagesForStream(). - Calls
this.sendStreamRequest()to actually send the messages to the backend. - Clears the stream using
this.stream.clear(). - Sets
isWaitingto false. - Calls
this.handleChatResponse()to process the response.
- Sets
sendStreamRequest()method: This method is responsible for making the actual request to the backend. It usesinvokeMainChannelwithMainChannels.SEND_CHAT_MESSAGES_STREAMto send the messages and a uniquerequestId. This is the key point where the request is sent to the main process.
-
apps/studio/src/lib/utils.ts: This file contains theinvokeMainChannelfunction. This function is used to send messages to the main process, which is where the actual AI request is made. -
packages/models/src/constants.ts: This file defines theMainChannels.SEND_CHAT_MESSAGES_STREAMconstant. This constant is used as the channel name for the message sent to the main process.
How to modify for local models:
To make the AI requests compatible with local models, you'll need to modify the main process code that receives the message sent via
invokeMainChannelwith theMainChannels.SEND_CHAT_MESSAGES_STREAM.Based on the code, here is what you should do:
- Locate the main process code: You'll need to find the code in the main process (likely in the
electronpart of the application) that handles the message. It's not included in the files you provided.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.