()
| 32 | |
| 33 | |
| 34 | def build_application(): |
| 35 | embed_text = HaystackAction( |
| 36 | component=OpenAITextEmbedder(model="text-embedding-3-small"), |
| 37 | name="embed_text", |
| 38 | reads=[], |
| 39 | writes={"query_embedding": "embedding"}, |
| 40 | ) |
| 41 | |
| 42 | retrieve_documents = HaystackAction( |
| 43 | component=InMemoryEmbeddingRetriever(InMemoryDocumentStore()), |
| 44 | name="retrieve_documents", |
| 45 | reads=["query_embedding"], |
| 46 | writes=["documents"], |
| 47 | ) |
| 48 | |
| 49 | build_prompt = HaystackAction( |
| 50 | component=PromptBuilder(template="Document: {{documents}} Question: {{question}}"), |
| 51 | name="build_prompt", |
| 52 | reads=["documents"], |
| 53 | writes={"question_prompt": "prompt"}, |
| 54 | ) |
| 55 | |
| 56 | generate_answer = HaystackAction( |
| 57 | component=OpenAIGenerator(model="gpt-4o-mini"), |
| 58 | name="generate_answer", |
| 59 | reads={"prompt": "question_prompt"}, |
| 60 | writes={"answer": "replies"}, |
| 61 | ) |
| 62 | |
| 63 | return ( |
| 64 | ApplicationBuilder() |
| 65 | .with_actions( |
| 66 | embed_text, |
| 67 | retrieve_documents, |
| 68 | build_prompt, |
| 69 | generate_answer, |
| 70 | display_answer, |
| 71 | ) |
| 72 | .with_transitions( |
| 73 | ("embed_text", "retrieve_documents"), |
| 74 | ("retrieve_documents", "build_prompt"), |
| 75 | ("build_prompt", "generate_answer"), |
| 76 | ("generate_answer", "display_answer"), |
| 77 | ) |
| 78 | .with_entrypoint("embed_text") |
| 79 | .build() |
| 80 | ) |
| 81 | |
| 82 | |
| 83 | if __name__ == "__main__": |
no test coverage detected