Prechádzať zdrojové kódy

feat(配置): 添加.ai-commit.json配置文件

- 定义了commit_options、diff_options和http_options等配置项
- 配置了retry策略
- 定义了commit message的类型和提示信息
- 配置了generators,包括bito_cli、ernie_bot、ernie_bot_turbo、moonshot和openai等
- 配置了prompts,包括conventional commit message的提示信息
luoyali 9 mesiacov pred
rodič
commit
2d01e77061

+ 128 - 0
.ai-commit.json

@@ -0,0 +1,128 @@
+{
+    "commit_options": [
+        "--edit"
+    ],
+    "diff_options": [
+        ":!*-lock.json",
+        ":!*.lock",
+        ":!*.sum"
+    ],
+    "http_options": {
+        "verify": false,
+        "connect_timeout": 30,
+        "timeout": 120
+    },
+    "retry": {
+        "times": 3,
+        "sleep": 200
+    },
+    "diff_mark": "<diff>",
+    "type_mark": "<type>",
+    "type_prompt_mark": "<type-prompt>",
+    "type_prompt": "- Use commit type `%s`.",
+    "types": {
+        "auto": "Automatically generate commit type",
+        "feat": "A new feature",
+        "fix": "A bug fix",
+        "docs": "Documentation only changes",
+        "style": "Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",
+        "refactor": "A code change that neither fixes a bug nor adds a feature",
+        "perf": "A code change that improves performance",
+        "test": "Adding missing tests or correcting existing tests",
+        "build": "Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)",
+        "ci": "Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)",
+        "chore": "Other changes that don't modify src or test files",
+        "revert": "Reverts a previous commit"
+    },
+    "no_edit": false,
+    "no_verify": false,
+    "prompt": "conventional",
+    "generator": "moonshot",
+    "generators": {
+        "bito_cli": {
+            "driver": "bito_cli",
+            "path": "bito",
+            "prompt_filename": "bito.prompt",
+            "parameters": {
+                "cwd": null,
+                "env": null,
+                "input": null,
+                "timeout": 120
+            }
+        },
+        "ernie_bot": {
+            "driver": "ernie_bot",
+            "api_key": "...",
+            "secret_key": "...",
+            "parameters": {
+                "temperature": 0.95,
+                "top_p": 0.8,
+                "penalty_score": 1,
+                "stream": true
+            }
+        },
+        "ernie_bot_turbo": {
+            "driver": "ernie_bot_turbo",
+            "api_key": "...",
+            "secret_key": "...",
+            "parameters": {
+                "temperature": 0.95,
+                "top_p": 0.8,
+                "penalty_score": 1,
+                "stream": true
+            }
+        },
+        "moonshot": {
+            "driver": "moonshot",
+            "api_key": "sk-SYN427v6luITEeMt8l3ZZR1KFaMQrrfVclRJBjgeY68QKZmi",
+            "parameters": {
+                "model": "moonshot-v1-8k",
+                "max_tokens": 600,
+                "temperature": 0,
+                "top_p": 1,
+                "n": 1,
+                "stream": true,
+                "stop": null,
+                "presence_penalty": 0,
+                "frequency_penalty": 0
+            }
+        },
+        "openai": {
+            "driver": "openai",
+            "api_key": "sk-SYN427v6luITEeMt8l3ZZR1KFaMQrrfVclRJBjgeY68QKZmi",
+            "parameters": {
+                "model": "text-davinci-003",
+                "suffix": null,
+                "max_tokens": 600,
+                "temperature": 0,
+                "top_p": 1,
+                "n": 1,
+                "stream": true,
+                "logprobs": null,
+                "echo": false,
+                "stop": null,
+                "presence_penalty": 0,
+                "frequency_penalty": 0,
+                "best_of": 1
+            }
+        },
+        "openai_chat": {
+            "driver": "openai_chat",
+            "api_key": "sk-SYN427v6luITEeMt8l3ZZR1KFaMQrrfVclRJBjgeY68QKZmi",
+            "parameters": {
+                "model": "gpt-3.5-turbo",
+                "max_tokens": 600,
+                "temperature": 0,
+                "top_p": 1,
+                "n": 1,
+                "stream": true,
+                "stop": null,
+                "presence_penalty": 0,
+                "frequency_penalty": 0
+            }
+        }
+    },
+    "prompts": {
+        "conventional": "Here are some best practices for writing commit messages:\n- Write clear, concise, and descriptive messages that explain the changes made in the commit.\n- Use the present tense and active voice in the message, for example, \"Fix bug\" instead of \"Fixed bug.\"\n- Use the imperative mood, which gives the message a sense of command, e.g. \"Add feature\" instead of \"Added feature\"\n- Limit the subject line to 72 characters or less.\n- Capitalize the subject line.\n- Do not end the subject line with a period.\n- Limit the body of the message to 256 characters or less.\n- Use a blank line between the subject and the body of the message.\n- Use the body of the message to provide additional context or explain the reasoning behind the changes.\n- Avoid using general terms like \"update\" or \"change\" in the subject line, be specific about what was updated or changed.\n- Explain, What was done at a glance in the subject line, and provide additional context in the body of the message.\n- Why the change was necessary in the body of the message.\n- The details about what was done in the body of the message.\n- Any useful details concerning the change in the body of the message.\n- Use a hyphen (-) for the bullet points in the body of the message.\n<type-prompt>\nWrite 1 commit messages that accurately summarizes the changes made in the given `git diff` output, following the best practices listed above and the conventional commit format in chinese.\nPlease provide a response in the form of a valid JSON object and do not include \"Output:\", \"Response:\" or anything similar to those two before it, in the following format:\n{\n    \"subject\": \"<type>(<scope>): <subject>\",\n    \"body\": \"<BODY (bullet points)>\"\n}\n\nHere is the output of the `git diff`:\n<diff>"
+    }
+}

+ 83 - 0
src/layout/components/Header/components/Message1.vue

@@ -0,0 +1,83 @@
+<template>
+	<el-popover placement="bottom" :width="310" trigger="click">
+		<template #reference>
+			<div class="menu--message-trigger">
+				<el-tooltip :content="$t('le.message.txt')" effect="dark" placement="bottom">
+					<div class="menu--message menu-item le-hover-effect--bg">
+						<el-badge :value="90" :max="99">
+							<i class="le-iconfont le-notice"></i>
+						</el-badge>
+					</div>
+				</el-tooltip>
+			</div>
+		</template>
+		<ul>
+			<li v-for="(item, idx) in receivedData" :key="idx"> {{ item }}</li>
+		</ul>
+	</el-popover>
+</template>
+<script setup>
+import { onMounted, ref, onBeforeUnmount } from 'vue';
+import {ls} from "@/utils";
+const token = ls.get('token')
+const { VITE_APP_BASE_API } = import.meta.env;
+// const serviceUrlApi = ref(`${VITE_APP_BASE_API}/sys/sse/connect`);
+const serviceUrlApi = ref(`http://localhost:3000/events`);
+let sseService = ref(null);
+let receivedData = ref([])
+
+// 创建一个新的 EventSource,但首先使用 fetch API 发送带有 Authorization 头的请求
+function connectSSEWithHeaders(url, headers = {}) {
+	return fetch(url, {
+		method: 'GET',
+		headers: headers,
+		cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
+		mode: 'cors', // no-cors, cors, *same-origin
+		credentials: 'same-origin', // include, *same-origin, omit
+		redirect: 'follow', // manual, *follow, error
+		referrerPolicy: 'no-referrer', // no-referrer, *client
+	})
+		.then(response => {
+			if (!response.ok) {
+				throw new Error('Network response was not ok');
+			}
+			return new EventSource(url);
+			// 读取响应体作为文本,然后解析URL来创建 EventSource
+			// const t = response.json()
+			// console.log(t);
+			// return response.text().then(text => {
+			//      console.info('text', text)
+			//       // 这里通常不需要解析text,因为我们只是要确认连接成功。
+			//       // 但如果SSE URL在响应体中,你可能需要处理它。
+			//       // 假设服务器直接支持SSE在原始URL
+			//
+			//   });
+		})
+		.catch(error => {
+			console.error('There was a problem with your fetch operation:', error);
+		});
+}
+
+
+onMounted(() => {
+	connectSSEWithHeaders(serviceUrlApi.value,  { 'accessToken': token })
+		.then(eventSource => {
+			sseService = eventSource
+			eventSource.onmessage = function(e) {
+				console.log(e, '----====----');
+				console.log('后端返回的数据:', e.data);
+				receivedData.value.push(e.data)
+			}
+			eventSource.onerror = function(err) {
+				console.error('EventSource failed:', err);
+			};
+		})
+})
+
+onBeforeUnmount(() => {
+	if (sseService) {
+		sseService.close();
+		sseService = null;
+	}
+});
+</script>