diff --git a/.inscode b/.inscode
index 75cbde42e38700eb5f08c445b5175ecf9cf63c5d..9fec9576d482baaf90d2f47230ce9133cfce99d4 100644
--- a/.inscode
+++ b/.inscode
@@ -11,4 +11,4 @@ XDG_CONFIG_HOME = "/root/.config"
npm_config_prefix = "/root/${PROJECT_DIR}/.config/npm/node_global"
[debugger]
-program = "main.js"
\ No newline at end of file
+program = "main.js"
diff --git a/src/App.vue b/src/App.vue
index 633a5dfe4e547c48bfa93740a290ba5ba370930a..ff10dc950332673ec57c80f59c83ac90a0c65d9a 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,47 +1,245 @@
+
+
+
+
+
+
+ Powered By liyuzhu
+
+
+
+
+
+import { ref } from 'vue';
+import axios from 'axios';
+import MarkdownIt from 'markdown-it';
+import { fetchEventSource } from 'fetch-event-source';
-
-
-
+const userInput = ref('');
+const chatMessages = ref([]);
+const loading = ref(false);
+const md = new MarkdownIt();
-
-
-
-
+const sendMessage = async () => {
+ if (loading.value || userInput.value.trim() === '') return;
+ loading.value = true;
-
-
-
-
+ const userMessage = { sender: '你', text: userInput.value };
+ chatMessages.value.push(userMessage);
+ userInput.value = '';
+
+ let aiResponse = '';
+ let aiMessageIndex = chatMessages.value.length;
+ chatMessages.value.push({ sender: 'AI', text: 'AI 思考中...' });
+
+ try {
+ await fetchEventSource('http://localhost:11434/api/generate', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ model: 'gemma3:12b',
+ prompt: userMessage.text
+ }),
+ onmessage: (event) => {
+ if (event.data === '[DONE]') return;
+ try {
+ const data = JSON.parse(event.data);
+ aiResponse += data.response;
+ chatMessages.value[aiMessageIndex].text = aiResponse;
+ } catch (error) {
+ console.error('解析响应数据出错:', error);
+ }
+ },
+ onclose: () => {
+ loading.value = false;
+ },
+ onerror: (error) => {
+ console.error('请求出错:', error);
+ let errorText = '无法连接到模型,请检查服务是否运行。';
+ if (error.response) {
+ errorText += ` 服务器响应错误: ${JSON.stringify(error.response.data)}`;
+ } else if (error.request) {
+ errorText += ' 没有收到服务器响应。';
+ } else {
+ errorText += ` 错误信息: ${error.message}`;
+ }
+ const errorMessage = { sender: '错误', text: errorText };
+ chatMessages.value.push(errorMessage);
+ loading.value = false;
+ }
+ });
+ } catch (error) {
+ console.error('请求出错:', error);
+ let errorText = '无法连接到模型,请检查服务是否运行。';
+ if (error.response) {
+ errorText += ` 服务器响应错误: ${JSON.stringify(error.response.data)}`;
+ } else if (error.request) {
+ errorText += ' 没有收到服务器响应。';
+ } else {
+ errorText += ` 错误信息: ${error.message}`;
+ }
+ const errorMessage = { sender: '错误', text: errorText };
+ chatMessages.value.push(errorMessage);
+ loading.value = false;
+ }
+};
+
+const handleNewChat = () => {
+ chatMessages.value = [];
+};
+
+const renderMarkdown = (text) => {
+ return md.render(text);
+};
+
+const handleKeyDown = (event) => {
+ if (event.shiftKey && event.key === 'Enter') {
+ // Shift + Enter 实现换行
+ userInput.value += '\n';
+ event.preventDefault();
+ } else if (event.key === 'Enter') {
+ // Enter 发送消息
+ sendMessage();
+ event.preventDefault();
+ }
+};
+
+
\ No newline at end of file