Skip to content

Fix bugs and add Gemini API compatibility#57

Open
realshovanshah wants to merge 3 commits into
dense-analysis:mainfrom
realshovanshah:fix/gemini-compatibility-and-bugs
Open

Fix bugs and add Gemini API compatibility#57
realshovanshah wants to merge 3 commits into
dense-analysis:mainfrom
realshovanshah:fix/gemini-compatibility-and-bugs

Conversation

@realshovanshah
Copy link
Copy Markdown

@realshovanshah realshovanshah commented May 5, 2026

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:250

User configuration was not being passed to the provider script due to using config instead of l:config.

- let l:provider.config = config
+ let l:provider.config = l:config

2. Fix frequency_penalty typo

File: src/neural/provider/openai.py:209

frequency_penalty was being set to presence_penalty value instead of its own value.

- frequency_penalty=presence_penalty,
+ frequency_penalty=frequency_penalty,

3. Make penalty parameters optional

File: src/neural/provider/openai.py:60-68

Some 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

  • Verified all three fixes resolve the issues
  • Tested with Gemini API: works with penalties=0 (excluded from request)
  • Tested backward compatibility: OpenAI still works with non-zero penalties

Gemini Configuration Example

let g:neural = {
\   'providers': [
\       {
\           'type': 'openai',
\           'url': 'https://generativelanguage.googleapis.com/v1beta/openai',
\           'api_key': $GEMINI_API_KEY,
\           'model': 'gemini-2.5-flash',
\           'use_chat_api': v:true,
\           'presence_penalty': 0,
\           'frequency_penalty': 0,
\       },
\   ],
\}

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)
@w0rp
Copy link
Copy Markdown
Member

w0rp commented May 5, 2026

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.

@w0rp
Copy link
Copy Markdown
Member

w0rp commented May 5, 2026

Having shared the above, if/when you mark this ready for review I will merge it.

@realshovanshah
Copy link
Copy Markdown
Author

realshovanshah commented May 12, 2026

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?)

@w0rp
Copy link
Copy Markdown
Member

w0rp commented May 12, 2026

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.

@realshovanshah realshovanshah marked this pull request as ready for review May 16, 2026 00:40
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.

2 participants