Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
Radiant
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wuzekai
Radiant
Commits
8d152d15
Commit
8d152d15
authored
Nov 21, 2025
by
wuzekai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了大模型对话助手
parent
53dd5828
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
155 additions
and
5 deletions
+155
-5
NAMESPACE
radiant.quickgen/NAMESPACE
+1
-0
quickgen_ai.R
radiant.quickgen/R/quickgen_ai.R
+3
-5
quickgen_chat.R
radiant.quickgen/R/quickgen_chat.R
+6
-0
help.R
radiant.quickgen/inst/app/help.R
+1
-0
init.R
radiant.quickgen/inst/app/init.R
+2
-0
quickgen_chat_ui.R
radiant.quickgen/inst/app/tools/analysis/quickgen_chat_ui.R
+142
-0
quickgen_chat.md
radiant.quickgen/inst/app/tools/help/quickgen_chat.md
+0
-0
No files found.
radiant.quickgen/NAMESPACE
View file @
8d152d15
...
...
@@ -31,6 +31,7 @@ export(p975)
export(p99)
export(prop)
export(qscatter)
export(quickgen_chat_server)
export(sdpop)
export(sdprop)
export(se)
...
...
radiant.quickgen/R/quickgen_ai.R
View file @
8d152d15
...
...
@@ -3,7 +3,7 @@ MODELSCOPE_OPENAI_URL <- "https://api-inference.modelscope.cn/v1"
MODELSCOPE_API_KEY
<-
Sys.getenv
(
"MODELSCOPE_API_KEY"
,
"ms-5b9f3668-ea8e-4a2c-8cd3-a1a9ba04810b"
)
MODEL_ID
<-
"deepseek-ai/DeepSeek-V3.1"
# ===
低层封装:
单次对话 ===
# === 单次对话 ===
#' @export
chat_completion
<-
function
(
user_prompt
,
max_tokens
=
1500
,
...
...
@@ -38,10 +38,8 @@ build_r_prompt <- function(user_prompt, data_call) {
〓 输出格式 〓
- 只返回可运行 R 代码,用 ```r 包裹,禁止任何解释、注释、空行。
- 若用户请求不符合下方【白名单】,一律返回空代码块(仅 ```r\n``` ),不对话。
〓 白名单关键词(必须至少出现 1 个)〓
箱线图|柱状图|条形图|散点图|折线图|密度图|直方图|热图|森林图|瀑布图|饼图|气泡图|生存曲线|KM 曲线|ggsurvplot|tbl_summary|tableone|CreateTableOne|描述性统计|基线表|相关性|group comparison|distribution|ggplot|geom_|patchwork
- 若用户请求不符合规范,一律返回空代码块(仅 ```r\n``` ),不对话。
- 当所需绘制的图中出现数据集中不存在的列或无法计算时,一律输出一张空白 ggplot,仅居中显示“无法绘制”四字,不抛出错误。
〓 否定示例(立即返回空块)〓
- 仅输入:“图表”“表格”“画图”“来张图”
...
...
radiant.quickgen/R/quickgen_chat.R
0 → 100644
View file @
8d152d15
#' @export
quickgen_chat_server
<-
function
(
input
,
output
,
session
,
r_values
=
NULL
,
r_data
)
{
# 当前这个模块不需要复杂的server逻辑
# 所有功能都在UI的renderUI中实现
# 保留函数签名以兼容Radiant框架
}
\ No newline at end of file
radiant.quickgen/inst/app/help.R
View file @
8d152d15
help_quickgen
<-
c
(
"一键生成描述性统计"
=
"quickgen_basic.md"
,
"大模型对话引导助手"
=
"quickgen_chat.md"
,
"大模型生成描述性统计"
=
"quickgen_ai.md"
)
output
$
help_quickgen
<-
reactive
(
append_help
(
"help_quickgen"
,
file.path
(
getOption
(
"radiant.path.quickgen"
),
"app/tools/help"
),
Rmd
=
TRUE
))
...
...
radiant.quickgen/inst/app/init.R
View file @
8d152d15
## urls for menu
r_url_list
<-
getOption
(
"radiant.url.list"
)
r_url_list
[[
"Generate descriptive statistics with one click"
]]
<-
"quickgen/basic/"
r_url_list
[[
"AI chat guidance"
]]
<-
"quickgen/chat/"
r_url_list
[[
"LLM generates descriptive statistics"
]]
<-
"quickgen/ai/"
options
(
radiant.url.list
=
r_url_list
)
rm
(
r_url_list
)
...
...
@@ -15,6 +16,7 @@ options(
tags
$
script
(
src
=
"www_quickgen/js/run_return.js"
)
),
tabPanel
(
i
18
n
$
t
(
"Generate descriptive statistics with one click"
),
uiOutput
(
"quickgen_basic"
)),
tabPanel
(
i
18
n
$
t
(
"AI chat guidance"
),
uiOutput
(
"quickgen_chat"
)),
tabPanel
(
i
18
n
$
t
(
"AI generates descriptive statistics"
),
uiOutput
(
"quickgen_ai"
))
)
)
...
...
radiant.quickgen/inst/app/tools/analysis/quickgen_chat_ui.R
0 → 100644
View file @
8d152d15
library
(
shinyjs
)
library
(
shinyAce
)
## ===== 统一入口=====
output
$
quickgen_chat
<-
renderUI
({
tagList
(
useShinyjs
(),
stat_tab_panel
(
menu
=
i
18
n
$
t
(
"One-click generation > AI chat guidance"
),
tool
=
i
18
n
$
t
(
"AI chat guidance"
),
tool_ui
=
"chat_main_ui"
,
output_panels
=
tabPanel
(
title
=
i
18
n
$
t
(
"Chat history"
),
value
=
"chat_panel"
,
uiOutput
(
"chat_history_area"
)
)
)
)
})
## ===== 左侧区域=====
output
$
chat_main_ui
<-
renderUI
({
tagList
(
useShinyjs
(),
wellPanel
(
div
(
style
=
"font-weight:bold; color:#1976d2; margin-bottom:10px;"
,
icon
(
"database"
),
" "
,
i
18
n
$
t
(
"Dataset Fields Information"
)
),
uiOutput
(
"field_info_display"
),
tags
$
hr
(),
div
(
style
=
"color:#666; font-size:0.9em; margin-top:5px;"
,
i
18
n
$
t
(
"The current dataset's field information is automatically passed to the AI assistant."
)
),
style
=
"max-height:450px; overflow-y:auto; background-color:#f8f9fa;"
),
help_and_report
(
modal_title
=
i
18
n
$
t
(
"AI chat guidance"
),
fun_name
=
"quickgen_chat"
,
help_file
=
inclMD
(
file.path
(
getOption
(
"radiant.path.quickgen"
),
"app/tools/help/quickgen_chat.md"
)),
lic
=
"by-sa"
)
)
})
## ===== 右侧区域=====
output
$
chat_history_area
<-
renderUI
({
field_info_encoded
<-
get_field_info
()
if
(
is.null
(
field_info_encoded
))
{
return
(
create_no_data_ui
())
}
iframe_src
<-
paste0
(
"http://180.169.131.147:8106/chat/9f51e1707c61027e?field_info="
,
field_info_encoded
)
tagList
(
div
(
id
=
"chat_box"
,
style
=
"height:700px; overflow-y:auto; border:1px solid #ddd;
border-radius:4px; padding:0; background:#fff; margin-bottom:10px;"
,
tags
$
iframe
(
src
=
iframe_src
,
style
=
"width: 100%; height: 100%; border: 0;"
,
frameborder
=
0
,
allow
=
"microphone"
)
)
)
})
# 生成左侧展示的格式化字段文本
output
$
field_info_display
<-
renderUI
({
if
(
is.null
(
input
$
dataset
)
||
!
exists
(
"r_data"
))
{
return
(
tags
$
pre
(
i
18
n
$
t
(
"Please select a dataset in another page first"
),
style
=
"margin:0; background-color:#f9f9f9; border:1px solid #ddd; padding:10px; font-size:0.9em;"
))
}
df
<-
tryCatch
({
get
(
input
$
dataset
,
envir
=
r_data
)
},
error
=
function
(
e
)
NULL
)
if
(
is.null
(
df
)
||
!
is.data.frame
(
df
)
||
nrow
(
df
)
==
0
)
{
return
(
tags
$
pre
(
i
18
n
$
t
(
"Current dataset is empty"
),
style
=
"margin:0; background-color:#f9f9f9; border:1px solid #ddd; padding:10px; font-size:0.9em;"
))
}
# 生成带换行的格式
field_lines
<-
sprintf
(
'"%s": "%s"'
,
names
(
df
),
sapply
(
df
,
function
(
x
)
class
(
x
)[
1
]))
formatted_text
<-
paste
(
field_lines
,
collapse
=
",\n"
)
tags
$
pre
(
formatted_text
,
style
=
"margin:0; background-color:#f9f9f9; border:1px solid #ddd;
padding:10px; font-size:0.9em; line-height:1.5; white-space:pre-wrap;"
)
})
# 获取并编码字段信息
get_field_info
<-
function
()
{
if
(
is.null
(
input
$
dataset
)
||
!
exists
(
"r_data"
))
{
return
(
NULL
)
}
df
<-
tryCatch
({
get
(
input
$
dataset
,
envir
=
r_data
)
},
error
=
function
(
e
)
NULL
)
if
(
is.null
(
df
)
||
!
is.data.frame
(
df
)
||
nrow
(
df
)
==
0
)
{
return
(
NULL
)
}
# 构建带数据集名称的JSON结构
fields_list
<-
list
()
for
(
col_name
in
names
(
df
))
{
fields_list
[[
col_name
]]
<-
class
(
df
[[
col_name
]])[
1
]
}
json_struct
<-
list
(
dataset_name
=
input
$
dataset
,
fields
=
fields_list
)
URLencode
(
jsonlite
::
toJSON
(
json_struct
,
auto_unbox
=
TRUE
),
reserved
=
TRUE
)
}
# 无数据时的UI
create_no_data_ui
<-
function
()
{
tagList
(
div
(
id
=
"chat_box"
,
style
=
"height:700px; overflow-y:auto; border:1px solid #ddd;
border-radius:4px; padding:20px; background:#fff; margin-bottom:10px;"
,
p
(
i
18
n
$
t
(
"请选择数据集"
),
style
=
"text-align:center; margin-top:50px; color:#888;"
)
)
)
}
\ No newline at end of file
radiant.quickgen/inst/app/tools/help/quickgen_chat.md
0 → 100644
View file @
8d152d15
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment