Skip to content

Conversation

@ILDaviz
Copy link
Member

@ILDaviz ILDaviz commented Sep 21, 2025

New AI-powered code autocomplete feature, leveraging the OpenRouter provider. This allows users to receive real-time code suggestions directly in the editor, enhancing productivity and the development experience.

New Additions and Main Changes:

  • OpenRouter Integration: A system has been implemented to connect to OpenRouter and fetch AI models for code autocompletion. This includes API key management and the selection of the desired model.
  • New Settings Section: A new AiAutocompleteSetting.vue view has been added, accessible from the settings page. This interface allows users to: Select "OpenRouter" as the AI provider. Securely enter their API key (it is stored locally). Choose from the available models provided by OpenRouter, which are loaded dynamically.
  • Autocomplete Logic in the Editor: The logic to request and display autocomplete suggestions has been integrated into the Editor.vue component. The request is sent to the OpenRouter API through the main Electron process to ensure the API key is not exposed in the renderer process.
  • State Management: The necessary modifications have been made to the settings store (settingsStore) to save and retrieve the AI configuration, such as the selected provider, model, and API key.

How It Works:

  • The user navigates to Settings > AI Autocomplete.
  • They select "OpenRouter" as the AI provider.
  • They enter their OpenRouter API key.
  • They choose a model from the dynamically loaded list.
  • Upon returning to the PHP editor, as they type, the application sends the code context to the selected AI model.
  • The completion suggestions are then displayed directly in the editor.

This feature has been designed to be extensible, allowing for the addition of other AI providers in the future.

@ILDaviz
Copy link
Member Author

ILDaviz commented Sep 21, 2025

In this case i'm using the model 4o-mini
Screenshot 2025-09-21 alle 15 57 03

@saeedvaziry
Copy link
Member

This looks awesome. How about copilot?

@ILDaviz
Copy link
Member Author

ILDaviz commented Sep 22, 2025

No api no party 🥲 It's not supported for third-party integration.

@luanfreitasdev
Copy link
Member

If the token is invalid or another error occurs, should we provide feedback to the user, and if so, in what form? 🤔

@ILDaviz
Copy link
Member Author

ILDaviz commented Sep 23, 2025

For me, the simplest solution is to use https://reka-ui.com/docs/components/toast to launch a simple toast.
This notifies the user. Or add a red banner with the usual X to remove the warning.

@saeedvaziry
Copy link
Member

How about just alert('msg')? :)

@ILDaviz
Copy link
Member Author

ILDaviz commented Sep 24, 2025

https://www.youtube.com/watch?v=Psz4F7f5fRU

Basically, the prompt needs to be optimised, because there are cases where it doesn't do what I expect. I need to figure out how to manage the prompt. The idea is to improve the context based on the type of project, whether it is Laravel, Symfony, or something else. Then, it takes the vendor to see what is installed and also sees where the cursor is located.
For example: Is it located in a comment? If so, suggest completing the comment; if it is located after a piece of code, suggest completing that code, and so on. To do this, we need to establish rules for building the context. I don't want to recreate a copilot, but rather create a basic yet solid foundation. I don't want to reinvent the wheel. I'm searching online to see if there is a package or code that already exists so I can understand how they manage it and “adapt” it to our needs. As I find ideas or packages, I will update you.

@ILDaviz ILDaviz changed the title [draft] Add AI Autocomplete functionality with OpenRouter Add AI Autocomplete functionality with OpenRouter Sep 27, 2025
@ILDaviz ILDaviz changed the title Add AI Autocomplete functionality with OpenRouter [test] Add AI Autocomplete functionality with OpenRouter Sep 27, 2025
@ILDaviz
Copy link
Member Author

ILDaviz commented Sep 28, 2025

Okay, that should do it.

The file that defines the contextual AI completion prompt is complete. It works by analyzing the user's position and actions to decide what type of assistance to provide (comment completion, code from comment, and code completion). The main logic doesn't use a single approach but instead routes the request to three different specialized prompts, each optimized for a specific task.

The first case is triggered when the user writes a comment and moves to a new empty line; here, the service understands that the intent is to translate the comment into executable code and uses a prompt focused on "translating" from natural language to PHP. The second case occurs when the cursor is inside an existing comment line; the service selects a prompt specifically designed to continue writing the comment's text in a natural and descriptive way. Finally, if neither of the previous scenarios is active, a default prompt is used the most rigid and technical one whose sole purpose is to complete the current line of code with valid, brief, and precise syntax. This three-prompt strategy allows it to offer much more accurate and relevant suggestions than a generic approach, as each prompt is finely calibrated with specific instructions and examples for its single purpose, distinguishing between code generation, code completion, and comment writing.
They are calibrated to run on Laravel.

@ILDaviz ILDaviz self-assigned this Sep 28, 2025
@ILDaviz ILDaviz changed the title [test] Add AI Autocomplete functionality with OpenRouter Add AI Autocomplete functionality with OpenRouter Sep 29, 2025
@luanfreitasdev
Copy link
Member

Review Notes / Feedback (suggestions)

  • Labels - Simplify and ensure consistency across the interface.
  • Default Provider - Keep OpenRouter selected by default.
  • Provider List - Sort providers in alphabetical order for easier navigation.
Field Current Suggestion
Label AI Autocomplete. AI Completions
Label Openrouter. OpenRouter
Toggle Active Ai Autocomplete Active
Provider AI Provider Provider
Label Seleziona un provider Select the AI provider
Label Openrouter AI Models Models
Label Seleziona un modello Select the AI Model

@luanfreitasdev
Copy link
Member

I've testing again 🙌

id="ai-model"
v-model="settingsStore.settings.aiModelId"
@change="saveSettings()"
placeholder="Select the AI Model"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion for the future: Sort in alphabetical order for easier navigation.

@saeedvaziry
Copy link
Member

@ILDaviz can we make the prompt customizable by the user instead of hard-coding it please?

@saeedvaziry
Copy link
Member

also this
image

@ILDaviz ILDaviz changed the title Add AI Autocomplete functionality with OpenRouter [draft] Add AI Autocomplete functionality with OpenRouter Nov 17, 2025
@saeedvaziry saeedvaziry changed the title [draft] Add AI Autocomplete functionality with OpenRouter Add AI Autocomplete functionality with OpenRouter Dec 6, 2025
@saeedvaziry saeedvaziry changed the title Add AI Autocomplete functionality with OpenRouter Add AI Autocomplete functionalit Dec 6, 2025
@saeedvaziry saeedvaziry changed the title Add AI Autocomplete functionalit Add AI Autocomplete functionality Dec 6, 2025
@saeedvaziry saeedvaziry merged commit fd44289 into tweakphp:main Dec 6, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants