Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Jan 18, 2025
1 parent dc9ff09 commit 6bb7f42
Show file tree
Hide file tree
Showing 80 changed files with 1,954 additions and 407 deletions.
25 changes: 15 additions & 10 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
import optimizeRegex from "eslint-plugin-optimize-regex"
import optimizeRegex from 'eslint-plugin-optimize-regex'

export default [
{
plugins: {
"optimize-regex": optimizeRegex
'optimize-regex': optimizeRegex
},
ignores: ["**/dist/*"],
ignores: ['**/dist/*'],
rules: {
// 移除多余的分号
semi: [
"error", "never"
'error', 'never'
],
// 当块内容只有一行时,移除块的大括号
curly: ["error", "multi"],
curly: ['error', 'multi'],
// tab 缩进
indent: ["error", "tab", {
indent: ['error', 'tab', {
VariableDeclarator: 1,
MemberExpression: 1,
SwitchCase: 1,
ignoredNodes: [
'ConditionalExpression'
]
}],
// 鼓励单引号
quotes: ['error', 'single'],
// 去除不必要小括号
"no-extra-parens": ["error", "all", {
"nestedBinaryExpressions": false, // 允许嵌套二元表达式中有括号
"returnAssign": false // 允许 return 语句中的赋值表达式中有括号
'no-extra-parens': ['error', 'all', {
nestedBinaryExpressions: false, // 允许嵌套二元表达式中有括号
returnAssign: false // 允许 return 语句中的赋值表达式中有括号
}],
"optimize-regex/optimize-regex": "warn"
// if中的没有await的promise
'no-constant-condition': ['error', { checkLoops: false }],
// 优化正则
'optimize-regex/optimize-regex': 'warn'
}
}
]
1 change: 1 addition & 0 deletions src/decl/AIsource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class tokenizer_t<InputType, TokenType> {
}

export class AIsource_t<InputType, OutputType> {
filename: string;
info: Record<locale_t, {
avatar: string;
name: string;
Expand Down
12 changes: 5 additions & 7 deletions src/decl/UserAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ export class UserAPI_t {
// calls on uninstall
Uninstall: (reason: string, from: string) => void;

// set the source of the AI so that persona can use it by `source.Call(prompt)`
// the type is for extensibility. maybe youll use an API for sfw and an other API for nsfw, idc.
SetAISource: (source: AIsource_t<any, any>, type: string) => void;
GetAISource: (type: string) => AIsource_t<any, any>;
AISourceTypes: { name: string; type: string }[];

interfacies: {
interfaces: {
config: {
GetData: () => Promise<any>
SetData: (data: any) => Promise<void>
},
chat: {
GetPrompt: (arg: chatReplyRequest_t, prompt_struct: prompt_struct_t, detail_level: number) => Promise<single_part_prompt_t>;
GetChatLog: (arg: chatReplyRequest_t) => Promise<chatLogEntry_t[]>
Expand Down
12 changes: 5 additions & 7 deletions src/decl/WorldAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ export class WorldAPI_t {
// calls on uninstall
Uninstall: (reason: string, from: string) => void;

// set the source of the AI so that persona can use it by `source.Call(prompt)`
// the type is for extensibility. maybe youll use an API for sfw and an other API for nsfw, idc.
SetAISource: (source: AIsource_t<any, any>, type: string) => void;
GetAISource: (type: string) => AIsource_t<any, any>;
AISourceTypes: { name: string; type: string }[];

interfacies: {
interfaces: {
config: {
GetData: () => Promise<any>
SetData: (data: any) => Promise<void>
},
chat: {
GetGreeting: (arg: chatReplyRequest_t, index: number) => Promise<chatReply_t>
GetGroupGreeting: (arg: chatReplyRequest_t, index: number) => Promise<chatReply_t>
Expand Down
26 changes: 13 additions & 13 deletions src/decl/charAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { locale_t, timeStamp_t } from './basedefs.ts';
import { AIsource_t } from './AIsource.ts';
import { chatLogEntry_t, prompt_struct_t, single_part_prompt_t } from './prompt_struct.ts';
import { chatReply_t, chatReplyRequest_t } from '../public/shells/chat/decl/chatLog.ts';

Expand All @@ -9,9 +8,12 @@ export class charState_t {
InitCount: number;
StartCount: number;
LastStart: timeStamp_t;
memories: {
extension: {};
};
}

export class charInit_t {
state: charState_t;
username: string;
charname: string;
}

export class charAPI_t {
Expand All @@ -27,22 +29,20 @@ export class charAPI_t {
tags: string[];
}>;
// calls only on char install, and if fail, all file under this char's folder will be deleted
Init: (stat: charState_t) => void;
Init: (stat: charInit_t) => void;
// calls on every char start, pop a message if fail
Load: (stat: charState_t) => void;
Load: (stat: charInit_t) => void;
// calls on every char unload
Unload: (reason: string) => void;
// calls on char uninstall
Uninstall: (reason: string, from: string) => void;

// set the source of the AI so that char can use it by `source.Call(prompt)`
// the type is for extensibility. maybe youll use an API for sfw and an other API for nsfw, idc.
SetAISource: (source: AIsource_t<any, any>, type: string) => void;
GetAISource: (type: string) => AIsource_t<any, any>;
AISourceTypes: { name: string; type: string }[];

// interface with shell (maybe chat WebUI or cute Live2d or a kill machine, i don't care)
interfacies: {
interfaces: {
config: {
GetData: () => Promise<any>
SetData: (data: any) => Promise<void>
},
chat: {
GetGreeting: (arg: chatReplyRequest_t, index: number) => Promise<chatReply_t>
GetGroupGreeting: (arg: chatReplyRequest_t, index: number) => Promise<chatReply_t>
Expand Down
4 changes: 3 additions & 1 deletion src/decl/importHanlderAPI.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "node:buffer";
import { locale_t } from "./basedefs";

export class importHanlderAPI_t {
Expand All @@ -21,5 +22,6 @@ export class importHanlderAPI_t {
// calls on char uninstall
Uninstall: (reason: string, from: string) => void;

ImportChar: (username: string, chardata: Buffer) => Promise<void>;
ImportAsData: (username: string, chardata: Buffer) => Promise<void>;
ImportByText: (username: string, text: string) => Promise<void>
}
10 changes: 5 additions & 5 deletions src/decl/pluginAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export class pluginAPI_t {
Unload: (reason: string) => void;
Uninstall: (reason: string, from: string) => void;

SetAISource: (source: AIsource_t<any, any>, type: string) => void;
GetAISource: (type: string) => AIsource_t<any, any>;
AISourceTypes: { name: string; type: string }[];

interfacies: {
interfaces: {
config: {
GetData: () => Promise<any>
SetData: (data: any) => Promise<void>
},
chat: {
GetPrompt: (arg: chatReplyRequest_t, prompt_struct: prompt_struct_t, detail_level: number) => Promise<single_part_prompt_t>;
RepalyHandler: (repaly: chatLogEntry_t, functions: {
Expand Down
2 changes: 1 addition & 1 deletion src/public/AIsourceGenerators/blackbox/main.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { with_timeout } from "../../../scripts/await_timeout.mjs"
import { with_timeout } from '../../../scripts/await_timeout.mjs'
import { margeStructPromptChatLog, structPromptToSingleNoChatLog } from '../../shells/chat/src/server/prompt_struct.mjs'
import { BlackboxAI } from './blackbox.mjs'
/** @typedef {import('../../../decl/AIsource.ts').AIsource_t} AIsource_t */
Expand Down
6 changes: 3 additions & 3 deletions src/public/AIsourceGenerators/duckduckgo/duckduckgo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class DuckDuckGoAPI {

async requestToken() {
try {
const response = await fetch(`https://duckduckgo.com/duckchat/v1/status`, {
const response = await fetch('https://duckduckgo.com/duckchat/v1/status', {
method: 'GET',
headers: {
...this.fake_headers,
Expand All @@ -31,14 +31,14 @@ export class DuckDuckGoAPI {
})
return response.headers.get('x-vqd-4')
} catch (error) {
console.error("Request token error: ", error)
console.error('Request token error: ', error)
throw error
}
}

async createCompletion(model, content, returnStream) {
const token = await this.requestToken()
const response = await fetch(`https://duckduckgo.com/duckchat/v1/chat`, {
const response = await fetch('https://duckduckgo.com/duckchat/v1/chat', {
method: 'POST',
headers: {
...this.fake_headers,
Expand Down
6 changes: 3 additions & 3 deletions src/public/AIsourceGenerators/gemini/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ system:
role: chatLogEntry.role === 'user' ? 'user' : 'model',
parts: [
{ text: chatLogEntry.name + ':\n' + chatLogEntry.content },
...(chatLogEntry.files || []).map(file => ({ inlineData: { data: file.buffer.toString("base64"), mimeType: file.mimeType } }))
...(chatLogEntry.files || []).map(file => ({ inlineData: { data: file.buffer.toString('base64'), mimeType: file.mimeType } }))
],
})
})
Expand All @@ -97,7 +97,7 @@ system:
request.contents = request.contents.concat([
{
role: 'user',
parts: [{ text: `system:\n暂停扮演,请你在xml标签<pause>中重新整理并回复你的目标,随后继续扮演。` }]
parts: [{ text: 'system:\n暂停扮演,请你在xml标签<pause>中重新整理并回复你的目标,随后继续扮演。' }]
},
{
role: 'model',
Expand Down Expand Up @@ -127,7 +127,7 @@ system:
}

// 移除<declare></declare>
text = text.replace(/<declare>([^<]*)<\/declare>\s*$/g, '')
text = text.replace(/<\/?declare>([^<]*)<\/?declare>\s*$/g, '')

text = text.split('\n')
while (['', '</pause>', '</declare>'].includes(text[text.length - 1].trim())) text.pop() //?
Expand Down
Loading

0 comments on commit 6bb7f42

Please sign in to comment.