feat: 03_07
Browse files- README.md +4 -6
- app/app.py +0 -11
- app/prompt.py +7 -30
README.md
CHANGED
@@ -2,16 +2,14 @@
|
|
2 |
This is the repository for the LinkedIn Learning course `Hands-On AI: Building and Deploying LLM-Powered Apps`. The full course is available from [LinkedIn Learning][lil-course-url].
|
3 |
|
4 |
_See the readme file in the main branch for updated instructions and information._
|
5 |
-
## Lab6:
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
Before we can do that, we need to extract the prompt template out of the code.
|
11 |
|
12 |
## Exercises
|
13 |
|
14 |
-
Please
|
15 |
|
16 |
## References
|
17 |
|
|
|
2 |
This is the repository for the LinkedIn Learning course `Hands-On AI: Building and Deploying LLM-Powered Apps`. The full course is available from [LinkedIn Learning][lil-course-url].
|
3 |
|
4 |
_See the readme file in the main branch for updated instructions and information._
|
5 |
+
## Lab6: Prompt Engineering
|
6 |
+
With the prompt templates extracted from the code, we can iterate on the prompts to fix the problem that we have observed!
|
7 |
|
8 |
+
Please iterate on the prompts and ensure the model can respond properly to our sample question.
|
|
|
|
|
9 |
|
10 |
## Exercises
|
11 |
|
12 |
+
Please find a prompt in our Chainlit application's playground that ensures our sample question is answered properly. And then edit `prompt.py` with the newly discovered/engineered prompt.
|
13 |
|
14 |
## References
|
15 |
|
app/app.py
CHANGED
@@ -9,7 +9,6 @@ from typing import List
|
|
9 |
|
10 |
import chainlit as cl
|
11 |
from chainlit.types import AskFileResponse
|
12 |
-
|
13 |
import chromadb
|
14 |
from chromadb.config import Settings
|
15 |
from langchain.chains import LLMChain, RetrievalQAWithSourcesChain
|
@@ -22,11 +21,6 @@ from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
22 |
from langchain.vectorstores import Chroma
|
23 |
from langchain.vectorstores.base import VectorStore
|
24 |
|
25 |
-
|
26 |
-
##############################################################################
|
27 |
-
# Exercise 2:
|
28 |
-
# Please import the copied prompt scaffolds from prompt.py
|
29 |
-
##############################################################################
|
30 |
from prompt import EXAMPLE_PROMPT, PROMPT
|
31 |
|
32 |
|
@@ -156,11 +150,6 @@ async def on_chat_start():
|
|
156 |
streaming=True
|
157 |
)
|
158 |
|
159 |
-
##########################################################################
|
160 |
-
# Exercise 3:
|
161 |
-
# Please modify this chain's initiation with the proper kwargs to take in
|
162 |
-
# custom prompts.
|
163 |
-
##########################################################################
|
164 |
chain = RetrievalQAWithSourcesChain.from_chain_type(
|
165 |
llm=model,
|
166 |
chain_type="stuff",
|
|
|
9 |
|
10 |
import chainlit as cl
|
11 |
from chainlit.types import AskFileResponse
|
|
|
12 |
import chromadb
|
13 |
from chromadb.config import Settings
|
14 |
from langchain.chains import LLMChain, RetrievalQAWithSourcesChain
|
|
|
21 |
from langchain.vectorstores import Chroma
|
22 |
from langchain.vectorstores.base import VectorStore
|
23 |
|
|
|
|
|
|
|
|
|
|
|
24 |
from prompt import EXAMPLE_PROMPT, PROMPT
|
25 |
|
26 |
|
|
|
150 |
streaming=True
|
151 |
)
|
152 |
|
|
|
|
|
|
|
|
|
|
|
153 |
chain = RetrievalQAWithSourcesChain.from_chain_type(
|
154 |
llm=model,
|
155 |
chain_type="stuff",
|
app/prompt.py
CHANGED
@@ -1,45 +1,22 @@
|
|
1 |
##############################################################################
|
2 |
# Exercise 1:
|
3 |
-
# Please
|
4 |
-
#
|
|
|
5 |
##############################################################################
|
6 |
from langchain.prompts import PromptTemplate
|
7 |
|
8 |
-
template = """Given the following extracted parts of a long document and a question, create a final answer with references ("SOURCES").
|
9 |
-
If you don't know the answer, just say that you don't know. Don't try to make up an answer.
|
10 |
-
ALWAYS return a "SOURCES" part in your answer.
|
11 |
-
|
12 |
-
QUESTION: Which state/country's law governs the interpretation of the contract?
|
13 |
-
=========
|
14 |
-
Content: This Agreement is governed by English law and the parties submit to the exclusive jurisdiction of the English courts in relation to any dispute (contractual or non-contractual) concerning this Agreement save that either party may apply to any court for an injunction or other relief to protect its Intellectual Property Rights.
|
15 |
-
Source: 28-pl
|
16 |
-
Content: No Waiver. Failure or delay in exercising any right or remedy under this Agreement shall not constitute a waiver of such (or any other) right or remedy.\n\n11.7 Severability. The invalidity, illegality or unenforceability of any term (or part of a term) of this Agreement shall not affect the continuation in force of the remainder of the term (if any) and this Agreement.\n\n11.8 No Agency. Except as expressly stated otherwise, nothing in this Agreement shall create an agency, partnership or joint venture of any kind between the parties.\n\n11.9 No Third-Party Beneficiaries.
|
17 |
-
Source: 30-pl
|
18 |
-
Content: (b) if Google believes, in good faith, that the Distributor has violated or caused Google to violate any Anti-Bribery Laws (as defined in Clause 8.5) or that such a violation is reasonably likely to occur,
|
19 |
-
Source: 4-pl
|
20 |
-
=========
|
21 |
-
FINAL ANSWER: This Agreement is governed by English law.
|
22 |
-
SOURCES: 28-pl
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
Source: 0-pl
|
28 |
-
Content: And we won’t stop. \n\nWe have lost so much to COVID-19. Time with one another. And worst of all, so much loss of life. \n\nLet’s use this moment to reset. Let’s stop looking at COVID-19 as a partisan dividing line and see it for what it is: A God-awful disease. \n\nLet’s stop seeing each other as enemies, and start seeing each other for who we really are: Fellow Americans. \n\nWe can’t change how divided we’ve been. But we can change how we move forward—on COVID-19 and other issues we must face together. \n\nI recently visited the New York City Police Department days after the funerals of Officer Wilbert Mora and his partner, Officer Jason Rivera. \n\nThey were responding to a 9-1-1 call when a man shot and killed them with a stolen gun. \n\nOfficer Mora was 27 years old. \n\nOfficer Rivera was 22. \n\nBoth Dominican Americans who’d grown up on the same streets they later chose to patrol as police officers. \n\nI spoke with their families and told them that we are forever in debt for their sacrifice, and we will carry on their mission to restore the trust and safety every community deserves.
|
29 |
-
Source: 24-pl
|
30 |
-
Content: And a proud Ukrainian people, who have known 30 years of independence, have repeatedly shown that they will not tolerate anyone who tries to take their country backwards. \n\nTo all Americans, I will be honest with you, as I’ve always promised. A Russian dictator, invading a foreign country, has costs around the world. \n\nAnd I’m taking robust action to make sure the pain of our sanctions is targeted at Russia’s economy. And I will use every tool at our disposal to protect American businesses and consumers. \n\nTonight, I can announce that the United States has worked with 30 other countries to release 60 Million barrels of oil from reserves around the world. \n\nAmerica will lead that effort, releasing 30 Million barrels from our own Strategic Petroleum Reserve. And we stand ready to do more if necessary, unified with our allies. \n\nThese steps will help blunt gas prices here at home. And I know the news about what’s happening can seem alarming. \n\nBut I want you to know that we are going to be okay.
|
31 |
-
Source: 5-pl
|
32 |
-
Content: More support for patients and families. \n\nTo get there, I call on Congress to fund ARPA-H, the Advanced Research Projects Agency for Health. \n\nIt’s based on DARPA—the Defense Department project that led to the Internet, GPS, and so much more. \n\nARPA-H will have a singular purpose—to drive breakthroughs in cancer, Alzheimer’s, diabetes, and more. \n\nA unity agenda for the nation. \n\nWe can do this. \n\nMy fellow Americans—tonight , we have gathered in a sacred space—the citadel of our democracy. \n\nIn this Capitol, generation after generation, Americans have debated great questions amid great strife, and have done great things. \n\nWe have fought for freedom, expanded liberty, defeated totalitarianism and terror. \n\nAnd built the strongest, freest, and most prosperous nation the world has ever known. \n\nNow is the hour. \n\nOur moment of responsibility. \n\nOur test of resolve and conscience, of history itself. \n\nIt is in this moment that our character is formed. Our purpose is found. Our future is forged. \n\nWell I know this nation.
|
33 |
-
Source: 34-pl
|
34 |
-
=========
|
35 |
-
FINAL ANSWER: The president did not mention Michael Jackson.
|
36 |
-
SOURCES:
|
37 |
|
38 |
QUESTION: {question}
|
39 |
=========
|
40 |
{summaries}
|
41 |
=========
|
42 |
FINAL ANSWER:"""
|
|
|
43 |
PROMPT = PromptTemplate(template=template, input_variables=["summaries", "question"])
|
44 |
|
45 |
EXAMPLE_PROMPT = PromptTemplate(
|
|
|
1 |
##############################################################################
|
2 |
# Exercise 1:
|
3 |
+
# Please utilize Chainlit's app playground for prompt engineering and
|
4 |
+
# experimentation. Once done, modify the prompts template below with your
|
5 |
+
# newly developed prompts.
|
6 |
##############################################################################
|
7 |
from langchain.prompts import PromptTemplate
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
template = """Given the following extracted parts of a long document and a question, create a final answer with references ("SOURCES").
|
11 |
+
If you don't know the answer, just say that you don't know. Don't try to make up an answer.
|
12 |
+
ALWAYS return a "SOURCES" field in your answer, with the format "SOURCES: <source1>, <source2>, <source3>, ...".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
QUESTION: {question}
|
15 |
=========
|
16 |
{summaries}
|
17 |
=========
|
18 |
FINAL ANSWER:"""
|
19 |
+
|
20 |
PROMPT = PromptTemplate(template=template, input_variables=["summaries", "question"])
|
21 |
|
22 |
EXAMPLE_PROMPT = PromptTemplate(
|