Skip to content

Commit 7a9f28c

Browse files
committed
APIAuto: 新增 AI 问答聊天
1 parent 47dad22 commit 7a9f28c

File tree

2 files changed

+75
-8
lines changed
  • APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api

2 files changed

+75
-8
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/index.html

+12-8
Original file line numberDiff line numberDiff line change
@@ -743,14 +743,18 @@
743743

744744
<div class="right-main" id="vHtml" v-show="view == 'html'"></div>
745745
<div class="right-main" id="vMarkdown" v-show="view == 'markdown'"></div>
746-
<div v-show="view == 'markdown'" style="bottom: -6px; text-align: right; position: absolute; width: 100%; padding: 4px 20px 0px 4px; background-color: white;">
747-
<input id="vSearch" v-model="search" style="min-width: 60px; display: inline-flex; text-align: center" @keyup="doOnKeyUp(event, 'document', true)" placeholder="搜索" />
748-
<button @click="pageDown('document')">上页 < </button>
749-
<input id="vPage" v-model="page" style="width: 30px;text-align: center" type="number" @keyup="doOnKeyUp(event, 'document', true)" placeholder="页码" />
750-
<button @click="pageUp('document')"> > 下页</button>
751-
<a >每页</a>
752-
<input id="vCount" v-model="count" style="width: 30px;text-align: center" type="number" @keyup="doOnKeyUp(event, 'document', true)" placeholder="条数" />
753-
<a ></a>
746+
<div style="bottom: -6px; text-align: right; position: absolute; width: 100%; padding: 4px 20px 0px 4px; background-color: white;">
747+
<!-- <div style="float: right" >-->
748+
<input v-show="view == 'markdown'" id="vSearch" v-model="search" style="min-width: 60px; display: inline-flex; text-align: center" @keyup="doOnKeyUp(event, 'document', true)" placeholder="搜索文档" />
749+
<button v-show="view == 'markdown'" @click="pageDown('document')">上页 < </button>
750+
<input v-show="view == 'markdown'" id="vPage" v-model="page" style="width: 30px;text-align: center" type="number" @keyup="doOnKeyUp(event, 'document', true)" placeholder="页码" />
751+
<button v-show="view == 'markdown'" @click="pageUp('document')"> > 下页</button>
752+
<a v-show="view == 'markdown'" >每页</a>
753+
<input v-show="view == 'markdown'" id="vCount" v-model="count" style="width: 30px;text-align: center" type="number" @keyup="doOnKeyUp(event, 'document', true)" placeholder="条数" />
754+
<a v-show="view == 'markdown'" ></a>
755+
<!-- </div>-->
756+
<input id="vAskAI" style="min-width: 60px; display: inline-flex; padding: 0px 4px 0px 4px" @keyup="doOnKeyUp(event, 'ask', true)" placeholder="Ask AI" :style="{'width': view == 'markdown' ? 'auto' : '82%', 'text-align': view == 'markdown' ? 'center' : 'left'}" />
757+
<label style="float: right; margin-left: 8px; height: 100%; text-align: center"><input id="vDeepSearch" type="checkbox" style="height: 100%; text-align: center; bottom: 4px" name="Deep Search" />Deep Search</label>
754758
</div>
755759

756760
<ul class="dropdown-menu" id="vOption" style="display: block; left: 0px; top: 0px; max-height: 100%; max-width: 100%; overflow: scroll; overflow-x: scroll; overflow-y:scroll;" v-show="options != null && options.length > 0">

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/js/main.js

+63
Original file line numberDiff line numberDiff line change
@@ -7503,6 +7503,69 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
75037503
doOnKeyUp: function (event, type, isFilter, item) {
75047504
var keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
75057505
var isEnter = keyCode == 13
7506+
7507+
if (type == 'ask') {
7508+
if (isEnter) {
7509+
const user_query = StringUtil.trim(vAskAI.value);
7510+
const uuid = crypto.randomUUID();
7511+
this.request(true, REQUEST_TYPE_POST, REQUEST_TYPE_JSON, 'https://api.devin.ai/ada/query', {
7512+
"engine_id": "multihop",
7513+
"user_query": "<relevant_context>This query was sent from the wiki page: Overview.</relevant_context>" + user_query,
7514+
"keywords": [],
7515+
"repo_names": [
7516+
"Tencent/APIJSON"
7517+
],
7518+
"additional_context": "",
7519+
"query_id": uuid,
7520+
"use_notes": false,
7521+
"generate_summary": false
7522+
}, {}, function (url, res, err) {
7523+
App.onResponse(url, res, err)
7524+
var data = res.data || {}
7525+
var isOk = JSONResponse.isSuccess(data)
7526+
7527+
var msg = isOk ? '' : ('\nmsg: ' + StringUtil.get(data.msg))
7528+
if (err != null) {
7529+
msg += '\nerr: ' + err.msg
7530+
vOutput.value = err.msg
7531+
this.view = 'error';
7532+
return
7533+
}
7534+
7535+
App.request(true, REQUEST_TYPE_GET, REQUEST_TYPE_PARAM, 'https://api.devin.ai/ada/query/' + uuid, {}, {}, function (url, res, err) {
7536+
App.onResponse(url, res, err)
7537+
var data = res.data || {}
7538+
var isOk = JSONResponse.isSuccess(data)
7539+
7540+
var msg = isOk ? '' : ('\nmsg: ' + StringUtil.get(data.msg))
7541+
if (err != null) {
7542+
msg += '\nerr: ' + err.msg
7543+
vOutput.value = err.msg
7544+
this.view = 'error';
7545+
return
7546+
}
7547+
7548+
var queries = data.queries || []
7549+
var last = queries[queries.length - 1]
7550+
var query = last.user_query || user_query
7551+
var response = last.response || []
7552+
var answer = '### Ask\n' + query + '\n### Answer\n';
7553+
for (var i = 0; i < response.length; i ++) {
7554+
var item = response[i] || {};
7555+
if (item.type != 'file_contents') {
7556+
continue;
7557+
}
7558+
answer += '\n' + StringUtil.trim(typeof data == 'string' ? data : (data instanceof Array ? data.join() : JSON.stringify(data)));
7559+
}
7560+
7561+
vOutput.value += answer;
7562+
App.view = 'markdown';
7563+
})
7564+
})
7565+
}
7566+
return
7567+
}
7568+
75067569
if (type == 'option') {
75077570
if (isEnter) {
75087571
this.selectInput(item);

0 commit comments

Comments
 (0)