重构部分代码

This commit is contained in:
mcallzbl 2025-04-02 19:57:39 +08:00
parent 0df00ba33e
commit 03e1e5662d
5 changed files with 59 additions and 10 deletions

View File

@ -1,12 +1,12 @@
{
"name": "lingtropy",
"version": "1.0.1",
"version": "1.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "lingtropy",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"dependencies": {
"@mdi/font": "^7.4.47",

View File

@ -1,7 +1,7 @@
{
"name": "lingtropy",
"appId": "com.lingnite.lingtropy",
"version": "1.0.1",
"version": "1.0.2",
"description": "文案助手",
"homepage": "https://www.lingnite.com",
"author": "沈阳泠启网络科技有限公司",

View File

@ -0,0 +1,42 @@
// API 相关
export const API_ENDPOINTS = {
GET_BASE_URL: 'https://aqq-jbjsjuxivc.cn-hangzhou.fcapp.run',
FETCH_MODELS: 'https://get-model-list-vcwjgnvcld.cn-hangzhou.fcapp.run'
} as const
// AI 模型相关
export const AI_CONFIG = {
DEFAULT_MODEL: 'gpt-4o',
CONTENT_MAX_TOKENS: 1800, // 约900字
TITLE_MAX_TOKENS: 50, // 约20字
TEMPERATURE: 0.8,
MAX_RETRIES: 2,
TIMEOUT: 30000
} as const
// 提示词模板
export const PROMPTS = {
CONTENT_REWRITE: '你是一个小红书文案写手,能够熟练地根据用户的输入,改写成内容相近,但表达方式不同的新文案。你的文案中需要具备吸人眼球的钩子,能够牢牢抓住用户的注意力。请直接输出新的文案,不要输出其他任何提示性词语, 以纯文本的形式输出。注意输出的文案不要超过900字。',
TITLE_REWRITE: '你是一个小红书标题写手,能够熟练地根据用户的输入,改写成内容相近,但表达方式不同的新标题。你的标题中需要具备吸人眼球的钩子,能够牢牢抓住用户的注意力。请直接输出新的标题,不要输出其他任何提示性词语, 以纯文本的形式输出。注意输出的标题不要超过20字。'
} as const
// 存储键名
export const STORE_KEYS = {
API_KEY: 'api-key',
LAYOUT_MODE: 'layoutMode',
GENERATION_COUNT: 'generationCount'
} as const
// UI 相关
export const UI_CONFIG = {
DEFAULT_LAYOUT: 'list',
DEFAULT_COUNT: 3,
MAX_COUNT: 10,
MIN_COUNT: 1
} as const
// 应用信息
// export const APP_INFO = {
// VERSION: '1.0.0',
// NAME: 'LingTropy'
// } as const

View File

@ -3,6 +3,13 @@ import Constants from './utils/Constants'
import Store from 'electron-store'
import axios from 'axios'
import OpenAI from 'openai'
import {
API_ENDPOINTS,
AI_CONFIG,
PROMPTS,
STORE_KEYS,
APP_INFO
} from '../constants'
const store = new Store()
/*
@ -38,7 +45,7 @@ export default class IPCs {
ipcMain.handle('fetch-models', async () => {
try {
const response = await axios.get('https://get-model-list-vcwjgnvcld.cn-hangzhou.fcapp.run') // 从网络获取数据
const response = await axios.get(API_ENDPOINTS.FETCH_MODELS)
console.log('获取模型数据成功:', response.data)
return response.data.data
} catch (error) {
@ -49,7 +56,7 @@ export default class IPCs {
ipcMain.handle('getBaseUrl', async () => {
try {
const response = await axios.get('https://aqq-jbjsjuxivc.cn-hangzhou.fcapp.run')
const response = await axios.get(API_ENDPOINTS.GET_BASE_URL)
console.log('获取baseUrl成功:', response.data)
return response.data.data
} catch (error) {
@ -82,12 +89,12 @@ export default class IPCs {
messages: [
{
role: 'system',
content:
'你是一个小红书文案写手,能够熟练地根据用户的输入,改写成内容相近,但表达方式不同的新文案。你的文案中需要具备吸人眼球的钩子,能够牢牢抓住用户的注意力。请直接输出新的文案,不要输出其他任何提示性词语, 以纯文本的形式输出。注意输出的文案不要超过900字。'
content: PROMPTS.CONTENT_REWRITE
},
{ role: 'user', content: rawArticle }
],
max_tokens: 1800, // 约900字
max_tokens: AI_CONFIG.CONTENT_MAX_TOKENS,
temperature: AI_CONFIG.TEMPERATURE,
stream: true
})
.then(async (stream) => {

View File

@ -3339,7 +3339,7 @@ lie@~3.3.0:
immediate "~3.0.5"
"lingtropy@file:":
version "1.0.1"
version "1.0.2"
resolved "file:"
dependencies:
"@mdi/font" "^7.4.47"
@ -3354,7 +3354,7 @@ lie@~3.3.0:
vuetify "^3.7.14"
"lingtropy2@file:":
version "1.0.1"
version "1.0.2"
resolved "file:"
dependencies:
"@mdi/font" "^7.4.47"