(Update) Vercel AI SDK v0.0.10 (#2104)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mem0/vercel-ai-provider",
|
||||
"version": "0.0.9",
|
||||
"version": "0.0.10",
|
||||
"description": "Vercel AI Provider for providing memory to LLMs",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
|
||||
@@ -33,6 +33,11 @@ export interface Mem0ChatSettings extends OpenAIChatSettings {
|
||||
structuredOutputs?: boolean;
|
||||
org_id?: string;
|
||||
project_id?: string;
|
||||
metadata?: Record<string, any>;
|
||||
filters?: Record<string, any>;
|
||||
infer?: boolean;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
}
|
||||
|
||||
export interface Mem0Config extends Mem0ChatSettings {}
|
||||
@@ -28,6 +28,28 @@ const flattenPrompt = (prompt: LanguageModelV1Prompt) => {
|
||||
}).join(" ");
|
||||
}
|
||||
|
||||
const convertToMem0Format = (messages: LanguageModelV1Prompt) => {
|
||||
return messages.flatMap((message: any) => {
|
||||
if (typeof message.content === 'string') {
|
||||
return {
|
||||
role: message.role,
|
||||
content: message.content,
|
||||
};
|
||||
}
|
||||
else{
|
||||
return message.content.map((obj: any) => {
|
||||
if (obj.type === "text") {
|
||||
return {
|
||||
role: message.role,
|
||||
content: obj.text,
|
||||
};
|
||||
} else {
|
||||
return null; // Handle other cases or return null/undefined as needed
|
||||
}
|
||||
}).filter((item: null) => item !== null); // Filter out null values if necessary
|
||||
}
|
||||
})};
|
||||
|
||||
function convertMessagesToMem0Format(messages: LanguageModelV1Prompt) {
|
||||
return messages.map((message) => {
|
||||
// If the content is a string, return it as is
|
||||
@@ -92,11 +114,13 @@ const searchInternalMemories = async (query: string, config?: Mem0Config, top_k:
|
||||
|
||||
const addMemories = async (messages: LanguageModelV1Prompt, config?: Mem0Config)=>{
|
||||
tokenIsPresent(config);
|
||||
const message = flattenPrompt(messages);
|
||||
const response = await updateMemories([
|
||||
{ role: "user", content: message },
|
||||
{ role: "assistant", content: "Thank You!" },
|
||||
], config);
|
||||
let finalMessages: Array<Message> = [];
|
||||
if (typeof messages === "string") {
|
||||
finalMessages = [{ role: "user", content: messages }];
|
||||
}else {
|
||||
finalMessages = convertToMem0Format(messages);
|
||||
}
|
||||
const response = await updateMemories(finalMessages, config);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user