This commit is contained in:
2025-05-05 22:41:18 +08:00
parent a412c09da0
commit 8891b196ba
12 changed files with 249 additions and 41 deletions

View File

@@ -0,0 +1,14 @@
{
"$vars": {
"root": "https://kevisual.cn/root/ai"
},
"registry": {
"root": "https://kevisual.cn/root/ai"
},
"match": {
"./xhs/answer.ts": {
"url": "${root}/xhs/answer.ts"
},
"./kevisual.json": {}
}
}

View File

@@ -0,0 +1,14 @@
{
"name": "@kevisual/social-prompts",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
"license": "MIT",
"packageManager": "pnpm@10.10.0",
"type": "module"
}

View File

@@ -0,0 +1,15 @@
{
"extends": "@kevisual/types/json/backend.json",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": [
"src/*"
]
}
},
"include": [
"xhs/**/*.ts",
],
"exclude": [],
}

View File

@@ -0,0 +1,34 @@
export const answer = [
{
role: 'system',
content: `你是一个小红书的内容回答问题的助手,用户提供一条笔记的信息,属于内容的上下文,和用户提供的问题,你需要给出一个简短的回答,回答要简洁明了,符合小红书的风格。
要求:
1. 不能包函链接,如果包函链接,把对应的链接的字符 "." 替换为魔法字符 "点",比如 https://www.baidu.com 替换为 https://www点baidu点com
2. 言语中不能包函文档类型比如md格式只需要对应的文本的内容
3. 只返回给我最后的结果,不需要思考过程
例子:
笔记内容是我有一个问题我有一个网页的html的内容不知道怎么打开
用户介绍一下怎么用vscode打开html网页
回答:
首先打开vscode然后把html文件拖到vscode中就可以打开了或者直接在vscode中打开html文件点击右上角的预览按钮就可以预览网页了。
现在可以开始了。
`,
},
];
export const createQuestion = (question: string, note: string, answers: any[] = []) => {
return [
...answers,
{
role: 'assistant',
content: `上下文的内参考的内容是: ${note}`,
},
{
role: 'user',
content: `用户: ${question}`,
},
];
};

View File

@@ -344,7 +344,7 @@ class XhsClient {
const state = stateMatch[1].replace(/undefined/g, '""');
if (state !== '{}') {
const noteDict = transformJsonKeys(JSON.parse(state));
return noteDict.note.note_detail_map[noteId].note;
return { code: 0, data: noteDict.note.note_detail_map[noteId].note };
}
}
@@ -355,8 +355,12 @@ class XhsClient {
throw new DataFetchError(html);
} catch (error) {
console.error('Error fetching note:', error);
fs.writeFileSync('a.html', html);
throw error;
return {
code: 500,
msg: '请求失败',
error: error.message,
data: null,
};
}
}
/**

View File

@@ -0,0 +1,68 @@
import { XhsClient, Result } from '../xhs.ts';
interface ImageInfo {
image_scene: string;
url: string;
}
interface ImageItem {
file_id: string;
height: number;
width: number;
url: string;
trace_id: string;
url_pre: string;
stream: Record<string, never>; // 空对象类型
info_list: ImageInfo[];
url_default: string;
live_photo: boolean;
}
interface AtUser {
xsec_token: string;
user_id: string;
nickname: string;
}
interface User {
user_id: string;
nickname: string;
avatar: string;
xsec_token: string;
}
interface InteractInfo {
collected_count: string;
comment_count: string;
share_count: string;
followed: boolean;
relation: string;
liked: boolean;
liked_count: string;
collected: boolean;
}
interface ShareInfo {
un_share: boolean;
}
interface NoteData {
xsec_token: string;
desc: string;
user: User;
interact_info: InteractInfo;
tag_list: never[]; // 空数组类型
at_user_list: AtUser[];
ip_location: string;
share_info: ShareInfo;
note_id: string;
type: string;
title: string;
image_list: ImageItem[];
time: number;
last_update_time: number;
}
export const getNote = async function (id: string, x: string) {
const that = this as XhsClient;
const res = await that.getNoteByIdFromHtml(id, x);
return res as Result<NoteData>;
};

View File

@@ -2,6 +2,7 @@ import { getApiInfo } from './xhs-api/api.ts';
import { XhsClient as XhsClientBase } from '@kevisual/xhs-core';
import { Mention, CommonentInfo, ResponseMession } from './xhs-type/mention.ts';
import { pick } from 'lodash-es';
import { getNote } from './modules/get-note.ts';
export type Result<T> = {
code: number; // 0: success
msg?: string;
@@ -211,7 +212,8 @@ export class XhsClient extends XhsClientBase {
try {
const response = await this.post(uri, data, { sign: this.sign.bind(this) });
return response['items'][0]['node_card'];
// return response['items'][0]['node_card'];
return response;
} catch (error) {
console.log(error);
}
@@ -221,7 +223,7 @@ export class XhsClient extends XhsClientBase {
* @param comment
* @returns
*/
async postComment(comment: { note_id: string; comment_id?: string; content: string; images_info?: any, images?: string[] }) {
async postComment(comment: { note_id: string; comment_id?: string; content: string; images_info?: any; images?: string[] }) {
const uri = '/api/sns/web/v1/comment/post';
try {
const data = {
@@ -249,6 +251,7 @@ export class XhsClient extends XhsClientBase {
console.log(error);
}
}
getNote = getNote;
}
type UnreadCount = {

View File

@@ -1,5 +1,5 @@
import { xhsServices, program } from '../common.ts';
import util from 'node:util';
// client.getNoteComments()
@@ -8,7 +8,7 @@ import { xhsServices, program } from '../common.ts';
// });
const getNoteById = async () => {
const client = xhsServices.getClient();
client.getNoteById('67dcc34e000000000602a8eb', 'ABuYS8Xb1o08DlRmMLIabdqnW0OKnLR9nMpDGq5bVRdvk').then((res) => {
client.getNoteById('68136dab0000000007034c46', 'LByEmonX8WfJ9ebpAowVbOZX9Xh8T0Qkjil5KRFqDD6LM').then((res) => {
console.log(res);
});
};
@@ -16,8 +16,8 @@ const getNote = async () => {
const id = '68136dab0000000007034c46';
const x = 'LByEmonX8WfJ9ebpAowVbOZX9Xh8T0Qkjil5KRFqDD6LM=';
const client = xhsServices.getClient();
client.getNoteByIdFromHtml(id, x).then((res) => {
console.log(res);
client.getNote(id, x).then((res) => {
console.log(util.inspect(res, { depth: null }));
});
};
program
@@ -32,4 +32,4 @@ program
.description('get note by id')
.action(async () => {
getNoteById();
});
});