Skip to content

Commit

Permalink
🔧 为角色模板添加本地缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
tychozzz committed Jun 13, 2023
1 parent 418abbd commit 352d3bd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server/src/thirdpart/gptApi/gptApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,29 @@ const configuration = new Configuration({
});
const openai = new OpenAIApi(configuration);

// role - template 缓存
const roleMap = {}

async function generatePromptMessages(input, role) {
// 直接从缓存读取
if (roleMap[role]) {
let res = Object.assign(roleMap[role])
console.log("命中 roleMap 缓存")
return [
...res,
{
role: "user",
content: input,
},
]
}
let template = await loadPromptTemplate(
path.resolve(__dirname, `./template/${role}.md`)
);
console.log("template是:", template);
// 写入缓存
roleMap[role] = template.messages
console.log("未命中 roleMap 缓存")
return [
...template.messages,
{
Expand Down

0 comments on commit 352d3bd

Please sign in to comment.