Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files
freeCodeCamp-Langchain/.env
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
OPENAI_API_KEY="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"
|
2 |
+
huggingface=""
|
freeCodeCamp-Langchain/app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Q&A Chatbot
|
2 |
+
from langchain.llms import OpenAI
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
import streamlit as st
|
5 |
+
import os
|
6 |
+
|
7 |
+
load_dotenv() # take environment variables form .env
|
8 |
+
|
9 |
+
|
10 |
+
# Function to load OpenaI Model and get response
|
11 |
+
def get_openai_response(question):
|
12 |
+
llm=OpenAI(openai_api_key=os.getenv("OPEN_API_KEY"),model_name="gpt-3.5-turbo-instruct",temperature=0.5)
|
13 |
+
reponse=llm(question)
|
14 |
+
return reponse
|
15 |
+
|
16 |
+
### Initialize our streamlit app
|
17 |
+
|
18 |
+
st.set_page_config(page_title="Q&A Demo")
|
19 |
+
|
20 |
+
st.header("Langchain Application")
|
21 |
+
|
22 |
+
input=st.text_input("Input: ",key=input)
|
23 |
+
reponse=get_openai_response(input)
|
24 |
+
|
25 |
+
|
26 |
+
submit=st.button("As the question")
|
27 |
+
|
28 |
+
## IF ask button is clicked
|
29 |
+
|
30 |
+
if submit:
|
31 |
+
st.subheader("The Reponse is")
|
32 |
+
st.write(reponse)
|
freeCodeCamp-Langchain/langchain.ipynb
ADDED
@@ -0,0 +1,410 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 56,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"from langchain.llms import OpenAI\n"
|
10 |
+
]
|
11 |
+
},
|
12 |
+
{
|
13 |
+
"cell_type": "code",
|
14 |
+
"execution_count": 57,
|
15 |
+
"metadata": {},
|
16 |
+
"outputs": [],
|
17 |
+
"source": [
|
18 |
+
"import os\n",
|
19 |
+
"os.environ[\"OPEN_API_KEY\"]=\"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\""
|
20 |
+
]
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"cell_type": "code",
|
24 |
+
"execution_count": 58,
|
25 |
+
"metadata": {},
|
26 |
+
"outputs": [],
|
27 |
+
"source": [
|
28 |
+
"llm=OpenAI(openai_api_key=os.environ[\"OPEN_API_KEY\"],temperature=.5)"
|
29 |
+
]
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"cell_type": "code",
|
33 |
+
"execution_count": null,
|
34 |
+
"metadata": {},
|
35 |
+
"outputs": [],
|
36 |
+
"source": []
|
37 |
+
},
|
38 |
+
{
|
39 |
+
"cell_type": "code",
|
40 |
+
"execution_count": 59,
|
41 |
+
"metadata": {},
|
42 |
+
"outputs": [
|
43 |
+
{
|
44 |
+
"name": "stdout",
|
45 |
+
"output_type": "stream",
|
46 |
+
"text": [
|
47 |
+
"\n",
|
48 |
+
"\n",
|
49 |
+
"The capital of India is New Delhi.\n"
|
50 |
+
]
|
51 |
+
}
|
52 |
+
],
|
53 |
+
"source": [
|
54 |
+
"text=\"What is the capital of India?\"\n",
|
55 |
+
"print(llm.predict(text))"
|
56 |
+
]
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"cell_type": "code",
|
60 |
+
"execution_count": 60,
|
61 |
+
"metadata": {},
|
62 |
+
"outputs": [],
|
63 |
+
"source": [
|
64 |
+
"os.environ[\"HUGGINGFACEHUB_API_TOKEN\"]=\"\""
|
65 |
+
]
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"cell_type": "code",
|
69 |
+
"execution_count": 61,
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [],
|
72 |
+
"source": [
|
73 |
+
"from langchain import HuggingFaceHub\n",
|
74 |
+
"llm_huggingface=HuggingFaceHub(repo_id=\"google/flan-t5-large\",model_kwargs={\"temperature\":0,\"max_length\":64})"
|
75 |
+
]
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"cell_type": "code",
|
79 |
+
"execution_count": 62,
|
80 |
+
"metadata": {},
|
81 |
+
"outputs": [
|
82 |
+
{
|
83 |
+
"name": "stdout",
|
84 |
+
"output_type": "stream",
|
85 |
+
"text": [
|
86 |
+
"moscow\n"
|
87 |
+
]
|
88 |
+
}
|
89 |
+
],
|
90 |
+
"source": [
|
91 |
+
"output=llm_huggingface.predict(\"Can you tell me the capital of Russia?\")\n",
|
92 |
+
"print(output)"
|
93 |
+
]
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"cell_type": "code",
|
97 |
+
"execution_count": 63,
|
98 |
+
"metadata": {},
|
99 |
+
"outputs": [],
|
100 |
+
"source": [
|
101 |
+
"### Prompt Templates And LLM Chain\n"
|
102 |
+
]
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"cell_type": "code",
|
106 |
+
"execution_count": 64,
|
107 |
+
"metadata": {},
|
108 |
+
"outputs": [
|
109 |
+
{
|
110 |
+
"data": {
|
111 |
+
"text/plain": [
|
112 |
+
"'Tell me the capital of this India'"
|
113 |
+
]
|
114 |
+
},
|
115 |
+
"execution_count": 64,
|
116 |
+
"metadata": {},
|
117 |
+
"output_type": "execute_result"
|
118 |
+
}
|
119 |
+
],
|
120 |
+
"source": [
|
121 |
+
"from langchain.prompts import PromptTemplate\n",
|
122 |
+
"\n",
|
123 |
+
"prompt_template=PromptTemplate(input_variables=['country'],\n",
|
124 |
+
" template=\"Tell me the capital of this {country}\")\n",
|
125 |
+
"\n",
|
126 |
+
"prompt_template.format(country=\"India\")"
|
127 |
+
]
|
128 |
+
},
|
129 |
+
{
|
130 |
+
"cell_type": "code",
|
131 |
+
"execution_count": 65,
|
132 |
+
"metadata": {},
|
133 |
+
"outputs": [
|
134 |
+
{
|
135 |
+
"name": "stdout",
|
136 |
+
"output_type": "stream",
|
137 |
+
"text": [
|
138 |
+
"\n",
|
139 |
+
"\n",
|
140 |
+
"The capital of India is New Delhi.\n"
|
141 |
+
]
|
142 |
+
}
|
143 |
+
],
|
144 |
+
"source": [
|
145 |
+
"from langchain.chains import LLMChain\n",
|
146 |
+
"chain=LLMChain(llm=llm,prompt=prompt_template)\n",
|
147 |
+
"print(chain.run(\"India\"))"
|
148 |
+
]
|
149 |
+
},
|
150 |
+
{
|
151 |
+
"cell_type": "code",
|
152 |
+
"execution_count": 66,
|
153 |
+
"metadata": {},
|
154 |
+
"outputs": [],
|
155 |
+
"source": [
|
156 |
+
"### Combining Multiple Chains Using Simple Sequential Chains"
|
157 |
+
]
|
158 |
+
},
|
159 |
+
{
|
160 |
+
"cell_type": "code",
|
161 |
+
"execution_count": 67,
|
162 |
+
"metadata": {},
|
163 |
+
"outputs": [],
|
164 |
+
"source": [
|
165 |
+
"capital_prompt=PromptTemplate(input_variables=['country'],\n",
|
166 |
+
" template=\"Please tellme the capital of the {country}\")\n",
|
167 |
+
"\n",
|
168 |
+
"capital_chain=LLMChain(llm=llm,prompt=capital_prompt)\n",
|
169 |
+
"\n",
|
170 |
+
"famous_template=PromptTemplate(input_variables=['capital'],\n",
|
171 |
+
" template=\"Suggest to me some amazing places to visit in {capital}\")\n",
|
172 |
+
"\n",
|
173 |
+
"famous_chain=LLMChain(llm=llm,prompt=famous_template)\n",
|
174 |
+
"\n",
|
175 |
+
"\n"
|
176 |
+
]
|
177 |
+
},
|
178 |
+
{
|
179 |
+
"cell_type": "code",
|
180 |
+
"execution_count": 68,
|
181 |
+
"metadata": {},
|
182 |
+
"outputs": [
|
183 |
+
{
|
184 |
+
"name": "stdout",
|
185 |
+
"output_type": "stream",
|
186 |
+
"text": [
|
187 |
+
" Some amazing places to visit in Washington, D.C. include:\n",
|
188 |
+
"\n",
|
189 |
+
"1. The National Mall - This iconic stretch of green space is home to some of the most famous monuments and memorials, including the Lincoln Memorial, Washington Monument, and Vietnam Veterans Memorial.\n",
|
190 |
+
"\n",
|
191 |
+
"2. Smithsonian Museums - The Smithsonian Institution is made up of 19 museums and galleries, all of which are free to visit. Some must-see museums include the National Air and Space Museum, National Museum of Natural History, and National Museum of African American History and Culture.\n",
|
192 |
+
"\n",
|
193 |
+
"3. The White House - Take a tour of the official residence and workplace of the President of the United States. You can also visit the White House Visitor Center to learn more about its history and significance.\n",
|
194 |
+
"\n",
|
195 |
+
"4. Georgetown - This historic neighborhood is a charming mix of cobblestone streets, upscale shops and restaurants, and beautiful architecture. It's also home to Georgetown University and the famous Exorcist stairs.\n",
|
196 |
+
"\n",
|
197 |
+
"5. Arlington National Cemetery - Pay your respects to fallen soldiers at this somber and beautiful cemetery, which is also the final resting place of President John F. Kennedy and his family.\n",
|
198 |
+
"\n",
|
199 |
+
"6. National Zoo - Part of the Smithsonian Institution, the National Zoo is home to over 2,000 animals, including giant pandas, lions,\n"
|
200 |
+
]
|
201 |
+
}
|
202 |
+
],
|
203 |
+
"source": [
|
204 |
+
"from langchain.chains import SimpleSequentialChain\n",
|
205 |
+
"chain=SimpleSequentialChain(chains=[capital_chain,famous_chain])\n",
|
206 |
+
"print(chain.run(\"United States\"))"
|
207 |
+
]
|
208 |
+
},
|
209 |
+
{
|
210 |
+
"cell_type": "code",
|
211 |
+
"execution_count": 69,
|
212 |
+
"metadata": {},
|
213 |
+
"outputs": [],
|
214 |
+
"source": [
|
215 |
+
"### Sequential Chain"
|
216 |
+
]
|
217 |
+
},
|
218 |
+
{
|
219 |
+
"cell_type": "code",
|
220 |
+
"execution_count": 70,
|
221 |
+
"metadata": {},
|
222 |
+
"outputs": [],
|
223 |
+
"source": [
|
224 |
+
"capital_prompt=PromptTemplate(input_variables=['country'],\n",
|
225 |
+
" template=\"Please tellme the capital of the {country}\")\n",
|
226 |
+
"\n",
|
227 |
+
"capital_chain=LLMChain(llm=llm,prompt=capital_prompt,output_key=\"capital\")\n",
|
228 |
+
"\n",
|
229 |
+
"famous_template=PromptTemplate(input_variables=['capital'],\n",
|
230 |
+
" template=\"Suggest to me some amazing places to visit in {capital}\")\n",
|
231 |
+
"\n",
|
232 |
+
"famous_chain=LLMChain(llm=llm,prompt=famous_template,output_key=\"places\")"
|
233 |
+
]
|
234 |
+
},
|
235 |
+
{
|
236 |
+
"cell_type": "code",
|
237 |
+
"execution_count": 71,
|
238 |
+
"metadata": {},
|
239 |
+
"outputs": [],
|
240 |
+
"source": [
|
241 |
+
"from langchain.chains import SequentialChain\n",
|
242 |
+
"chain=SequentialChain(chains=[capital_chain,famous_chain],\n",
|
243 |
+
"input_variables=['country'],\n",
|
244 |
+
"output_variables=['capital',\"places\"])"
|
245 |
+
]
|
246 |
+
},
|
247 |
+
{
|
248 |
+
"cell_type": "code",
|
249 |
+
"execution_count": 72,
|
250 |
+
"metadata": {},
|
251 |
+
"outputs": [
|
252 |
+
{
|
253 |
+
"data": {
|
254 |
+
"text/plain": [
|
255 |
+
"{'country': 'India',\n",
|
256 |
+
" 'capital': '\\n\\nThe capital of India is New Delhi.',\n",
|
257 |
+
" 'places': \" It is a bustling metropolis with a rich history and culture. Some amazing places to visit in Delhi are:\\n\\n1. Red Fort: This iconic monument was built in the 17th century and served as the residence of the Mughal emperors. It is a UNESCO World Heritage Site and a must-visit for its stunning architecture and historical significance.\\n\\n2. India Gate: This war memorial is a popular spot for locals and tourists alike. It was built to honor the soldiers who lost their lives in World War I and the Third Anglo-Afghan War. The lush green lawns and the surrounding area make it a perfect spot for a picnic or a leisurely stroll.\\n\\n3. Qutub Minar: Another UNESCO World Heritage Site, the Qutub Minar is the tallest minaret in India. It was built in the 12th century and is a fine example of Indo-Islamic architecture. The complex also houses other historical structures and a lush garden.\\n\\n4. Lotus Temple: This beautiful temple is a symbol of unity and peace. Its unique lotus-shaped architecture and serene atmosphere make it a popular spot for meditation and reflection.\\n\\n5. Humayun's Tomb: This stunning mausoleum was built in the 16th century and is\"}"
|
258 |
+
]
|
259 |
+
},
|
260 |
+
"execution_count": 72,
|
261 |
+
"metadata": {},
|
262 |
+
"output_type": "execute_result"
|
263 |
+
}
|
264 |
+
],
|
265 |
+
"source": [
|
266 |
+
"chain({'country':\"India\"})"
|
267 |
+
]
|
268 |
+
},
|
269 |
+
{
|
270 |
+
"cell_type": "code",
|
271 |
+
"execution_count": 73,
|
272 |
+
"metadata": {},
|
273 |
+
"outputs": [],
|
274 |
+
"source": [
|
275 |
+
"### Chatmodels WIth ChatOpenAI"
|
276 |
+
]
|
277 |
+
},
|
278 |
+
{
|
279 |
+
"cell_type": "code",
|
280 |
+
"execution_count": 74,
|
281 |
+
"metadata": {},
|
282 |
+
"outputs": [],
|
283 |
+
"source": [
|
284 |
+
"from langchain.chat_models import ChatOpenAI\n",
|
285 |
+
"from langchain.schema import HumanMessage,SystemMessage,AIMessage"
|
286 |
+
]
|
287 |
+
},
|
288 |
+
{
|
289 |
+
"cell_type": "code",
|
290 |
+
"execution_count": 75,
|
291 |
+
"metadata": {},
|
292 |
+
"outputs": [
|
293 |
+
{
|
294 |
+
"name": "stdout",
|
295 |
+
"output_type": "stream",
|
296 |
+
"text": [
|
297 |
+
"content=\"In California, regulatory reporting related to ESG (Environmental, Social, Governance) factors can vary depending on the industry and the specific regulations in place. However, there are some key reporting requirements that companies may need to adhere to:\\n\\n1. **California Transparency in Supply Chains Act (CTSCA)**: This law requires certain companies to disclose their efforts to eradicate slavery and human trafficking from their direct supply chains. Covered companies must disclose their efforts to verify and audit their supply chains, as well as their training programs for employees and management on human trafficking and slavery.\\n\\n2. **California Greenhouse Gas (GHG) Reporting Program**: California has its own GHG reporting program that requires facilities that emit over a certain threshold of greenhouse gases to report their emissions annually. This program is part of the state's efforts to reduce GHG emissions and combat climate change.\\n\\n3. **California Environmental Reporting System (CERS)**: Certain businesses in California are required to report their hazardous materials inventory and business activities that generate hazardous waste to the CERS database. This reporting helps regulators and emergency responders track and manage hazardous materials in the state.\\n\\n4. **California Sustainable Groundwater Management Act (SGMA)**: Under SGMA, local agencies in California are required to develop and implement sustainable groundwater management plans to ensure the long-term viability of groundwater resources. Reporting requirements may include monitoring groundwater levels, water quality, and implementation of sustainable management practices.\\n\\n5. **California Corporate Disclosure Act**: This proposed legislation would require publicly traded companies headquartered in California to disclose information related to their ESG practices, including greenhouse gas emissions, workforce diversity, and board diversity. While this bill has not been enacted as of my last update, it indicates a growing trend towards increased ESG reporting requirements in the state.\\n\\nIt's important for companies operating in California to stay informed about the latest regulatory requirements related to ESG reporting to ensure compliance and transparency in their operations.\" response_metadata={'token_usage': {'completion_tokens': 383, 'prompt_tokens': 34, 'total_tokens': 417}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None} id='run-1644211e-9ced-421a-9a12-46c6c1005ef7-0'\n"
|
298 |
+
]
|
299 |
+
}
|
300 |
+
],
|
301 |
+
"source": [
|
302 |
+
"from langchain.chat_models import ChatOpenAI\n",
|
303 |
+
"from langchain.schema import HumanMessage,SystemMessage,AIMessage\n",
|
304 |
+
"\n",
|
305 |
+
"chatllm=ChatOpenAI(openai_api_key=os.environ[\"OPEN_API_KEY\"],temperature=.5,model='gpt-3.5-turbo')\n",
|
306 |
+
"\n",
|
307 |
+
"print(chatllm([\n",
|
308 |
+
" SystemMessage(content=\"You are an expert in ESG (Environmental, Social, Governance) factual knowledge\"), \n",
|
309 |
+
" HumanMessage(content=\"Please explain the regulatory reporting in California\") \n",
|
310 |
+
"]))"
|
311 |
+
]
|
312 |
+
},
|
313 |
+
{
|
314 |
+
"cell_type": "code",
|
315 |
+
"execution_count": 76,
|
316 |
+
"metadata": {},
|
317 |
+
"outputs": [],
|
318 |
+
"source": [
|
319 |
+
"### Prompt Template + LLM + Output Parsers"
|
320 |
+
]
|
321 |
+
},
|
322 |
+
{
|
323 |
+
"cell_type": "code",
|
324 |
+
"execution_count": 77,
|
325 |
+
"metadata": {},
|
326 |
+
"outputs": [],
|
327 |
+
"source": [
|
328 |
+
"from langchain.chat_models import ChatOpenAI\n",
|
329 |
+
"from langchain.prompts.chat import ChatPromptTemplate\n",
|
330 |
+
"from langchain.schema import BaseOutputParser"
|
331 |
+
]
|
332 |
+
},
|
333 |
+
{
|
334 |
+
"cell_type": "code",
|
335 |
+
"execution_count": 81,
|
336 |
+
"metadata": {},
|
337 |
+
"outputs": [],
|
338 |
+
"source": [
|
339 |
+
"class CommaSeperatedOutput(BaseOutputParser):\n",
|
340 |
+
" def parse(self,text:str):\n",
|
341 |
+
" return text.strip().split(\",\")\n",
|
342 |
+
"\n"
|
343 |
+
]
|
344 |
+
},
|
345 |
+
{
|
346 |
+
"cell_type": "code",
|
347 |
+
"execution_count": 82,
|
348 |
+
"metadata": {},
|
349 |
+
"outputs": [],
|
350 |
+
"source": [
|
351 |
+
"template=\"You are a helpful assistant. When the user given any input, you should generate five synomonous words in a comma seperated list\"\n",
|
352 |
+
"human_template=\"{text}\"\n",
|
353 |
+
"chatprompt=ChatPromptTemplate.from_messages([\n",
|
354 |
+
" (\"system\",template),\n",
|
355 |
+
" (\"human\",human_template)\n",
|
356 |
+
"])"
|
357 |
+
]
|
358 |
+
},
|
359 |
+
{
|
360 |
+
"cell_type": "code",
|
361 |
+
"execution_count": 83,
|
362 |
+
"metadata": {},
|
363 |
+
"outputs": [],
|
364 |
+
"source": [
|
365 |
+
"chain=chatprompt|chatllm|CommaSeperatedOutput()"
|
366 |
+
]
|
367 |
+
},
|
368 |
+
{
|
369 |
+
"cell_type": "code",
|
370 |
+
"execution_count": 84,
|
371 |
+
"metadata": {},
|
372 |
+
"outputs": [
|
373 |
+
{
|
374 |
+
"data": {
|
375 |
+
"text/plain": [
|
376 |
+
"['smart', ' clever', ' bright', ' astute', ' sharp']"
|
377 |
+
]
|
378 |
+
},
|
379 |
+
"execution_count": 84,
|
380 |
+
"metadata": {},
|
381 |
+
"output_type": "execute_result"
|
382 |
+
}
|
383 |
+
],
|
384 |
+
"source": [
|
385 |
+
"chain.invoke({\"text\":\"intelligent\"})"
|
386 |
+
]
|
387 |
+
}
|
388 |
+
],
|
389 |
+
"metadata": {
|
390 |
+
"kernelspec": {
|
391 |
+
"display_name": "Python 3",
|
392 |
+
"language": "python",
|
393 |
+
"name": "python3"
|
394 |
+
},
|
395 |
+
"language_info": {
|
396 |
+
"codemirror_mode": {
|
397 |
+
"name": "ipython",
|
398 |
+
"version": 3
|
399 |
+
},
|
400 |
+
"file_extension": ".py",
|
401 |
+
"mimetype": "text/x-python",
|
402 |
+
"name": "python",
|
403 |
+
"nbconvert_exporter": "python",
|
404 |
+
"pygments_lexer": "ipython3",
|
405 |
+
"version": "3.12.4"
|
406 |
+
}
|
407 |
+
},
|
408 |
+
"nbformat": 4,
|
409 |
+
"nbformat_minor": 2
|
410 |
+
}
|
freeCodeCamp-Langchain/requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain
|
2 |
+
openai
|
3 |
+
huggingface_hub
|
4 |
+
python-dotenv
|
5 |
+
streamlit
|