LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
[FIX] Removing preamble from embedding retrieval prompt (#539)
harini-venkataramaneb64aabb8a87
diff --git a/prompt-service/src/unstract/prompt_service/main.py b/prompt-service/src/unstract/prompt_service/main.pyindex 6a06b90e1..f9a05506a 100644--- a/prompt-service/src/unstract/prompt_service/main.py+++ b/prompt-service/src/unstract/prompt_service/main.py@@ -129,31 +129,6 @@ def construct_prompt(return prompt-def construct_prompt_for_engine(- preamble: str,- prompt: str,- postamble: str,- grammar_list: list[dict[str, Any]],-) -> str:- # Let's cleanup the context. Remove if 3 consecutive newlines are found- prompt = f"{preamble}\n\nQuestion or Instruction: {prompt}\n"- if grammar_list is not None and len(grammar_list) > 0:- prompt += "\n"- for grammar in grammar_list:- word = ""- synonyms = []- if PSKeys.WORD in grammar:- word = grammar[PSKeys.WORD]- if PSKeys.SYNONYMS in grammar:- synonyms = grammar[PSKeys.SYNONYMS]- if len(synonyms) > 0 and word != "":- prompt += f'\nNote: You can consider that the word {word} is same as \- {", ".join(synonyms)} in both the quesiton and the context.' # noqa- prompt += f"\n\n{postamble}"- prompt += "\n\n"- return prompt--def authentication_middleware(func: Any) -> Any:def wrapper(*args: Any, **kwargs: Any) -> Any:token = AuthenticationMiddleware.get_token_from_auth_header(request)@@ -703,13 +678,8 @@ def run_retrieval( # type:ignorevector_index,retrieval_type: str,) -> tuple[str, str]:- prompt = construct_prompt_for_engine(- preamble=tool_settings.get(PSKeys.PREAMBLE, ""),- prompt=output[PSKeys.PROMPTX],- postamble=tool_settings.get(PSKeys.POSTAMBLE, ""),- grammar_list=tool_settings.get(PSKeys.GRAMMAR, []),- )- if retrieval_type is PSKeys.SUBQUESTION:+ prompt = output[PSKeys.PROMPTX]+ if retrieval_type == PSKeys.SUBQUESTION:subq_prompt = (f"Generate a sub-question from the following verbose prompt that will"f" help extract relevant documents from a vector store:\n\n{prompt}"