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

feat: Read CHAT_MODEL and BASE_URL from .env for local code review (#80)

* feat: Read CHAT_MODEL and BASE_URL from .env for local code review

* feat: Read CHAT_MODEL and BASE_URL from .env for local code review
This commit is contained in:
Justin Ma
2025-02-07 18:45:54 +08:00
committed by GitHub
parent bb17f50cc2
commit 9fce8f6d22
2 changed files with 12 additions and 5 deletions

View File

@@ -4,6 +4,8 @@
# CHAT_TOKEN: Obtain this token from your DeepSeek account settings
CHAT_TOKEN='Your DeepSeek API token'
# CHAT_MODEL='deepseek-chat' # Official DeepSeek model
# CHAT_MODEL='deepseek-ai/DeepSeek-V3' # SiliconFlow DS model
# GITHUB_TOKEN: Your GitHub API token to query GitHub PR changes
# Generate this token from your GitHub account with the necessary permissions
GITHUB_TOKEN='Your GitHub API token'
@@ -20,6 +22,7 @@ DEFAULT_LOCAL_REPO='/Users/hustcer/deepseek-review'
# BASE_URL: DeepSeek API base URL
# Replace with the actual API base URL if different
BASE_URL='https://api.deepseek.ai'
# BASE_URL='https://api.siliconflow.cn/v1' # SiliconFlow API
# USER_PROMPT: User prompt message, customize as needed
# OR a yaml file path with key name specified to load the prompt message,
# e.g., USER_PROMPT='/User/abc/prompts.yaml:usr-prompt'

View File

@@ -61,8 +61,8 @@ export def --env deepseek-review [
--diff-to(-t): string, # Diff to git REF
--diff-from(-f): string, # Diff from git REF
--max-length(-l): int, # Maximum length of the content for review, 0 means no limit.
--model(-m): string = $DEFAULT_OPTIONS.MODEL, # Model name, deepseek-chat by default
--base-url(-b): string = $DEFAULT_OPTIONS.BASE_URL,
--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
--sys-prompt(-s): string # Default to $DEFAULT_OPTIONS.SYS_PROMPT,
--user-prompt(-u): string # Default to $DEFAULT_OPTIONS.USER_PROMPT,
--include(-i): string, # Comma separated file patterns to include in the code review
@@ -73,11 +73,15 @@ export def --env deepseek-review [
let token = $token | default $env.CHAT_TOKEN?
let repo = $repo | default $env.DEFAULT_GITHUB_REPO?
let CHAT_HEADER = [Authorization $'Bearer ($token)']
let url = $'($base_url)/chat/completions'
let local_repo = $env.DEFAULT_LOCAL_REPO? | default (pwd)
let model = $model | default $env.CHAT_MODEL? | default $DEFAULT_OPTIONS.MODEL
let max_length = $max_length | default ($env.MAX_LENGTH? | default 0 | into int)
let base_url = $base_url | default $env.BASE_URL? | default $DEFAULT_OPTIONS.BASE_URL
let url = $'($base_url)/chat/completions'
let setting = {
repo: $repo,
model: $model,
chat_url: $url,
include: $include,
exclude: $exclude,
diff_to: $diff_to,
@@ -119,7 +123,7 @@ export def --env deepseek-review [
]
}
if $debug { print $'Code Changes:'; hr-line; print $content }
print $'(char nl)(ansi g)Waiting for response from DeepSeek ...(ansi reset)'
print $'(char nl)Waiting for response from (ansi g)($url)(ansi reset) ...'
let response = http post -e -H $CHAT_HEADER -t application/json $url $payload
if ($response | is-empty) {
print $'(ansi r)Oops, No response returned from DeepSeek API.(ansi reset)'
@@ -135,7 +139,7 @@ export def --env deepseek-review [
print $'Code Review Result:'; hr-line; print $review
} else {
let BASE_HEADER = [Authorization $'Bearer ($env.GH_TOKEN)' Accept application/vnd.github.v3+json ...$HTTP_HEADERS]
http post -H $BASE_HEADER $'($GITHUB_API_BASE)/repos/($repo)/issues/($pr_number)/comments' { body: $review }
http post -H $BASE_HEADER $'($GITHUB_API_BASE)/repos/($repo)/issues/($pr_number)/comments' ({ body: $review } | to json)
print $'✅ Code review finishedPR (ansi g)#($pr_number)(ansi reset) review result was posted as a comment.'
}
print $'(char nl)Token Usage Info:'; hr-line