Fix bugs and add Gemini API compatibility#57
Conversation
The provider config was being set to 'config' instead of 'l:config', causing the user's configuration to not be properly passed to the provider script. This bug affects all Neural users as the local variable l:config is never assigned to the provider, resulting in incorrect or default configuration being used.
In the Config initialization, frequency_penalty was incorrectly being set to the value of presence_penalty instead of frequency_penalty. This bug causes frequency_penalty to always equal presence_penalty, regardless of the user's configuration.
Some OpenAI-compatible APIs (like Google's Gemini) don't support presence_penalty and frequency_penalty parameters at all, even when set to 0. This change makes Neural only include these parameters in the API request when they are non-zero, improving compatibility with a wider range of OpenAI-compatible API providers. Tested with: - Gemini API: Works with penalties=0 (excluded from request) - OpenAI API: Works with non-zero penalties (included in request)
|
I appreciate the effort here and I encourage you to maintain your own fork. @Angelchev and I have recently started work on a complete rewrite of Neural probably absolutely loaded with breaking changes that'll be much better. I'll be replaying all of the commits for the brand new version on top of this repository and see what we can do to make the existing commands work or not in the new plugins. We're planning on shipping two separate plugins for Vim and Neovim that use Vim9script and Lua respectively, with a FOSS compiled Zig middleware. Can't say when it will be ready, but hopefully later this year. |
|
Having shared the above, if/when you mark this ready for review I will merge it. |
|
oh - looks like you're right, this diff got Gemini working for me but looks like supporting all the features is a different beast altogether. looking forward to the rewrite then!! i don't see a lot of LLM-related plugins for good old Vim for some reason. please feel free to close the PR. (and btw, why not mention the coming update in the readme?) |
We will tell everyone soon enough! We've been rapidly developing a new version where the shape of it keeps changing. |
Summary
This PR fixes three bugs in Neural and adds compatibility with OpenAI-compatible APIs that don't support penalty parameters (e.g., Google Gemini).
Changes
1. Fix undefined variable in
s:LoadProvider()File:
autoload/neural.vim:250User configuration was not being passed to the provider script due to using
configinstead ofl:config.2. Fix
frequency_penaltytypoFile:
src/neural/provider/openai.py:209frequency_penaltywas being set topresence_penaltyvalue instead of its own value.3. Make penalty parameters optional
File:
src/neural/provider/openai.py:60-68Some OpenAI-compatible APIs (like Gemini) don't support penalty parameters and return 400 errors even when they're set to 0. This change only includes penalty parameters in the request when they're non-zero.
Testing
Gemini Configuration Example