forked from rashadphz/farfalle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(issue-89): workaround for unmarshalling-strings issue rashadphz#89
- Loading branch information
1 parent
883003f
commit 759fd20
Showing
2 changed files
with
18 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
from backend.llm.base import BaseLLM | ||
from backend.prompts import RELATED_QUESTION_PROMPT | ||
from backend.schemas import RelatedQueries, SearchResult | ||
|
||
import ast | ||
|
||
async def generate_related_queries( | ||
query: str, search_results: list[SearchResult], llm: BaseLLM | ||
) -> list[str]: | ||
context = "\n\n".join([f"{str(result)}" for result in search_results]) | ||
context = context[:4000] | ||
|
||
related = llm.structured_complete( | ||
RelatedQueries, RELATED_QUESTION_PROMPT.format(query=query, context=context) | ||
) | ||
|
||
return [query.lower().replace("?", "") for query in related.related_questions] | ||
# Hotfix Part II (https://github.com/rashadphz/farfalle/issues/82) | ||
if len(related.related_questions) == 1: | ||
related.related_questions = ast.literal_eval(related.related_questions[0]) | ||
|
||
return [query.lower().replace("?", "").replace("}", "") for query in related.related_questions] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters