forked from phoenix-oss/llama-stack-mirror
# What does this PR do? This PR changes our API to follow more idiomatic REST API approaches of having paths being resources and methods indicating the action being performed. Changes made to generator: 1) removed the prefix check of "get" as its not required and is actually needed for other method types too 2) removed _ check on path since variables can have "_" ## Test Plan LLAMA_STACK_BASE_URL=http://localhost:5000 pytest -v tests/client-sdk/agents/test_agents.py
67 lines
2 KiB
Python
67 lines
2 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
from typing import Any, Dict, List, Optional, Protocol, runtime_checkable
|
|
|
|
from llama_models.schema_utils import json_schema_type, webmethod
|
|
from pydantic import BaseModel, Field
|
|
|
|
from llama_stack.apis.common.content_types import URL
|
|
from llama_stack.apis.inference import InterleavedContent
|
|
from llama_stack.apis.memory_banks import MemoryBank
|
|
from llama_stack.providers.utils.telemetry.trace_protocol import trace_protocol
|
|
|
|
|
|
@json_schema_type
|
|
class MemoryBankDocument(BaseModel):
|
|
document_id: str
|
|
content: InterleavedContent | URL
|
|
mime_type: str | None = None
|
|
metadata: Dict[str, Any] = Field(default_factory=dict)
|
|
|
|
|
|
class Chunk(BaseModel):
|
|
content: InterleavedContent
|
|
token_count: int
|
|
document_id: str
|
|
|
|
|
|
@json_schema_type
|
|
class QueryDocumentsResponse(BaseModel):
|
|
chunks: List[Chunk]
|
|
scores: List[float]
|
|
|
|
|
|
class MemoryBankStore(Protocol):
|
|
def get_memory_bank(self, bank_id: str) -> Optional[MemoryBank]: ...
|
|
|
|
|
|
@runtime_checkable
|
|
@trace_protocol
|
|
class Memory(Protocol):
|
|
memory_bank_store: MemoryBankStore
|
|
|
|
# this will just block now until documents are inserted, but it should
|
|
# probably return a Job instance which can be polled for completion
|
|
@webmethod(route="/memory/insert", method="POST")
|
|
async def insert_documents(
|
|
self,
|
|
bank_id: str,
|
|
documents: List[MemoryBankDocument],
|
|
ttl_seconds: Optional[int] = None,
|
|
) -> None: ...
|
|
|
|
@webmethod(route="/memory/query", method="POST")
|
|
async def query_documents(
|
|
self,
|
|
bank_id: str,
|
|
query: InterleavedContent,
|
|
params: Optional[Dict[str, Any]] = None,
|
|
) -> QueryDocumentsResponse: ...
|