Пример кода:
Код: Выделить всё
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import List, Optional
import newVector
app = FastAPI()
class Xitems(BaseModel):
items: List[str]
@app.post("/searchi")
async def searchi(xItems: Xitems):
items = xItems.items
try:
query = ' '.join(items)
results = newVector.searchCollection('ingredients', query, 10)
collection_direction = newVector.getCollection('directions')
collection_titles = newVector.getCollection('title')
directions = collection_direction.get(ids=results['ids'][0])
titles = collection_titles.get(ids=results['ids'][0])
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
return {"ingredients": str(results), "directions": str(directions), "titles": str(titles)}
Код: Выделить всё
Invoke-WebRequest : {"detail":"An error occurred: Expected ID to be a str, got
['911b8613-ee7e-4f5c-8dd8-987da61ed6c3', '8c486e26-2ebe-4ff3-8e56-81bf32e4cabe',
'345a7873-18e3-487b-9744-a49d65b879ec', '0f3b9bb8-3bb5-42c0-bbdd-a14e16a6797e',
'eda8f7e9-2f3b-4bd7-ac75-135147e1915d', 'f7351e82-9968-49cf-aed3-eeef0f3ca7ed',
'37ef1795-8f3f-4903-9c7b-c086e5aca787', '9830b1bc-7a4c-48d8-b3b6-cb47a82dc5cc',
'66cb637a-3e2d-424a-ae91-f2775839b2cc', 'c2246f77-bd8b-4c68-bff6-7272e8819f8d']"}
Код: Выделить всё
def get(
self,
ids: Optional[OneOrMany[ID]] = None,
where: Optional[Where] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["metadatas", "documents"],
) -> GetResult:
Код: Выделить всё
OneOrMany = Union[T, List[T]]
как описано выше
Подробнее здесь: https://stackoverflow.com/questions/790 ... ltiple-ids