Repository navigation
o1 #4
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
Closed
o1 #4
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3181d20
Use o1 as a coder
jahooma 6caec13
Increase timeout
jahooma 0f35a08
Switch to o1 mini. Also use it to generate patch
jahooma 66ddbe8
fix: change openai response temp to 1, fixed '```' filter issue, adde…
a842553
Produce patch file directly
jahooma aade5fe
Tweaks
jahooma e24e0b5
Markdown file blocks. Streamline prompting
jahooma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,84 @@ | ||
| import { WebSocket } from 'ws' | ||
|
|
||
| import { Message } from 'common/actions' | ||
| import { parseMarkdownPatchBlocks, ProjectFileContext } from 'common/util/file' | ||
| import { getCoderPrompt } from './system-prompt' | ||
| import { assert } from 'common/util/object' | ||
| import { OpenAIMessage, promptOpenAI } from './openai-api' | ||
| import { FileChange } from 'common/actions' | ||
|
|
||
| /** | ||
| * Handles code-related actions by interacting with the AI assistant to generate and apply code changes. | ||
| * | ||
| * The `codeAgent` function serves as the primary handler for processing user instructions related to code modifications. | ||
| * It leverages the AI assistant to interpret user requests, generate appropriate responses, and apply necessary changes | ||
| * to the codebase in a context-aware manner. | ||
| * | ||
| * Steps involved: | ||
| * 1. Constructs a prompt using the system-generated coder prompt and the latest user message. | ||
| * 2. Sends the prompt to the OpenAI API to generate a response. | ||
| * 3. Processes the AI's response by removing unnecessary markdown syntax. | ||
| * 4. Parses the response into file blocks and generates corresponding file changes. | ||
| * 5. Applies the generated patches to the relevant files. | ||
| * | ||
| * @param userId - The unique identifier of the user initiating the code action. | ||
| * @param fileContext - An object representing the current context of project files, including their contents. | ||
| * @param messages - An array of user and assistant messages exchanged in the current session. | ||
| * @param ws - The WebSocket connection instance for real-time communication with the client. | ||
| * @param onResponseChunk - A callback function to handle chunks of the AI assistant's response as they are received. | ||
| * @returns An object containing the AI assistant's full response and the list of file changes generated. | ||
| * | ||
| * @throws Will throw an error if the OpenAI API request fails or returns an unexpected response. | ||
| */ | ||
| export const codeAgent = async ( | ||
| userId: string, | ||
| fileContext: ProjectFileContext, | ||
| messages: Message[], | ||
| ws: WebSocket, | ||
| onResponseChunk: (chunk: string) => void | ||
| ) => { | ||
| const coderPrompt = getCoderPrompt(fileContext, { | ||
| checkFiles: true, | ||
| }) | ||
| const lastMessage = messages[messages.length - 1] | ||
| assert(lastMessage.role === 'user', 'Last message must be from user') | ||
| assert( | ||
| typeof lastMessage.content === 'string', | ||
| 'Last user message must be text' | ||
| ) | ||
|
|
||
| const infoPrompt = `Please use the above information to answer the user's question:` | ||
| const content = [coderPrompt, infoPrompt, lastMessage.content].join('\n\n') | ||
|
|
||
| const messagesWithContext = [ | ||
| ...messages.slice(0, -1), | ||
| { | ||
| ...lastMessage, | ||
| content, | ||
| }, | ||
| ] as OpenAIMessage[] | ||
|
|
||
| onResponseChunk('Generating response with o1-preview...\n\n') | ||
|
|
||
| const response = await promptOpenAI( | ||
| userId, | ||
| messagesWithContext, | ||
| 'o1-preview', | ||
| { | ||
| temperature: 1, | ||
| } | ||
| ) | ||
|
|
||
| onResponseChunk(response + '\n') | ||
| console.log('response', response) | ||
| const patches = parseMarkdownPatchBlocks(response) | ||
| const changes: FileChange[] = patches.map(({ filePath, patch }) => ({ | ||
| filePath, | ||
| content: patch, | ||
| type: 'patch', | ||
| })) | ||
|
|
||
| console.log('changes', changes) | ||
|
|
||
| return { response, changes } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code looks familiar... o.o