tak-bro / aicommit2

A Reactive CLI that generates git commit messages with Ollama, ChatGPT, Gemini, Claude, Mistral and other AI
https://www.npmjs.com/package/aicommit2
MIT License
77 stars 4 forks source link

Support for Codestral #48

Closed bhodrolok closed 6 days ago

bhodrolok commented 1 week ago

Feature request

Thanks for making this tool! Been enjoying tinkering around with it.

I think aicommit2 can be further extended to support Mistral AI's new coding-focused genAI model, Codestral.

Why?

Codestral is a 22 billion parameter model, which was released end of last month by Mistral AI, which is optimized for assisting developers. Cool thing about this model is that the API, available at codestral.mistral.ai, is free to use/consume until August 1. Additionally it will give the user another option in terms of choosing a different model for selecting the generated commit message.

Alternatives

I tried to implement the feature myself and managed to get it working, albeit in a hacky way. Here is the repo with my changes: https://github.com/bhodrolok/aicommit2-codestral

The main thing I noticed is that the API key for using Codestral is different from the one used for Mistral AI's other models. Also there is no endpoint for listing all available Mistral AI models for the main Codestral domain (codestral.mistral.ai) and as such the regular Mistral AI domain (api.mistral.ai) has to be used (alongside the regular API key MISTRAL_KEY).

I have been trying to refactor it such that it works in a single MistralService class but keep running into the Invalid AI type error.

I can open a PR so you can take a look at it!

Additional context

tak-bro commented 1 week ago

Thank you for your interest in my project and for leaving the issue. I have reviewed your code. I’m not sure about the necessity of the checkAvailableModels function in CodestralService. If it is not strictly needed, it might be better to remove it. In that case, you could also remove the apiKeyMistral variable.

Alternatively, you could modify MistralService to decide whether to use Codestral or Mistral based on the configured model(MISTRAL_MODEL). For instance, if MISTRAL_MODEL is codestral-2405, it would use Codestral’s endpoint. I hope my response is clear.

If you don’t mind, could you please create a pull request with your changes?

bhodrolok commented 1 week ago

Thanks for looking into it! Yeah I did remove the checkAvailableModels function originally but thought it could potentially be helpful down the road if Mistral AI releases more Codestral models.

Yup I see what you mean and that is exactly what I was trying to refactor i.e. have MistralService determine what API calls to make based on the MISTRAL_MODEL value. image

The main problem I see is [CODESTRAL_KEY] Invalid AI type, even after defining it in the utils\config.ts and services\ai\ai.service.ts files.

Sure will make the Pull Request soon, thanks!

tak-bro commented 1 week ago

By the way, if you encounter the "Invalid AI type" message, you need to add the corresponding AI KEY to AIType in ai.service.ts. If you want to add Codestral, you need to include the code as follows:

image

and then add your AI service in AIRequestManager

image

After making this modification, no error will occur if CODESTRAL_KEY is set

bhodrolok commented 1 week ago

Yup I noticed that earlier too but looks like I was getting that error message as I messed up the switch cases with the new CODESTRAL AIType haha. image

I also went ahead and submitted a PR with the refactored version and it does seem to be working but like I said earlier it is not the best of solutions... image