Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dicklesworthstone committed May 22, 2024
1 parent c44feea commit 39f5648
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion service_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ async def _get_embedding_from_db(text_hash: str, llm_model_name: str) -> Optiona
row = result.fetchone()
if row:
embedding_json = row[0]
logger.info(f"Embedding found in database for text hash '{text_hash}' using model '{llm_model_name}'")
return json.loads(embedding_json)
return None

Expand Down
8 changes: 4 additions & 4 deletions swiss_army_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ async def get_token_level_embeddings_matrix_and_combined_feature_vector_for_stri
```""")
async def compute_similarity_between_strings(request: SimilarityRequest, req: Request, token: str = None) -> SimilarityResponse:
request.text1 = prepare_string_for_embedding(request.text1)
request.text1 = prepare_string_for_embedding(request.text2)
request.text2 = prepare_string_for_embedding(request.text2)
logger.info(f"Received request: {request}")
request_time = datetime.utcnow()
similarity_measure = request.similarity_measure.lower()
Expand All @@ -542,8 +542,8 @@ async def compute_similarity_between_strings(request: SimilarityRequest, req: Re
client_ip = req.client.host if req else "localhost"
embedding_request1 = EmbeddingRequest(text=request.text1, llm_model_name=request.llm_model_name)
embedding_request2 = EmbeddingRequest(text=request.text2, llm_model_name=request.llm_model_name)
embedding1_response = await get_or_compute_embedding(embedding_request1, client_ip=client_ip)
embedding2_response = await get_or_compute_embedding(embedding_request2, client_ip=client_ip)
embedding1_response = await get_or_compute_embedding(request=embedding_request1, req=req, client_ip=client_ip, use_verbose=False)
embedding2_response = await get_or_compute_embedding(request=embedding_request2, req=req, client_ip=client_ip, use_verbose=False)
embedding1 = np.array(embedding1_response["embedding"])
embedding2 = np.array(embedding2_response["embedding"])
if embedding1.size == 0 or embedding2.size == 0:
Expand All @@ -563,7 +563,7 @@ async def compute_similarity_between_strings(request: SimilarityRequest, req: Re
raise HTTPException(status_code=400, detail="Invalid similarity measure specified")
response_time = datetime.utcnow()
total_time = (response_time - request_time).total_seconds()
logger.info(f"Computed similarity using {similarity_measure} in {total_time:,.2f} seconds; similarity score: {similarity_score:,.6f}")
logger.info(f"Computed similarity using {similarity_measure} in {total_time:,.2f} seconds; similarity score: {similarity_score}")
return {
"text1": request.text1,
"text2": request.text2,
Expand Down

0 comments on commit 39f5648

Please sign in to comment.