mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
fix(tools): pass apiKey to profile search instead of using process.env (#634)
This commit is contained in:
parent
10d8f92439
commit
aa5654f084
2 changed files with 29 additions and 25 deletions
|
|
@ -16,22 +16,23 @@ const supermemoryProfileSearch = async (
|
|||
containerTag: string,
|
||||
queryText: string,
|
||||
baseUrl: string,
|
||||
apiKey: string,
|
||||
): Promise<ProfileStructure> => {
|
||||
const payload = queryText
|
||||
? JSON.stringify({
|
||||
q: queryText,
|
||||
containerTag: containerTag,
|
||||
})
|
||||
q: queryText,
|
||||
containerTag: containerTag,
|
||||
})
|
||||
: JSON.stringify({
|
||||
containerTag: containerTag,
|
||||
})
|
||||
containerTag: containerTag,
|
||||
})
|
||||
|
||||
try {
|
||||
const response = await fetch(`${baseUrl}/v4/profile`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${process.env.SUPERMEMORY_API_KEY}`,
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
body: payload,
|
||||
})
|
||||
|
|
@ -57,7 +58,8 @@ export const addSystemPrompt = async (
|
|||
containerTag: string,
|
||||
logger: Logger,
|
||||
mode: "profile" | "query" | "full",
|
||||
baseUrl = "https://api.supermemory.ai",
|
||||
baseUrl: string,
|
||||
apiKey: string,
|
||||
): Promise<LanguageModelCallOptions> => {
|
||||
const systemPromptExists = params.prompt.some(
|
||||
(prompt) => prompt.role === "system",
|
||||
|
|
@ -66,22 +68,23 @@ export const addSystemPrompt = async (
|
|||
const queryText =
|
||||
mode !== "profile"
|
||||
? params.prompt
|
||||
.slice()
|
||||
.reverse()
|
||||
.find((prompt: { role: string }) => prompt.role === "user")
|
||||
?.content?.filter(
|
||||
(content: { type: string }) => content.type === "text",
|
||||
)
|
||||
?.map((content: { type: string; text: string }) =>
|
||||
content.type === "text" ? content.text : "",
|
||||
)
|
||||
?.join(" ") || ""
|
||||
.slice()
|
||||
.reverse()
|
||||
.find((prompt: { role: string }) => prompt.role === "user")
|
||||
?.content?.filter(
|
||||
(content: { type: string }) => content.type === "text",
|
||||
)
|
||||
?.map((content: { type: string; text: string }) =>
|
||||
content.type === "text" ? content.text : "",
|
||||
)
|
||||
?.join(" ") || ""
|
||||
: ""
|
||||
|
||||
const memoriesResponse = await supermemoryProfileSearch(
|
||||
containerTag,
|
||||
queryText,
|
||||
baseUrl,
|
||||
apiKey,
|
||||
)
|
||||
|
||||
const memoryCountStatic = memoriesResponse.profile.static?.length || 0
|
||||
|
|
@ -120,18 +123,18 @@ export const addSystemPrompt = async (
|
|||
const profileData =
|
||||
mode !== "query"
|
||||
? convertProfileToMarkdown({
|
||||
profile: {
|
||||
static: deduplicated.static,
|
||||
dynamic: deduplicated.dynamic,
|
||||
},
|
||||
searchResults: { results: [] },
|
||||
})
|
||||
profile: {
|
||||
static: deduplicated.static,
|
||||
dynamic: deduplicated.dynamic,
|
||||
},
|
||||
searchResults: { results: [] },
|
||||
})
|
||||
: ""
|
||||
const searchResultsMemories =
|
||||
mode !== "profile"
|
||||
? `Search results for user's recent message: \n${deduplicated.searchResults
|
||||
.map((memory) => `- ${memory}`)
|
||||
.join("\n")}`
|
||||
.map((memory) => `- ${memory}`)
|
||||
.join("\n")}`
|
||||
: ""
|
||||
|
||||
const memories =
|
||||
|
|
|
|||
|
|
@ -234,6 +234,7 @@ export const transformParamsWithMemory = async (
|
|||
ctx.logger,
|
||||
ctx.mode,
|
||||
ctx.normalizedBaseUrl,
|
||||
ctx.apiKey,
|
||||
)
|
||||
return transformedParams
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue