This commit is contained in:
刘正航
2026-04-21 22:45:19 +08:00
commit b5237f9038
159 changed files with 7769 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
const { request } = require('../../utils/request')
Page({
data: {
question: '',
answer: '',
provider: 'fastgpt',
mode: 'auto',
hits: [],
adviceType: 'general',
loading: false,
providerOptions: ['fastgpt', 'dify', 'local'],
modeOptions: ['auto', 'local', 'llm'],
adviceOptions: ['general', 'gain_muscle', 'lose_fat', 'keto', 'nutritionist']
},
onInput(e) {
const field = e.currentTarget.dataset.field
this.setData({ [field]: e.detail.value })
},
onPickerChange(e) {
const field = e.currentTarget.dataset.field
const options = this.data[`${field}Options`]
this.setData({ [field]: options[e.detail.value] })
},
async askQuestion() {
if (!this.data.question.trim()) {
wx.showToast({ title: '请输入问题', icon: 'none' })
return
}
this.setData({ loading: true })
try {
const provider = this.data.provider === 'local' ? 'fastgpt' : this.data.provider
const mode = this.data.provider === 'local' ? 'local' : this.data.mode
const data = await request({
url: '/qa/ask',
method: 'POST',
data: {
question: this.data.question,
provider,
mode
}
})
this.setData({ answer: data.answer, hits: data.items || [] })
} catch (err) {
// handled
} finally {
this.setData({ loading: false })
}
},
async getAdvice() {
this.setData({ loading: true })
try {
const provider = this.data.provider === 'local' ? 'dify' : this.data.provider
const data = await request({
url: '/qa/advice',
method: 'POST',
data: {
advice_type: this.data.adviceType,
question: this.data.question || '请给我本周饮食建议',
provider
}
})
this.setData({ answer: data.answer, hits: data.knowledge_hits || [] })
} catch (err) {
// handled
} finally {
this.setData({ loading: false })
}
}
})

View File

@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "营养问答"
}

View File

@@ -0,0 +1,49 @@
<view class="container">
<view class="hero">
<view class="hero-title">营养学科普问答</view>
<view class="hero-sub">RAG 本地知识库 + FastGPT / Dify 工作流</view>
</view>
<view class="card">
<view class="card-title">问答配置</view>
<textarea class="input textarea" data-field="question" placeholder="输入问题,如:减脂期晚餐怎么吃?" value="{{question}}" bindinput="onInput" />
<view class="row">
<text class="label">模型来源</text>
<picker mode="selector" range="{{providerOptions}}" data-field="provider" bindchange="onPickerChange">
<text class="value">{{provider}}</text>
</picker>
</view>
<view class="row">
<text class="label">问答模式</text>
<picker mode="selector" range="{{modeOptions}}" data-field="mode" bindchange="onPickerChange">
<text class="value">{{mode}}</text>
</picker>
</view>
<view class="row">
<text class="label">功能化建议</text>
<picker mode="selector" range="{{adviceOptions}}" data-field="adviceType" bindchange="onPickerChange">
<text class="value">{{adviceType}}</text>
</picker>
</view>
<button class="btn btn-primary" loading="{{loading}}" bindtap="askQuestion">提问(科普问答)</button>
<button class="btn btn-accent" loading="{{loading}}" bindtap="getAdvice">生成个性化建议</button>
</view>
<view class="card" wx:if="{{answer}}">
<view class="card-title">回答结果</view>
<view class="item-sub">{{answer}}</view>
</view>
<view class="card" wx:if="{{hits && hits.length}}">
<view class="card-title">RAG 命中文档</view>
<view class="item" wx:for="{{hits}}" wx:key="index">
<view class="item-title">{{item.question}}</view>
<view class="item-sub">{{item.answer}}</view>
<view class="item-sub">score: {{item.score}} | source: {{item.source}}</view>
</view>
</view>
</view>

View File

@@ -0,0 +1,3 @@
.card .row {
margin-top: 8rpx;
}