Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冯丙见
AI私人知识库
提交
c6099eb8
A
AI私人知识库
项目概览
冯丙见
/
AI私人知识库
与 Fork 源项目一致
Fork自
冯丙见 / AI绘图
通知
1
Star
128
Fork
114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
AI私人知识库
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c6099eb8
编写于
1月 11, 2024
作者:
W
weixin_44463441
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Thu Jan 11 12:02:00 CST 2024 inscode
上级
405fcf8b
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
108 addition
and
23 deletion
+108
-23
.inscode
.inscode
+3
-8
src/App.vue
src/App.vue
+14
-2
src/components/content/index.vue
src/components/content/index.vue
+34
-0
src/js/config.js
src/js/config.js
+6
-4
src/js/inscodeai.js
src/js/inscodeai.js
+11
-6
src/js/repEs.js
src/js/repEs.js
+33
-2
tailwind.config.js
tailwind.config.js
+1
-0
vite.config.js
vite.config.js
+6
-1
未找到文件。
.inscode
浏览文件 @
c6099eb8
run = "
cd dist; python3 -m http.server
"
run = "
npm i -f && npm run dev
"
language = "node"
language = "node"
[deployment]
[deployment]
build = "npm i && npm run build"
build = "npm i -f && npm run build"
run = "cd dist; python3 -m http.server"
run = "npm run preview"
[env]
PATH = "/root/${PROJECT_DIR}/.config/npm/node_global/bin:/root/${PROJECT_DIR}/node_modules/.bin:${PATH}"
XDG_CONFIG_HOME = "/root/.config"
npm_config_prefix = "/root/${PROJECT_DIR}/.config/npm/node_global"
[debugger]
[debugger]
program = "main.js"
program = "main.js"
src/App.vue
浏览文件 @
c6099eb8
...
@@ -67,6 +67,9 @@
...
@@ -67,6 +67,9 @@
</div>
</div>
<!-- right -->
<!-- right -->
<div
class=
"flex-auto bg-slate-300 md:bg-slate-300 p-2 sm:p-8"
>
<div
class=
"flex-auto bg-slate-300 md:bg-slate-300 p-2 sm:p-8"
>
<content/>
<div
class=
"w-full bg-slate-200 h-full m-auto relative container max-w-6xl rounded-xl"
>
<div
class=
"w-full bg-slate-200 h-full m-auto relative container max-w-6xl rounded-xl"
>
<div
class=
"w-full h-full pb-24 p-4 overflow-y-auto overflow-x-hidden"
ref=
"messageList"
>
<div
class=
"w-full h-full pb-24 p-4 overflow-y-auto overflow-x-hidden"
ref=
"messageList"
>
<div
v-for=
"(item,index) in message"
class=
"mb-8"
>
<div
v-for=
"(item,index) in message"
class=
"mb-8"
>
...
@@ -159,12 +162,16 @@
...
@@ -159,12 +162,16 @@
// import { Configuration, OpenAIApi } from "openai"
// import { Configuration, OpenAIApi } from "openai"
import
OpenAI
from
'
./js/openai.js
'
import
OpenAI
from
'
./js/openai.js
'
import
Config
from
'
./js/config.js
'
import
Config
from
'
./js/config.js
'
import
InsCodeAI
from
'
./js/inscodeai.js
'
import
SDApi
from
'
./js/sd.js
'
import
SDApi
from
'
./js/sd.js
'
import
StorageApi
from
'
./js/storage.js
'
import
StorageApi
from
'
./js/storage.js
'
import
PodsApi
from
'
./js/pod.js
'
import
PodsApi
from
'
./js/pod.js
'
import
RepEs
from
'
./js/repEs.js
'
import
RepEs
from
'
./js/repEs.js
'
import
{
MessagePlugin
}
from
'
tdesign-vue-next
'
;
import
{
MessagePlugin
}
from
'
tdesign-vue-next
'
;
import
Content
from
'
./components/content/index.vue
'
// import MarkdownItVue from 'markdown-it-vue'
// import MarkdownItVue from 'markdown-it-vue'
// import 'markdown-it-vue/dist/markdown-it-vue.css'
// import 'markdown-it-vue/dist/markdown-it-vue.css'
...
@@ -177,7 +184,7 @@ import 'markdown-it-vue/dist/markdown-it-vue.css'
...
@@ -177,7 +184,7 @@ import 'markdown-it-vue/dist/markdown-it-vue.css'
export
default
{
export
default
{
name
:
'
LlmApp
'
,
name
:
'
LlmApp
'
,
components
:
{
components
:
{
MarkdownItVue
MarkdownItVue
,
Content
},
},
data
()
{
data
()
{
return
{
return
{
...
@@ -276,7 +283,8 @@ export default {
...
@@ -276,7 +283,8 @@ export default {
})
})
},
},
initAIClient
()
{
initAIClient
()
{
this
.
client
=
new
OpenAI
(
this
.
config
)
// this.client = new OpenAI(this.config)
this
.
client
=
new
InsCodeAI
(
this
.
config
)
},
},
initIndexClient
()
{
initIndexClient
()
{
if
(
this
.
config
?.
index_url
)
{
if
(
this
.
config
?.
index_url
)
{
...
@@ -329,6 +337,8 @@ export default {
...
@@ -329,6 +337,8 @@ export default {
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
this
.
getAnswer
(
null
,
newPrompt
,
currentMsg
)
this
.
getAnswer
(
null
,
newPrompt
,
currentMsg
)
})
})
}
else
{
this
.
getAnswer
(
null
,
newPrompt
,
currentMsg
)
}
}
}
}
// if (this.indexClient) {
// if (this.indexClient) {
...
@@ -408,6 +418,7 @@ export default {
...
@@ -408,6 +418,7 @@ export default {
{
{
onmessage
:
(
msg
,
isPart
)
=>
{
onmessage
:
(
msg
,
isPart
)
=>
{
// _this.set(_this.message, id, currentMsg)
// _this.set(_this.message, id, currentMsg)
// console.info(msg)
if
(
isPart
)
{
if
(
isPart
)
{
currentMsg
.
message
+=
msg
currentMsg
.
message
+=
msg
}
else
{
}
else
{
...
@@ -564,6 +575,7 @@ export default {
...
@@ -564,6 +575,7 @@ export default {
})
})
},
},
initChat
()
{
initChat
()
{
this
.
initAIClient
()
this
.
initAIClient
()
this
.
initIndexClient
()
this
.
initIndexClient
()
const
config
=
this
.
config
const
config
=
this
.
config
...
...
src/components/content/index.vue
0 → 100644
浏览文件 @
c6099eb8
<
template
>
<div
class=
"container w-auto m-auto bg-gray-200 mb-10"
>
<div
class=
"p-4"
>
<span>
添加内容
</span>
<textarea
class=
"block my-2 w-full"
v-model=
"newContent"
></textarea>
<button
class=
"bg-gray-300 py-2 px-4 rounded hover:bg-gray-400"
>
ass
</button>
</div>
</div>
</
template
>
<
script
>
import
Config
from
'
../../js/config
'
import
RepEs
from
'
../../js/repEs
'
const
esClient
=
new
RepEs
(
Config
)
export
default
{
name
:
'
contentIndex
'
,
components
:
{
},
data
()
{
return
{
newContent
:
'
xxx
'
}
},
methods
:
{
add
()
{
esClient
}
}
}
</
script
>
\ No newline at end of file
src/js/config.js
浏览文件 @
c6099eb8
...
@@ -36,7 +36,7 @@ Inscode文档地址:https://inscode-doc.inscode.cc/
...
@@ -36,7 +36,7 @@ Inscode文档地址:https://inscode-doc.inscode.cc/
// 外部内容库,没有时指定为null,你也可以替换为自己的知识库
// 外部内容库,没有时指定为null,你也可以替换为自己的知识库
// const index_url = null
// const index_url = null
const
index_url
=
"
https://
api.quickapi.cloud/api/b/v1/es-api
"
const
index_url
=
"
https://
es-api.inscode.cc/
"
// 默认提示词
// 默认提示词
const
default_prompt
=
'
介绍下InsCode
'
const
default_prompt
=
'
介绍下InsCode
'
...
@@ -63,9 +63,11 @@ export default {
...
@@ -63,9 +63,11 @@ export default {
"
prompt_template
"
:
prompt_template
,
"
prompt_template
"
:
prompt_template
,
"
api_prompt_prefix
"
:
"
结合上下文回答问题,如果问题不是技术问题,请直接回答不知道。
\n
问题为:
"
,
"
api_prompt_prefix
"
:
"
结合上下文回答问题,如果问题不是技术问题,请直接回答不知道。
\n
问题为:
"
,
"
show_profile_setting
"
:
false
,
"
show_profile_setting
"
:
false
,
// "index_url": index_url,
// "index_name":"inscode",
"
search_url
"
:
index_url
,
// "index_type":"es",
"
index_name
"
:
"
inscode-rag
"
,
"
index_type
"
:
"
es
"
,
"
welcome_text
"
:
welcome_text
,
"
welcome_text
"
:
welcome_text
,
"
temperature
"
:
0.1
"
temperature
"
:
0.1
},
},
...
...
src/js/inscodeai.js
浏览文件 @
c6099eb8
import
{
fetchEventSource
}
from
'
@microsoft/fetch-event-source
'
;
import
{
fetchEventSource
}
from
'
@microsoft/fetch-event-source
'
;
import
Prompt
from
'
./prompt.js
'
import
Prompt
from
'
./prompt.js
'
class
OpenAI
{
const
apiKey
=
process
.
env
.
INSCODE_API_KEY
;
const
apiUrl
=
'
https://inscode-api.csdn.net/api/v1/gpt/
'
;
class
InsCodeAI
{
constructor
(
config
)
{
constructor
(
config
)
{
this
.
config
=
config
this
.
config
=
config
...
@@ -22,7 +25,7 @@ class OpenAI {
...
@@ -22,7 +25,7 @@ class OpenAI {
const
mode
=
config
?.
mode
??
'
chat
'
const
mode
=
config
?.
mode
??
'
chat
'
const
token
=
config
?.
token
??
'
empty
'
const
token
=
config
?.
token
??
'
empty
'
const
url
=
config
.
api_url
+
(
mode
===
'
chat
'
?
'
/chat/completions
'
:
'
/completions
'
)
const
url
=
apiUrl
const
stop
=
config
?.
stop
??
'
[DONE]
'
const
stop
=
config
?.
stop
??
'
[DONE]
'
const
max_tokens
=
config
?.
api_max_token
??
512
const
max_tokens
=
config
?.
api_max_token
??
512
const
model
=
config
?.
model
??
'
vicuna-13b-all-v1.1
'
const
model
=
config
?.
model
??
'
vicuna-13b-all-v1.1
'
...
@@ -38,7 +41,8 @@ class OpenAI {
...
@@ -38,7 +41,8 @@ class OpenAI {
temperature
:
parseFloat
(
temperature
),
temperature
:
parseFloat
(
temperature
),
top_p
:
parseFloat
(
top_p
),
top_p
:
parseFloat
(
top_p
),
stream
:
true
,
stream
:
true
,
stop
:
stop_key
stop
:
stop_key
,
apikey
:
apiKey
,
// prefix: prefix
// prefix: prefix
}
}
...
@@ -63,12 +67,13 @@ class OpenAI {
...
@@ -63,12 +67,13 @@ class OpenAI {
if
(
callback
?.
onclose
)
{
if
(
callback
?.
onclose
)
{
callback
?.
onclose
()
callback
?.
onclose
()
}
}
abortController
.
abort
();
//
abortController.abort();
return
return
}
else
{
}
else
{
console
.
info
(
msg
.
data
)
//
console.info(msg.data)
const
jsonData
=
JSON
.
parse
(
msg
.
data
)
const
jsonData
=
JSON
.
parse
(
msg
.
data
)
// 和上面重复触发,只留一个
// 和上面重复触发,只留一个
// if (jsonData.choices[0].finish_reason === 'stop') {
// if (jsonData.choices[0].finish_reason === 'stop') {
// if (callback?.onclose) {
// if (callback?.onclose) {
...
@@ -126,4 +131,4 @@ class OpenAI {
...
@@ -126,4 +131,4 @@ class OpenAI {
}
}
export
default
OpenAI
export
default
InsCodeAI
\ No newline at end of file
\ No newline at end of file
src/js/repEs.js
浏览文件 @
c6099eb8
...
@@ -7,12 +7,12 @@ class RepEs {
...
@@ -7,12 +7,12 @@ class RepEs {
this
.
config
=
config
this
.
config
=
config
this
.
index_url
=
config
.
index_url
this
.
index_url
=
config
.
index_url
this
.
index_name
=
config
.
index_name
this
.
index_name
=
config
.
index_name
this
.
url
=
this
.
index_url
+
'
?index_name=
'
+
this
.
index_name
this
.
token
=
process
.
env
?.
INSCODE_API_KEY
??
'
default
'
}
}
query
(
keyword
)
{
query
(
keyword
)
{
const
url
=
this
.
url
const
url
=
this
.
index_url
+
'
?user_token=
'
+
this
.
token
+
'
&index_name=
'
+
this
.
index_name
return
new
Promise
(
function
(
resolve
,
rejcet
){
return
new
Promise
(
function
(
resolve
,
rejcet
){
axios
.
get
(
url
,{
axios
.
get
(
url
,{
params
:
{
params
:
{
...
@@ -41,6 +41,37 @@ class RepEs {
...
@@ -41,6 +41,37 @@ class RepEs {
}
}
add
(
content
)
{
debugger
const
url
=
this
.
index_url
+
'
/
'
+
this
.
index_name
return
new
Promise
(
function
(
resolve
,
rejcet
){
axios
.
put
(
url
,{
data
:
{
content
:
content
,
}
}).
then
(
res
=>
{
if
(
res
?.
status
===
200
&&
res
?.
data
?.
code
===
200
)
{
const
result
=
[]
res
?.
data
?.
data
?.
hits
.
forEach
(
element
=>
{
result
.
push
({
page_content
:
element
?.
_source
?.
content
})
});
resolve
(
result
)
}
console
.
info
(
res
)
}).
catch
((
err
)
=>
{
console
.
error
(
err
)
rejcet
()
})
})
}
}
}
export
default
RepEs
export
default
RepEs
\ No newline at end of file
tailwind.config.js
浏览文件 @
c6099eb8
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
module
.
exports
=
{
module
.
exports
=
{
content
:
[
content
:
[
"
./index.html
"
,
"
./index.html
"
,
"
./src/components/*.{vue,js,ts,jsx,tsx}
"
,
"
./src/*.{vue,js,ts,jsx,tsx}
"
,
"
./src/*.{vue,js,ts,jsx,tsx}
"
,
"
./src/**/*.{vue,js,ts,jsx,tsx}
"
,
"
./src/**/*.{vue,js,ts,jsx,tsx}
"
,
],
],
...
...
vite.config.js
浏览文件 @
c6099eb8
...
@@ -6,5 +6,10 @@ export default defineConfig({
...
@@ -6,5 +6,10 @@ export default defineConfig({
server
:
{
server
:
{
host
:
true
host
:
true
},
},
plugins
:
[
vue
()]
plugins
:
[
vue
()],
define
:
{
'
process.env
'
:
{
INSCODE_API_KEY
:
process
.
env
.
INSCODE_API_KEY
}
}
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录