提交 c6099eb8 编写于 作者: W weixin_44463441

Thu Jan 11 12:02:00 CST 2024 inscode

上级 405fcf8b
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"
...@@ -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
......
<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
...@@ -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
}, },
......
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
...@@ -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
...@@ -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}",
], ],
......
...@@ -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.
先完成此消息的编辑!
想要评论请 注册