Use AI to review the Issues before submitting them. Helps write better Bug reports and Feature requests.
First add ‘ruby-openai’ to your Gemfile.local and run ‘bundle install’.
Redmine does not offer all the hooks needed, so here are a couple of manual patches:
-
Add the following at line 40 of
app/views/repositories/_changeset.html.erb:
“‘ <!– CUSTOM INSERTED CODE –> <div>
<h3>AI Code Review</h3>
<% begin %>
<%= call_hook(:view_issues_history_changeset_bottom, { :changeset => @changeset }) %>
<% rescue => e%>
<div>Exception in erb template: <%= e %></div>
<% end %>
</div> <!– /CUSTOM INSERTED CODE –> “‘
-
Add the following at the end of
app/views/issues/tabs/_changesets.html.erb:
“‘ <!– CUSTOM INSERTED CODE –> <%= call_hook(:view_issues_history_changesets_bottom, { :changesets => @changesets }) %> <!– /CUSTOM INSERTED CODE –> “`
Go to the plugin settings page and add your API urls, keys for each provider you want to use. Setup default models for Code Review or the Ask AI page. Then setup the prompts you want to use, see the prompts directory for examples.
In API Providers:
- Provider Name
-
A string to identify the provider and add models to it
- API Url
-
The base URL of the OpenAI compatible API, e.g. for OpenAI ‘api.openai.com/v1’, for Gemini ‘generativelanguage.googleapis.com/v1beta/openai/’, for Ollama usually ‘localhost:11434/v1’, for Llama ‘api.llama-api.com’
- API Key
-
The API key to use for authentication
In AI Models:
- Model Provider
-
which API provides the model
- Model
-
the name of the model, refer to the API documentation for the available models or use the List Available Models helper (not every API provider support this)
- Temperature
-
Optional: Override the Model default temperature, see for example: platform.openai.com/docs/api-reference/chat#chat-create-temperature
- Max Tokens
-
Optional: Limit the amount of output tokens, see platform.openai.com/docs/api-reference/chat#chat-create-max_tokens
Optionally setup the default models:
- Default Model
-
The default model to use for the AI requests
- Default Tool Model
-
The model to use for tool invocation, usually OpenAI model work better here
In Prompts:
- Default Prompt
-
The default prompt to use for evaluating the Issue content, the other prompt are for each specific Issue type
- Code Review Prompts
-
Links to a page where the prompts for code reviews can be configured for each Repository setup in Redmine
On the New Issue page, you will see a new button ‘Evaluate with AI’ that will give suggestions on how to improve the issue description based on the type of issue (Bug or Feature) and the prompts that are configured.
Go to the /issues_ai/ask page for an interface to ask free questions. This supports injecting issues and wiki pages as context in the following way:
-
[Some_Page]will inject the content of the wiki page named ‘Some Page’. -
#123will inject the content of issue 123, -
issues injected will be including ID / Subject / Description / Tracker / Status / Created Date / Assigned
-
issues can also be injected based on natural language queries like ‘new feature issues over the last month’
The AI also has access to the following tools as defined in issues_ai/app/helpers/issues_ai_tools.rb:
-
get_tickets: retreive tickets based on status / tracker / max_age_days / limit, this can be used to include tickets into the context based on a query like ‘new feature issues over the last month’ or ‘the last 5 closed bugs’
The Code Review feature is available in the following places:
-
In the Issue view, in the ‘Associated revisions’ section (eg: ‘/issues/2121?tab=changesets`)
-
In the Revisiton view (eg:
/projects/my_prject_name/repository/my_repository/revisions/1bc93040...f9d18a53f)
There you can ‘Queue an AI Code Review` or `Review Now` a specific commit.
In addition, you can also use the ‘Review All` button to review all the commits in the Issue view in the ’Associated revisions’ section. This creates a Review off all the commits associated to the Issue and provides a summary of the overall changes. This review can then by Saved as a Note on the Issue itself.