|
|
|
@ -1,8 +1,11 @@
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
|
|
import openai
|
|
|
|
|
from langchain import OpenAI, VectorDBQA
|
|
|
|
|
from py_executable_checklist.workflow import WorkflowBase
|
|
|
|
|
|
|
|
|
|
from doc_search import retry
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AskQuestion(WorkflowBase):
|
|
|
|
|
"""
|
|
|
|
@ -17,7 +20,7 @@ class AskQuestion(WorkflowBase):
|
|
|
|
|
return f"""
|
|
|
|
|
Instructions:
|
|
|
|
|
- Answer and guide the human when they ask for it.
|
|
|
|
|
- Provide comprehensive responses that relate to the humans prompt.
|
|
|
|
|
- Provide detailed responses that relate to the humans prompt.
|
|
|
|
|
|
|
|
|
|
Summarize text.
|
|
|
|
|
{selected_blocks}
|
|
|
|
@ -30,5 +33,9 @@ AI:"""
|
|
|
|
|
def execute(self) -> dict:
|
|
|
|
|
prompt = self.prompt_from_question(self.input_question, self.selected_blocks)
|
|
|
|
|
qa = VectorDBQA.from_llm(llm=OpenAI(), vectorstore=self.search_index)
|
|
|
|
|
output = qa.run(prompt)
|
|
|
|
|
output = self.send_prompt(prompt, qa)
|
|
|
|
|
return {"output": output}
|
|
|
|
|
|
|
|
|
|
@retry(exceptions=openai.error.RateLimitError, tries=2, delay=60, back_off=2)
|
|
|
|
|
def send_prompt(self, prompt: str, qa: VectorDBQA) -> Any:
|
|
|
|
|
return qa.run(prompt)
|
|
|
|
|