Add memory management APIs for OpenViking: list, read, write, and delete memories
This commit is contained in:
@ -190,6 +190,62 @@ class OpenVikingMemorySystemClient:
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
async def list_memories(
|
||||
self,
|
||||
credential: OpenVikingCredential | str,
|
||||
uri: str = "viking://user/memories",
|
||||
recursive: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
async with self._credential_client(credential) as client:
|
||||
response = await client.get(
|
||||
"/api/v1/fs/ls",
|
||||
params={"uri": uri, "recursive": str(recursive).lower()},
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
async def read_memory(self, credential: OpenVikingCredential | str, uri: str) -> dict[str, Any]:
|
||||
async with self._credential_client(credential) as client:
|
||||
response = await client.get("/api/v1/content/read", params={"uri": uri})
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
async def write_memory(
|
||||
self,
|
||||
credential: OpenVikingCredential | str,
|
||||
*,
|
||||
uri: str,
|
||||
content: str,
|
||||
mode: str = "create",
|
||||
wait: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
async with self._credential_client(credential) as client:
|
||||
response = await client.post(
|
||||
"/api/v1/content/write",
|
||||
json={
|
||||
"uri": uri,
|
||||
"content": content,
|
||||
"mode": mode,
|
||||
"wait": wait,
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
async def delete_memory(
|
||||
self,
|
||||
credential: OpenVikingCredential | str,
|
||||
uri: str,
|
||||
recursive: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
async with self._credential_client(credential) as client:
|
||||
response = await client.delete(
|
||||
"/api/v1/fs",
|
||||
params={"uri": uri, "recursive": str(recursive).lower()},
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
async def find(self, credential: OpenVikingCredential | str, query: str, limit: int) -> dict[str, Any]:
|
||||
user_id = credential.user_id if isinstance(credential, OpenVikingCredential) else None
|
||||
target_uri = f"viking://user/{user_id}/memories/" if user_id else "viking://user/memories/"
|
||||
|
||||
Reference in New Issue
Block a user