1
0
mirror of https://github.com/hustcer/deepseek-review.git synced 2026-05-13 05:16:05 +08:00

2 Commits

Author SHA1 Message Date
hustcer
91c90031c0 ci skip 2025-04-29 17:12:23 +08:00
hustcer
2157323736 feat: Make system prompt optional and use user prompt instead 2025-04-29 17:12:23 +08:00
9 changed files with 36 additions and 64 deletions

View File

@@ -15,7 +15,6 @@ on:
branches:
- main
- develop
- feature/test
paths-ignore:
- '**.md'
- 'docs/**'

View File

@@ -1,32 +1,6 @@
# Changelog
All notable changes to this project will be documented in this file.
## [1.19.0] - 2025-07-23
### Bug Fixes
- Fix "variable not found" error (#185)
- Fix getting Nu binary path for Nushell 0.106
### Deps
- Upgrade Nu to v0.106 (#186)
## [1.18.0] - 2025-06-11
### Features
- Set default `temperature` to **0.3** for code review (#181)
### Miscellaneous Tasks
- Refine diff flag descriptions in docs and scripts (#177)
- Upgrade `Nu` to 0.105 and pin [`hustcer/setup-nu`](https://github.com/hustcer/setup-nu) to v3.19 (#183)
### Deps
- Upgrade `nutest` to v1.1.0 (#179)
## [1.17.0] - 2025-04-11
### Bug Fixes

View File

@@ -28,7 +28,7 @@ alias cr := code-review
# Used to handle the path separator issue
DEEPSEEK_REVIEW_PATH := parent_directory(justfile())
NU_DIR := parent_directory(`$nu.current-exe`)
NU_DIR := parent_directory(`(which nu).path.0`)
_query_plugin := if os_family() == 'windows' { 'nu_plugin_query.exe' } else { 'nu_plugin_query' }
# To pass arguments to a dependency, put the dependency

View File

@@ -58,9 +58,9 @@ runs:
using: 'composite'
steps:
- name: Setup Nu
uses: hustcer/setup-nu@v3.19
uses: hustcer/setup-nu@v3
with:
version: 0.106.0
version: 0.103.0
- name: DeepSeek Code Review
shell: nu {0}

4
cr
View File

@@ -21,8 +21,8 @@ def main [
--model(-m): string, # Model name, or read from CHAT_MODEL env var, `deepseek-chat` by default
--base-url(-b): string, # DeepSeek API base URL, fallback to BASE_URL env var
--chat-url(-U): string, # DeepSeek Model chat full API URL, e.g. http://localhost:11535/api/chat
--sys-prompt(-s): string # Default to $DEFAULT_OPTIONS.SYS_PROMPT,
--user-prompt(-u): string # Default to $DEFAULT_OPTIONS.USER_PROMPT,
--sys-prompt(-s): string # Optional, System prompt message, fallback to SYSTEM_PROMPT env var
--user-prompt(-u): string # Default to $DEFAULT_OPTIONS.USER_PROMPT
--include(-i): string, # Comma separated file patterns to include in the code review
--exclude(-x): string, # Comma separated file patterns to exclude in the code review
--temperature(-T): float, # Temperature for the model, between `0` and `2`, default value `0.3`

View File

@@ -1,7 +1,7 @@
{
"name": "deepseek-review",
"version": "1.19.0",
"actionVer": "v1.19",
"version": "1.17.0",
"actionVer": "v1.17",
"author": "hustcer",
"license": "MIT",
"github": "https://github.com/hustcer/deepseek-review",

View File

@@ -51,8 +51,8 @@ export def compare-ver [v1: string, v2: string] {
# If you want to compare more parts use the following code:
# for i in 0..([2 ($a | length) ($b | length)] | math max)
for i in 0..2 {
let x = $a | get -o $i | default 0
let y = $b | get -o $i | default 0
let x = $a | get -i $i | default 0
let y = $b | get -i $i | default 0
if $x > $y { return 1 }
if $x < $y { return (-1) }
}
@@ -102,7 +102,7 @@ export def 'from env' []: string -> record {
# Compact the record by removing empty columns
export def compact-record []: record -> record {
let record = $in
let empties = $record | columns | where {|it| $record | get $it | is-empty }
let empties = $record | columns | filter {|it| $record | get $it | is-empty }
$record | reject ...$empties
}

View File

@@ -23,20 +23,21 @@ def file-exists [file: string] {
# Check if the prompt keys exist in the config.yml file
def check-prompts [options: record] {
check-prompt $options user
check-prompt $options system
# System prompt is optional, so we don't exit if it's missing
# check-prompt $options system
}
# Check if the specified type of prompt key exists in the config.yml file
def check-prompt [options: record, type: string] {
let prompt_key = $options.settings | get -o $'($type)-prompt' | default ''
let prompt_key = $options.settings | get -i $'($type)-prompt' | default ''
if ($prompt_key | is-empty) {
print $'(ansi r)The ($type) prompt key is missing in `settings.($type)-prompt` config.yml file.(ansi reset)'
exit $ECODE.INVALID_PARAMETER
}
let prompt = $options.prompts | get -o $type
let prompt = $options.prompts | get -i $type
| default []
| where name == $prompt_key
| get -o 0.prompt
| get -i 0.prompt
if ($prompt | is-empty) {
print $'The ($type) prompt (ansi r)($prompt_key)(ansi reset) is missing in `prompts.($type)` of config.yml file.'
exit $ECODE.INVALID_PARAMETER
@@ -59,11 +60,11 @@ def check-providers [options: record] {
exit $ECODE.INVALID_PARAMETER
}
# Each provider should have name, token and models field
$options.providers | each {|p|
let empties = [name token models] | where { |field| $p | get -o $field | is-empty }
$options.providers | each {|it|
let empties = [name token models] | filter { |field| $it | get -i $field | is-empty }
if ($empties | is-not-empty) {
print $'Field (ansi r)`($empties | str join ,)`(ansi reset) should not be empty for provider:'
$p | table -e -t psql | print
$it | table -e -t psql | print
exit $ECODE.INVALID_PARAMETER
}
}
@@ -105,7 +106,7 @@ def get-model-envs [settings: record, model?: string = ''] {
let provider = $settings.providers
| default []
| where name == $name
| get -o 0
| get -i 0
| default {}
let model_name = $provider.models
| default []
@@ -114,7 +115,7 @@ def get-model-envs [settings: record, model?: string = ''] {
} else {
$it.name == $model or $it.alias? == $model }
}
| get -o 0.name
| get -i 0.name
| default $model
{ CHAT_TOKEN: $provider.token?, BASE_URL: $provider.base-url?, CHAT_URL: $provider.chat-url?, CHAT_MODEL: $model_name }
@@ -132,12 +133,12 @@ export def --env config-load [
let user_prompt = $all_settings.prompts?.user?
| default []
| where name == ($settings.user-prompt? | default '')
| get -o 0.prompt
| get -i 0.prompt
let system_prompt = $all_settings.prompts?.system?
| default []
| where name == ($settings.system-prompt? | default '')
| get -o 0.prompt
| get -i 0.prompt
let model_envs = get-model-envs $all_settings $model

View File

@@ -46,8 +46,7 @@ const DEFAULT_OPTIONS = {
MODEL: 'deepseek-chat',
TEMPERATURE: 0.3,
BASE_URL: 'https://api.deepseek.com',
USER_PROMPT: 'Please review the following code changes:',
SYS_PROMPT: 'You are a professional code review assistant responsible for analyzing code changes in GitHub Pull Requests. Identify potential issues such as code style violations, logical errors, security vulnerabilities, and provide improvement suggestions. Clearly list the problems and recommendations in a concise manner.',
USER_PROMPT: 'You are a professional code review assistant responsible for analyzing code changes. Identify potential issues such as code style violations, logical errors, security vulnerabilities, and provide improvement suggestions. Clearly list the problems and recommendations in a concise manner. Please review the following code changes:',
}
# Use DeepSeek AI to review code changes locally or in GitHub Actions
@@ -65,8 +64,8 @@ export def --env deepseek-review [
--model(-m): string, # Model name, or read from CHAT_MODEL env var, `deepseek-chat` by default
--base-url(-b): string, # DeepSeek API base URL, fallback to BASE_URL env var
--chat-url(-U): string, # DeepSeek Model chat full API URL, e.g. http://localhost:11535/api/chat
--sys-prompt(-s): string # Default to $DEFAULT_OPTIONS.SYS_PROMPT,
--user-prompt(-u): string # Default to $DEFAULT_OPTIONS.USER_PROMPT,
--sys-prompt(-s): string # Optional, System prompt message, fallback to SYSTEM_PROMPT env var
--user-prompt(-u): string # Default to $DEFAULT_OPTIONS.USER_PROMPT
--include(-i): string, # Comma separated file patterns to include in the code review
--exclude(-x): string, # Comma separated file patterns to exclude in the code review
--temperature(-T): float, # Temperature for the model, between `0` and `2`, default value `0.3`
@@ -114,7 +113,7 @@ export def --env deepseek-review [
print $hint; print -n (char nl)
if ($pr_number | is-empty) {
print 'Current Settings:'; hr-line
$setting | compact-record | reject -o repo | print; print -n (char nl)
$setting | compact-record | reject -i repo | print; print -n (char nl)
}
let content = (
@@ -126,16 +125,15 @@ export def --env deepseek-review [
exit $ECODE.SUCCESS
}
print $'Review content length: (ansi g)($length)(ansi reset), current max length: (ansi g)($max_length)(ansi reset)'
let sys_prompt = $sys_prompt | default $env.SYSTEM_PROMPT? | default $DEFAULT_OPTIONS.SYS_PROMPT
let sys_prompt = $sys_prompt | default $env.SYSTEM_PROMPT?
let user_prompt = $user_prompt | default $env.USER_PROMPT? | default $DEFAULT_OPTIONS.USER_PROMPT
mut messages = if ($sys_prompt | is-empty) { [] } else { [{ role: 'system', content: $sys_prompt }] }
$messages = $messages | append { role: 'user', content: $"($user_prompt)\n($content)" }
let payload = {
model: $model,
stream: $stream,
messages: $messages
temperature: $temperature,
messages: [
{ role: 'system', content: $sys_prompt },
{ role: 'user', content: $"($user_prompt):\n($content)" }
]
}
if $debug { print $'(char nl)Code Changes:'; hr-line; print $content }
print $'(char nl)Waiting for response from (ansi g)($url)(ansi reset) ...'
@@ -151,9 +149,9 @@ export def --env deepseek-review [
print $'✖️ Code review failedError: '; hr-line; print $response
exit $ECODE.SERVER_ERROR
}
let message = $response | get -o choices.0.message
let message = $response | get -i choices.0.message
let reason = $message | coalesce-reasoning
let review = $message.content? | default ($response | get -o message.content)
let review = $message.content? | default ($response | get -i message.content)
let result = ['<details>' '<summary> Reasoning Details</summary>' $reason "</details>\n" $review] | str join "\n"
if ($review | is-empty) {
print $'✖️ Code review failedNo review result returned from ($base_url) ...'
@@ -192,7 +190,7 @@ def write-review-to-file [
'# DeepSeek Code Review Result', ''
$"Generated at: (date now | format date '%Y/%m/%d %H:%M:%S')", ''
'## Code Review Settings', ''
($setting | compact-record | reject -o repo | transpose key val | to md --pretty)
($setting | compact-record | reject -i repo | transpose key val | to md --pretty)
'', '## Review Detail', '', $result, '', ...$token_usage
]
try {
@@ -264,10 +262,10 @@ def streaming-output [
| try { lines } catch { print $'(ansi r)Error Happened ...(ansi reset)'; exit $ECODE.SERVER_ERROR }
| each {|line|
if ($line | is-empty) { return }
if ($IGNORED_MESSAGES | get -o $line | default false) { return }
if ($IGNORED_MESSAGES | get -i $line | default false) { return }
let $last = $line | parse-line
if $debug { $last | to json | kv set last-reply }
$last | get -o choices.0.delta | default ($last | get -o message) | if ($in | is-not-empty) {
$last | get -i choices.0.delta | default ($last | get -i message) | if ($in | is-not-empty) {
let delta = $in
if ($delta | coalesce-reasoning | is-not-empty) { kv set reasoning ((kv get reasoning) + 1) }
if (kv get reasoning) == 1 { print $'(char nl)Reasoning Details:'; hr-line }
@@ -279,7 +277,7 @@ def streaming-output [
if $debug and (kv get last-reply | is-not-empty) {
print $'(char nl)(char nl)Model & Token Usage:'; hr-line
kv get last-reply | from json | select -o model usage | table -e | print
kv get last-reply | from json | select -i model usage | table -e | print
}
}