Movatterモバイル変換


[0]ホーム

URL:


codestral0.0.1

codestral

Thanks to an appropriate Rstudio addin, this package allows promptingMistra AI models using their API for fill in the middle (FIM) and chat in Rstudio. Installing this package creates an Addin in Rstudio that allows a direct and simple use of the Mistral AI API.

For FIM, theCodestral model is used.

For chatting, the user may use either Codestral orCodestral Mamba.

Installation

You should first get 2 API keys from the Mistral AIPlateforme:

  • one general Mistral AI API key (menuAPI in La Plateforme).
  • one Codestral API key (menuCodestral in La Plateforme).

You can install the development version of codestral fromGitHub with:

# install.packages("pak")pak::pak("urbs-dev/codestral")

Restart your session to activate the addin.

The addin is now visible in the RstudioAddins drop down list asCodestral code completion.

Set up for usage in Rstudio

The package needs to be initialized, especially to get your API key.

library(codestral)## basic example code# replace *** with your API key# codestral_init(apikey = "********************************")

This function also sets some parameters for using the Mistral AI API properly. Once you get familiar with the package, you may customize those parameters.

A simple example to start with

Open a new text file and type:"m: Hello world !". Leave your cursor at the end of the line.

In the Rstudio toolbar, look for theAddins drop down menu and click onCodestral code completion.

The model’s answer should appear in your text file starting witha:.

In your console note that the functioncodestral:::insert_addin() has been called.

Using codestral package

Fill in the middle (FIM)

Place your cursor where you want the FIM code to appear and look forCodestral code completion in theAddins drop down menu ofRStudio.

When you click on the addin, the Codestral answer is inserted. In the request, the prompt is the part of the script before the cursor, the suffix is the part of the script after the cursor. The answer is limited tomax_tokens$FIM as set incodestral_init. In case you feel the FIM is incomplete, you may just activate the addin again.

Chat

  • To prompt the Codestral model: The current script should start withc:. Place your cursor at the end of your question. Activate the addin as for FIM. The answer is inserted from the line after your cursor position.

  • To prompt the Codestral Mamba model: Just replacec: withm:.

In both cases, the answer will start witha:.

You can follow up the dialog starting a new line withc: orm: after the model’s answer.

Including files content

If you wish to include a text file (.R, .Rmd …) in your prompt, just make sure that the file is in the current working directory or one of its subdirectories (for instance in the same project) and add a line in your prompt starting by “ff:” and followed by the file name :"ff:my_file.R"

Behind the scene,ff: triggers the insertion of the content ofmy_file.R at the location where the instruction has been placed.

Example:

m: Write the necessary unit testsfor the following functionsff:my_fun_file.R

Modify the assistant behaviour.

By default, when initializing the package, the assistant role is described as “You write programs in R language only. You adopt a proper coding approach by strictly naming all the functions’ parameters when calling any function with named parameters even when calling nested functions, by being straighforward in your answers.” This can be modified when initializing the package with the parameterrole_content ofcodestral_init. However, the user may find it usefull to modify this role temporarily. This can be achieved with the markers:.

Example:

s: you are an sql developer.m: How do joints work?

Make it more efficient using keyboard shortcut

In order to define a keyboard shortcut for this addin, in Rstudio, choose the menuTools/Addins/Browse Addins... In the pop-up window, click on theKeyboard shortcuts button. in the new window, double click on the table’s cell at rowCodestral code completion and columnShortcut. Insert your shortcut.

You can now replace default usage by your shortcut.

Additionnaly you may add the initialization step in an.Rprofile so that initialization is performed at any session start.

Information about your data

Keep in mind that the point of this addin is to communicate with an API. No AI model is installed locally. Therefore every time you activate the addin, the content of the file where your cursor is, will be sent to Mistral AI. Ifff:my_file.R is present in this file, then the content ofmy_file.R is also sent to Mistral AI.

The other information sent to Mistral AI is the content of the environment variables created bycodestral_init().

Nothing else is sent to Mistral AI and nothing is sent to a third party.

Note that if you are using the free services of Mistral AI, the data you sent may be used by them for training their future models. Visit their website for more information.

Links

License

Citation

Developers

  • Marc Grossouvre
    Author, maintainer
  • URBS company
    Copyright holder, funder

Dev status

  • Lifecycle: stable

[8]ページ先頭

©2009-2025 Movatter.jp