提交 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"
[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"
......@@ -67,6 +67,9 @@
</div>
<!-- right -->
<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 h-full pb-24 p-4 overflow-y-auto overflow-x-hidden" ref="messageList">
<div v-for="(item,index) in message" class="mb-8">
......@@ -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
......
<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/
// 外部内容库,没有时指定为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
},
......
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
......@@ -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
......@@ -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}",
],
......
......@@ -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
}
}
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册