Merge branch 'ikechan8370:v2' into v2

This commit is contained in:
ifeif 2023-12-21 16:42:16 +08:00 committed by GitHub
commit d537e8abc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 1218 additions and 2838 deletions

View file

@ -1030,6 +1030,25 @@ export function getUserSpeaker (userSetting) {
}
}
/**
* 获取或者下载文件如果文件存在则直接返回不会重新下载
* @param destPath 相对路径如received/abc.pdf
* @param url
* @param ignoreCertificateError 忽略证书错误
* @return {Promise<string>} 最终下载文件的存储位置
*/
export async function getOrDownloadFile (destPath, url, ignoreCertificateError = true) {
const _path = process.cwd()
let dest = path.join(_path, 'data', 'chatgpt', destPath)
const p = path.dirname(dest)
mkdirs(p)
if (fs.existsSync(dest)) {
return dest
} else {
return await downloadFile(url, destPath, false, ignoreCertificateError)
}
}
/**
*
* @param url 要下载的文件链接

View file

@ -163,6 +163,11 @@ const defaultConfig = {
qwenSeed: 0,
qwenTemperature: 1,
qwenEnableSearch: true,
geminiKey: '',
geminiModel: 'gemini-pro',
geminiPrompt: 'You are Gemini. Your answer shouldn\'t be too verbose. Prefer to answer in Chinese.',
// origin: https://generativelanguage.googleapis.com
geminiBaseUrl: 'https://gemini.ikechan8370.com',
version: 'v2.7.8'
}
const _path = process.cwd()

View file

@ -80,7 +80,7 @@ export async function imageVariation (imageUrl, n = 1, size = '512x512') {
return response.data.data?.map(pic => pic.b64_json)
}
async function resizeAndCropImage (inputFilePath, outputFilePath, size = 512) {
export async function resizeAndCropImage (inputFilePath, outputFilePath, size = 512) {
// Determine the maximum dimension of the input image
let sharp
try {

View file

@ -1,5 +1,7 @@
// workaround for ver 7.x and ver 5.x
import HttpsProxyAgent from 'https-proxy-agent'
import { Config } from './config.js'
import fetch from 'node-fetch'
let proxy = HttpsProxyAgent
if (typeof proxy !== 'function') {
@ -15,3 +17,17 @@ if (typeof proxy !== 'function') {
export function getProxy () {
return proxy
}
export const newFetch = (url, options = {}) => {
const defaultOptions = Config.proxy
? {
agent: proxy(Config.proxy)
}
: {}
const mergedOptions = {
...defaultOptions,
...options
}
return fetch(url, mergedOptions)
}

View file

@ -1,5 +1,5 @@
import { Config } from './config.js'
import { ChatGPTAPI } from 'chatgpt'
import { ChatGPTAPI } from './openai/chatgpt-api.js'
import fetch from 'node-fetch'
import { getProxy } from './proxy.js'
let proxy = getProxy()

View file

@ -19,6 +19,9 @@ export class SendPictureTool extends AbstractTool {
func = async function (opt, e) {
let { urlOfPicture, targetGroupIdOrQQNumber } = opt
if (typeof urlOfPicture === 'object') {
urlOfPicture = urlOfPicture.join(' ')
}
const defaultTarget = e.isGroup ? e.group_id : e.sender.user_id
const target = isNaN(targetGroupIdOrQQNumber) || !targetGroupIdOrQQNumber
? defaultTarget

View file

@ -19,7 +19,7 @@ export class SerpIkechan8370Tool extends AbstractTool {
func = async function (opts) {
let { q, source } = opts
if (!source) {
if (!source || !['google', 'bing', 'baidu'].includes(source)) {
source = 'bing'
}
let serpRes = await fetch(`https://serp.ikechan8370.com/${source}?q=${encodeURIComponent(q)}&lang=zh-CN&limit=5`, {

View file

@ -34,7 +34,7 @@ export class SetTitleTool extends AbstractTool {
return `failed, the user ${qq} is not in group ${groupId}`
}
if (mm.get(e.bot.uin).role !== 'owner') {
return 'on group owner can give title'
return 'failed, only group owner can give title'
}
logger.info('edit card: ', groupId, qq)
let result = await group.setTitle(qq, title)