fix: 实现Gemini客户端取代官方版本

This commit is contained in:
ikechan8370 2023-12-15 00:41:42 +08:00
parent 6769e9d3f0
commit bbe769f1aa
9 changed files with 431 additions and 2428 deletions

View file

@ -165,6 +165,8 @@ const defaultConfig = {
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

@ -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

@ -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`, {