-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b167efc
commit 5fee03a
Showing
10 changed files
with
2,565 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const google = require('@schneehertz/google-it') | ||
const { config } = require('../utils/loadConfig.js') | ||
|
||
const functionInfo = [ | ||
{ | ||
"name": "getInformationFromGoogle", | ||
"description": "Fetch information from Google based on a query string", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"queryString": { | ||
"type": "string", | ||
"description": "The search term to lookup", | ||
}, | ||
}, | ||
"required": ["queryString"], | ||
} | ||
}, | ||
{ | ||
"name": "getHistoricalConversationContent", | ||
"description": "Searching historical conversation content in conversation history.", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"relatedText": { | ||
"type": "string", | ||
"description": "The related text to find historical conversation content", | ||
}, | ||
}, | ||
"required": ["relatedText"], | ||
} | ||
}, | ||
] | ||
|
||
const functionAction = { | ||
getInformationFromGoogle ({queryString}) { | ||
return `休留正在搜索${queryString}` | ||
}, | ||
getHistoricalConversationContent ({relatedText}) { | ||
return `休留想起了关于${relatedText}的事情` | ||
} | ||
} | ||
|
||
const getInformationFromGoogle = async ({queryString}) => { | ||
let options = { proxy: config.proxyString } | ||
let additionalQueryParam = { | ||
lr: 'lang_zh-CN', | ||
hl: 'zh-CN', | ||
cr: 'countryCN', | ||
gl: 'cn', | ||
safe: 'high' | ||
} | ||
let googleRes = await google({options, disableConsole: true, query: queryString, limit: 6, additionalQueryParam}) | ||
// return googleRes.map(r=>r.snippet).join('\n').slice(0, 800) | ||
return JSON.stringify(googleRes) | ||
} | ||
|
||
const getHistoricalConversationContent = async ({relatedText, dbTable}) => { | ||
let MemoryTexts = await dbTable.search(relatedText).limit(2).execute() | ||
return MemoryTexts.map(s=>s.text).join('\n') | ||
} | ||
|
||
|
||
module.exports = { | ||
functionInfo, | ||
functionAction, | ||
functionList: { | ||
getInformationFromGoogle, | ||
getHistoricalConversationContent | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { app } = require('electron') | ||
const path = require('node:path') | ||
const fs = require('node:fs') | ||
|
||
let STORE_PATH = app.getPath('userData') | ||
if (!fs.existsSync(STORE_PATH)) { | ||
fs.mkdirSync(STORE_PATH) | ||
} | ||
|
||
let storeData | ||
try { | ||
storeData = JSON.parse(fs.readFileSync(path.join(STORE_PATH, 'storeData.json'), {encoding: 'utf-8'})) | ||
} catch { | ||
storeData = { | ||
history: [] | ||
} | ||
fs.writeFileSync(path.join(STORE_PATH, 'storeData.json'), JSON.stringify(storeData, null, ' '), {encoding: 'utf-8'}) | ||
} | ||
|
||
const getStore = (key, defaultValue)=>{ | ||
return storeData[key] || defaultValue | ||
} | ||
|
||
const setStore = (key, value)=>{ | ||
storeData[key] = value | ||
fs.writeFileSync(path.join(STORE_PATH, 'storeData.json'), JSON.stringify(storeData, null, ' '), {encoding: 'utf-8'}) | ||
} | ||
|
||
module.exports = { | ||
getStore, | ||
setStore | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.