Skip to content

Commit

Permalink
Fix fallback for keyword-based search
Browse files Browse the repository at this point in the history
  • Loading branch information
jaiamin committed Oct 19, 2023
1 parent decf8c2 commit 4efc25d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 5 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ services:
- "5173:5173"
environment:
REST_API_URL: http://localhost:8000
volumes:
- ./frontend:/app
# volumes:
# - ./frontend:/app

rest:
image: ghcr.io/catalystneuro/dandiset-search-service:latest
container_name: dandi-search-rest
command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]
command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4", "--reload"]
ports:
- "8000:8000"
environment:
Expand All @@ -34,3 +34,5 @@ services:
QDRANT_API_KEY: ${QDRANT_API_KEY}
OPENAI_API_KEY: ${OPENAI_API_KEY}
DANDI_API_KEY: ${DANDI_API_KEY}
volumes:
- ./rest:/app
13 changes: 11 additions & 2 deletions rest/clients/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,24 @@ def keywords_extraction(self, user_input: str, model: str = "gpt-3.5-turbo"):
)
chain = create_extraction_chain(schema, llm)
keywords_extracted = list(chain.run(user_input))

# Temporary fallback to extracting nouns (if no schema-related keywords found)
if any(isinstance(item, str) for item in keywords_extracted):
keywords_extracted = [{key: ""} for key in schema["properties"]]
# import nltk
# nltk.download(['punkt', 'averaged_perceptron_tagger'])
# words = nltk.word_tokenize(user_input)
# pos_tags = nltk.pos_tag(words)
# keywords_extracted = [noun for noun, tag in pos_tags if tag.startswith("N")]
# return keywords_extracted
return list(set(user_input.split()))

return self.prepare_keywords_for_semantic_search(keywords_extracted)


def prepare_keywords_for_semantic_search(self, keywords_list: list) -> list:
keywords_set = set()
for obj in keywords_list:
for k, v in obj.items():
for _, v in obj.items():
if v:
keywords_set.add(v.lower())
return list(keywords_set)
Expand Down

0 comments on commit 4efc25d

Please sign in to comment.