search for followups based on both initial query and generated response

This commit is contained in:
Fraser
2023-06-01 23:38:39 -04:00
parent 820d70a3ab
commit e2fd7def4b
2 changed files with 17 additions and 7 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
# ------------------------------- env, constants -------------------------------
from followups import search_authored
from followups import multisearch_authored
from get_blocks import get_top_k_blocks, Block
@@ -171,7 +171,7 @@ def talk_to_robot(index, query: str, history: List[Dict[str, str]], k: int = STA
log(query)
log(response)
search_authored(response, DEBUG_PRINT)
multisearch_authored([query, response], DEBUG_PRINT)
yield json.dumps({"state": "done"})
+15 -5
View File
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from typing import List
from urllib.parse import quote
import requests
@@ -15,12 +16,21 @@ class Followup:
# https://nlp.stampy.ai/api/search?query=what%20is%20agi
def search_authored(query: str, DEBUG_PRINT: bool = False):
url = 'https://nlp.stampy.ai/api/search?query=' + quote(query)
response = requests.get(url).json()
followups = [ Followup(entry['title'], entry['pageid'], entry['score']) for entry in response ]
multisearch_authored([query], DEBUG_PRINT)
# (note: api presently returns followups pre-sorted, but idk if that's
# guaranteed to stay the case. Re-sorting should be cheap anyway).
# search with multiple queries, combine results
def multisearch_authored(queries: List[str], DEBUG_PRINT: bool = False):
followups = {}
for query in queries:
url = 'https://nlp.stampy.ai/api/search?query=' + quote(query)
response = requests.get(url).json()
for entry in response:
followups[entry['pageid']] = Followup(entry['title'], entry['pageid'], entry['score'])
followups = list(followups.values())
followups.sort(key=lambda f: f.score, reverse=True)