mirror of
https://github.com/wassname/stampy-chat.git
synced 2026-09-13 13:10:58 +08:00
search for followups based on both initial query and generated response
This commit is contained in:
+2
-2
@@ -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
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user