diff --git a/.inscode b/.inscode index a69885cbd936929979a05e7eea0a9178ab0a617d..a0966445421e7759d1f5016d1da418625133a8f8 100644 --- a/.inscode +++ b/.inscode @@ -1,14 +1,9 @@ -run = "cd dist; python3 -m http.server" +run = "npm i -f && npm run dev" language = "node" [deployment] -build = "npm i && npm run build" -run = "cd dist; python3 -m http.server" - -[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" +build = "npm i -f && npm run build" +run = "npm run preview" [debugger] program = "main.js" diff --git a/src/App.vue b/src/App.vue index 705e3fe34d67e5a9d5a62af707169e8b09e0d1bd..43c89fac36ad70e4e247cc5959c1672c9229f03a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -67,6 +67,9 @@
+ + +
@@ -159,12 +162,16 @@ // import { Configuration, OpenAIApi } from "openai" import OpenAI from './js/openai.js' import Config from './js/config.js' +import InsCodeAI from './js/inscodeai.js' + import SDApi from './js/sd.js' import StorageApi from './js/storage.js' import PodsApi from './js/pod.js' import RepEs from './js/repEs.js' import { MessagePlugin } from 'tdesign-vue-next'; +import Content from './components/content/index.vue' + // import MarkdownItVue from 'markdown-it-vue' // import 'markdown-it-vue/dist/markdown-it-vue.css' @@ -177,7 +184,7 @@ import 'markdown-it-vue/dist/markdown-it-vue.css' export default { name: 'LlmApp', components: { - MarkdownItVue + MarkdownItVue, Content }, data() { return { @@ -276,7 +283,8 @@ export default { }) }, initAIClient () { - this.client = new OpenAI(this.config) + // this.client = new OpenAI(this.config) + this.client = new InsCodeAI(this.config) }, initIndexClient () { if (this.config?.index_url) { @@ -329,6 +337,8 @@ export default { }).catch((err) => { this.getAnswer(null, newPrompt, currentMsg) }) + }else { + this.getAnswer(null, newPrompt, currentMsg) } } // if (this.indexClient) { @@ -408,6 +418,7 @@ export default { { onmessage: (msg, isPart) => { // _this.set(_this.message, id, currentMsg) + // console.info(msg) if (isPart) { currentMsg.message += msg } else { @@ -564,6 +575,7 @@ export default { }) }, initChat() { + this.initAIClient() this.initIndexClient() const config = this.config diff --git a/src/components/content/index.vue b/src/components/content/index.vue new file mode 100644 index 0000000000000000000000000000000000000000..ac0bcc1bc56a8a0d2407a623affa68ebfc78bf04 --- /dev/null +++ b/src/components/content/index.vue @@ -0,0 +1,34 @@ + + \ No newline at end of file diff --git a/src/js/config.js b/src/js/config.js index b99ef7ea47dedbb3d68dd9002b1b66154b45c445..ac39f0134874234c77c12073e780d78e64436787 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -36,7 +36,7 @@ Inscode文档地址:https://inscode-doc.inscode.cc/ // 外部内容库,没有时指定为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' @@ -63,9 +63,11 @@ export default { "prompt_template": prompt_template, "api_prompt_prefix":"结合上下文回答问题,如果问题不是技术问题,请直接回答不知道。\n问题为:", "show_profile_setting":false, - // "index_url": index_url, - // "index_name":"inscode", - // "index_type":"es", + + "search_url": index_url, + "index_name":"inscode-rag", + "index_type":"es", + "welcome_text": welcome_text, "temperature": 0.1 }, diff --git a/src/js/inscodeai.js b/src/js/inscodeai.js index af823b95605c8e3834bbebdb65a8ae5985c12948..9a578c0d178aa7556f998ffd05f46fe1a2a358c0 100644 --- a/src/js/inscodeai.js +++ b/src/js/inscodeai.js @@ -1,7 +1,10 @@ import { fetchEventSource } from '@microsoft/fetch-event-source'; 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) { this.config = config @@ -22,7 +25,7 @@ class OpenAI { const mode = config?.mode??'chat' const token = config?.token??'empty' - const url = config.api_url + (mode === 'chat' ? '/chat/completions' : '/completions') + const url = apiUrl const stop = config?.stop??'[DONE]' const max_tokens = config?.api_max_token??512 const model = config?.model??'vicuna-13b-all-v1.1' @@ -38,7 +41,8 @@ class OpenAI { temperature: parseFloat(temperature), top_p: parseFloat(top_p), stream: true, - stop: stop_key + stop: stop_key, + apikey: apiKey, // prefix: prefix } @@ -63,12 +67,13 @@ class OpenAI { if (callback?.onclose) { callback?.onclose() } - abortController.abort(); + // abortController.abort(); return } else { - console.info(msg.data) + // console.info(msg.data) const jsonData = JSON.parse(msg.data) + // 和上面重复触发,只留一个 // if (jsonData.choices[0].finish_reason === 'stop') { // if (callback?.onclose) { @@ -126,4 +131,4 @@ class OpenAI { } -export default OpenAI \ No newline at end of file +export default InsCodeAI \ No newline at end of file diff --git a/src/js/repEs.js b/src/js/repEs.js index 3762dc86a2641ab81122ed316cbfc2335ece7873..cce95838e068164197718d0b15b6c0ec180e92c2 100644 --- a/src/js/repEs.js +++ b/src/js/repEs.js @@ -7,12 +7,12 @@ class RepEs { this.config = config this.index_url = config.index_url 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) { - const url = this.url + const url = this.index_url + '?user_token=' + this.token + '&index_name=' + this.index_name return new Promise(function(resolve,rejcet){ axios.get(url,{ params: { @@ -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 \ No newline at end of file diff --git a/tailwind.config.js b/tailwind.config.js index 8bea3f55b1ed032ae6cf3f4fd3781196b201bb07..d2574d5d4f6010c4fdaf51768d57a62d9b7380f9 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -2,6 +2,7 @@ module.exports = { content: [ "./index.html", + "./src/components/*.{vue,js,ts,jsx,tsx}", "./src/*.{vue,js,ts,jsx,tsx}", "./src/**/*.{vue,js,ts,jsx,tsx}", ], diff --git a/vite.config.js b/vite.config.js index 4ad898dec614e030adad5e4f80523145bce56245..e6011caf3818ce7cf61b27f79fee39096c896e4d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -6,5 +6,10 @@ export default defineConfig({ server: { host: true }, - plugins: [vue()] + plugins: [vue()], + define: { + 'process.env': { + INSCODE_API_KEY: process.env.INSCODE_API_KEY + } + } })