Skip to content

Commit 764f6c5

Browse files
authored
Question playground (#78)
* Initial playground * sub ref * Add save question via most_similar_by_embedding * Clean up most_similar_by_embedding * Remove unused fields * sub ref fix * Add question check * sub ref
1 parent b074954 commit 764f6c5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

app.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from pydantic import BaseModel
44
from typing import List, Optional, Dict, Any, Union
55
from neural_search import util
6-
from submodules.model.business_objects import general
6+
from submodules.model.business_objects import (
7+
general,
8+
playground_question as playground_question_db_bo,
9+
)
710
from submodules.model import session
811

912
app = FastAPI()
@@ -62,11 +65,13 @@ class MostSimilarByEmbeddingRequest(BaseModel):
6265
limit: int = 5
6366
att_filter: Optional[List[Dict[str, Any]]] = None
6467
threshold: Optional[Union[float, int]] = None
68+
question: Optional[str] = None
6569

6670

6771
@app.post("/most_similar_by_embedding")
6872
def most_similar_by_embedding(
69-
request: MostSimilarByEmbeddingRequest, include_scores: bool = False
73+
request: MostSimilarByEmbeddingRequest,
74+
include_scores: bool = False,
7075
) -> responses.JSONResponse:
7176
"""Find the n most similar records with respect to the specified embedding.
7277
Args:
@@ -95,6 +100,14 @@ def most_similar_by_embedding(
95100
request.threshold,
96101
include_scores,
97102
)
103+
104+
if request.question:
105+
playground_question_db_bo.create(
106+
request.project_id,
107+
request.question,
108+
with_commit=True,
109+
)
110+
98111
return responses.JSONResponse(
99112
status_code=status.HTTP_200_OK,
100113
content=similar_records,

0 commit comments

Comments
 (0)