Build Chat AI apps w/ Streamlit + LangChain
Вставка
- Опубліковано 13 лип 2023
- Langchain's Agent is the powerhouse to LLM (large language models), as it "delegates" to specialized tools ("experts") like calculator, web browser, translators etc among a wide suite of tools, determining at each step the best specialized tool, or combination of tools, to use. All powered by #langchain tools and action agents.
Action agents: at each timestep, decide on the next action using the outputs of all previous actions
Plan-and-execute agents: decide on the full sequence of actions up front, then execute them all without updating the plan
We combine this with Streamlit, a python based web app framework popular among machine learning engineers to build an AI web application powered by langchain and feels interactive and blazing fast⚡!
Read about LangChain Agents:
python.langchain.com/docs/mod...
Read about Streamlit:
docs.streamlit.io/
MRKL paper:
arxiv.org/pdf/2205.00445.pdf
- Watch PART 1 of the LangChain / LLM series:
Build a GPT Q&A on your own data
• LangChain + OpenAI tut...
- Watch PART 2 of the LangChain / LLM series:
LangChain + OpenAI to chat w/ (query) own Database / CSV!
• LangChain + OpenAI to ...
- Watch PART 3 of the LangChain / LLM series
LangChain + HuggingFace's Inference API (no OpenAI credits required!)
• LangChain + HuggingFac...
- Watch PART 4 of the LangChain / LLM series
Understanding Embeddings in LLMs (ft LlamadIndex + Chroma db)
• Understanding Embeddin...
- Watch PART 5 of the LangChain / LLM series
Query any website with GPT3 and LlamaIndex
• GPT scrapes + answers ...
- Watch PART 6 of the LangChain / LLM series
Locally-hosted, offline LLM w/LlamaIndex + OPT (open source, instruction-tuning LLM)
• Locally-hosted, offlin...
- Watch PART 7 of the LangChain / LLM series
Building an AI language tutor: Pinecone + LlamaIndex + GPT-3 + BeautifulSoup
• Building an AI languag...
- Watch PART 8 of the LangChain / LLM series
Building a queryable journal 💬 w/ OpenAI, markdown & LlamaIndex 🦙
• Building a queryable j...
- Watch PART 9 of the LLM series
Making a Sci-Fi game w/ Cohere LLM + Stability.ai: Generative AI tutorial
• Making a Sci-Fi game w...
- Watch PART 10 of the LLM series
GPT builds entire app from prompt (ft. SMOL Developer)
• GPT builds entire app ...
- Watch Part 11 (Prompt Engineering / Prompt Design)
A language for LLM Prompt Design: Guidance
• A language for LLM pro...
- Watch Part 12: LangChain Caching
• You should use LangCha...
All the code for the LLM (large language models) series featuring GPT-3, ChatGPT, LangChain, LlamaIndex and more are on my github repository so go and ⭐ star or 🍴 fork it. Happy Coding!
github.com/onlyphantom/llm-py... - Наука та технологія
Your LangChain series is incredible. I've learned so much, to reiterate many others here. Hope to see more in the future! Thanks!
Thank you! Very encouraging and I appreciate it!
I don't know how you do it but man you create a lot of content. Thank you very much.
Thank you!
Thank you so much for this informative video on building Chat AI apps with Streamlit and LangChain! Your content is incredibly helpful and well-presented. I've learned a lot and appreciate the effort you put into creating this. Keep up the great work! 👍
Thank you! Means a lot, appreciate it!
Great content, really like this format. Lots of specific information presented very quickly.
Thank you! I appreciate the feedback!
thank you for this content! i am looking forward to watching more of your videos!
Thank you! Means a lot!
Hey Sam,
your series has helped me immensely. I am trying to build on the work here and add some sort of cacheing so I can continue to ask questions. Any tips you can offer to do this?
Good video. I feel that the best way to learn about the whole "Langchain ecosystem" is to start with Flowise and then to eventually moved back into Langchain for more bespoke projects.
I’ll take a look at Flowise! :)
Would you make a video about building embeddings & LLM without relying on APIs, just our data, please.
That's actually exactly what I am building right now for my personal assistant. I realized that a plain vector search wasn't accurate enough, so do I small llm call first to get the domain which I need to query, and skip unrelated domains.
Yeah the step by step approach! Are you building it in public? If so, I’d like to check it out or follow your progress on github
Its private for now, because I am planning on hosting it publicly as my personal website, and I don't want to expose the specifics of a public system which can use my credit card. Once that thing is live and I had time to clean up I am planning on making a version public though.
Love your videos, really impressive how fast you can prototype with your setup.
Looking forward to seeing it go live! 🔥
Would you share the code of the last version of the streamlit app with more tools that you showcase on the video? the one on github seems to be the simple one. Thanks! was a great series!
@samuelChan super great videos (big thankyou, super helpful)
Streamlit Question
(In the second part of the video, you mention console log verity briefly)
Does this mean are you able to output the console log into streamlit call back handler?
Use case: Trying to show all details in ui including full outputs of console log in each of agents step in streamlit. (Hence trying to clarify how) so can re-use.
hey thank you! Can you give me a timestamp on the console log part? Would love to clarify and maybe add that extra note as a comment in the github code too!
Thanks!
Great seeing you here!
@@SamuelChan took me long enough
Never too late!
Great tutorial, thank you.
Question : Can we set multiple tools for an Agent, if yes , how can the Agent chose the right tool to use ?
Yeah you can use multiple tools; Choosing the right tool is a key component of the MRKL system.
A MRKL agent consists of three parts:
1. Tools: The tools the agent has available to use.
2. LLMChain: The LLMChain that produces the text that is parsed in a certain way to determine which action to take.
3. The agent class itself: this parses the output of the LLMChain to determine which action to take.
Thank you for this content. It's helping me a lot to build a chat bot with a knowledge base in my company. Can you provide the streamlit demo code from the final of the video in you repo? I checked and just saw the simpler streamlit demo.
Hey! Yes I’ll update the repo! (So sorry I’m currently traveling in Japan 🇯🇵 and have no access to my work computer but I’ll do once I get home by end of next week). Your project sounds like a great fit for what you’d use streamlit + LangChain for, looking forward to see where that goes!
Also, appreciate the super thanks! 🙏🏼
@@SamuelChan luckily your video resolution is good so I was able to add those few lines. I just manually did those updates. Note: He is looking for the message chaining via st.session_state and maybe not the open api key input thingy
Great Content :), I'm trying to implement CSV agent in Streamlit, but It's not able to render the plots interactively in streamlit layout instead they r opening in other tab, any suggestions, or workarounds on using CSV agent inside streamlit
Hmm do you have the code somewhere on your repo? I can try to fork and experiment with it to understand a bit more about the issue you’re facing. Might not be this coming week though, currently traveling around Japan with the missus
We can implement these tools for our conversational bots? Bots we can have conversations with with simulated memory and can call functions also.
Yeah and LangChain makes that easy as well, using Memory!
python.langchain.com/docs/modules/memory/
Greate 🎉. Is is possible to donthe same for local LLM model rather than OpenAI model?
Yeah, check out my LLM series to see local LLM / huggingface model examples!
Thanks a LOT it's amazing and literally saved me a ton of time trying to do it myself.
The base version well with me, but when i try to go the the most advance part you mentionned at the end, integrating the " from streamlit_agent " i got this error : ModuleNotFoundError: No module named 'streamlit_agent'
I cannot really find online what it could be. Any guess what i did wrong? thanks a bunch, you rock!
Wow thank you, love it!
Could it have been a dependency thing? I would do a pip list out to check! :)
@@SamuelChan such a quick reply! Thanks a lot!!
I though about it too, and try to uninstall/reinstall/upgrade, but it didn't works.
that's my pip list :
Package Version
------------------------- ------------------
aiofiles 23.2.1
aiohttp 3.8.5
aiosignal 1.3.1
altair 5.0.1
anyio 3.7.1
argcomplete 1.10.3
argilla 1.14.0
async-timeout 4.0.3
attrs 23.1.0
azure-ai-textanalytics 5.3.0
azure-common 1.1.28
azure-core 1.29.1
backoff 2.2.1
beautifulsoup4 4.8.2
blinker 1.6.2
Brotli 1.0.9
cachetools 5.3.1
certifi 2023.7.22
cffi 1.15.1
chardet 3.0.4
charset-normalizer 3.2.0
chroma-hnswlib 0.7.2
chromadb 0.4.5
click 8.1.6
colorama 0.4.6
coloredlogs 15.0.1
compressed-rtf 1.0.6
contourpy 1.1.0
cryptography 41.0.3
cycler 0.11.0
dataclasses-json 0.5.14
Deprecated 1.2.14
docopt 0.6.2
docx2txt 0.8
duckduckgo-search 3.8.4
ebcdic 1.1.1
et-xmlfile 1.1.0
extract-msg 0.28.7
faiss-cpu 1.7.4
fastapi 0.99.1
filelock 3.12.2
filetype 1.2.0
flatbuffers 23.5.26
fonttools 4.42.0
frozenlist 1.4.0
fsspec 2023.6.0
gitdb 4.0.10
GitPython 3.1.32
greenlet 2.0.2
h11 0.14.0
h2 4.1.0
hpack 4.0.0
httpcore 0.16.3
httptools 0.6.0
httpx 0.23.3
huggingface-hub 0.16.4
humanfriendly 10.0
hyperframe 6.0.1
idna 3.4
IMAPClient 2.1.0
importlib-metadata 6.8.0
importlib-resources 6.0.1
install 1.3.5
isodate 0.6.1
Jinja2 3.1.2
joblib 1.3.2
jsonschema 4.19.0
jsonschema-specifications 2023.7.1
kiwisolver 1.4.4
langchain 0.0.264
langsmith 0.0.21
lxml 4.9.3
Markdown 3.4.4
markdown-it-py 3.0.0
MarkupSafe 2.1.3
marshmallow 3.20.1
matplotlib 3.7.2
mdurl 0.1.2
monotonic 1.6
mpmath 1.3.0
msg-parser 1.2.0
multidict 6.0.4
mypy-extensions 1.0.0
nltk 3.8.1
num2words 0.5.12
numexpr 2.8.5
numpy 1.23.5
olefile 0.46
onnxruntime 1.15.1
openai 0.27.8
openapi-schema-pydantic 1.2.4
openpyxl 3.1.2
overrides 7.4.0
packaging 23.1
pandas 1.5.3
pdf2image 1.16.3
pdfminer.six 20221105
Pillow 9.5.0
pip 23.2.1
plotly 5.16.0
posthog 3.0.1
protobuf 4.24.0
pulsar-client 3.2.0
pyarrow 12.0.1
pycparser 2.21
pycryptodome 3.18.0
pydantic 1.10.12
pydeck 0.8.0
Pygments 2.16.1
Pympler 1.0.1
pypandoc 1.11
pyparsing 3.0.9
pypdf 3.15.1
PyPDF2 3.0.1
pypdfium2 4.18.0
PyPika 0.48.9
pyreadline3 3.4.1
python-dateutil 2.8.2
python-docx 0.8.11
python-dotenv 1.0.0
python-magic 0.4.27
python-pptx 0.6.21
pytz 2023.3
pytz-deprecation-shim 0.1.0.post0
PyYAML 6.0.1
referencing 0.30.2
regex 2023.8.8
requests 2.31.0
rfc3986 1.5.0
rich 13.5.2
rpds-py 0.9.2
safetensors 0.3.2
scikit-learn 1.3.0
scipy 1.11.1
setuptools 68.0.0
six 1.12.0
smmap 5.0.0
sniffio 1.3.0
socksio 1.0.0
sortedcontainers 2.4.0
soupsieve 2.4.1
SpeechRecognition 3.8.1
SQLAlchemy 2.0.19
starlette 0.27.0
streamlit 1.25.0
streamlit-nightly 1.25.1.dev20230813
sympy 1.12
tabulate 0.9.0
tenacity 8.2.2
threadpoolctl 3.2.0
tiktoken 0.4.0
tokenizers 0.13.3
toml 0.10.2
toolz 0.12.0
tornado 6.3.3
tqdm 4.66.1
transformers 4.31.0
typer 0.7.0
typing_extensions 4.7.1
typing-inspect 0.9.0
tzdata 2023.3
tzlocal 4.3.1
unstructured 0.7.12
urllib3 2.0.4
uvicorn 0.23.2
validators 0.21.2
watchdog 3.0.0
watchfiles 0.19.0
websockets 11.0.3
wrapt 1.14.1
xlrd 1.2.0
XlsxWriter 3.1.2
yarl 1.9.2
zipp 3.16.2
thanks again a LOT!
Ok! Turns out it’s not a dependency thing!
The streamlit_agent is a module you create in the same directory with some scaffolding code - I recorded it but left them out in the editing process to keep the video under 30 mins, being concise and focused, my thoughts are that those interested in that would just hop over to my GitHub for the code reference.
When you’re importing streamlit_agent you’re importing from this module you create! :)
Another great vid🙌🏼 I’m getting a type error ddgs object does not support the context manager protocol🤔my code is exact and all install and imports done, any ideas?
ddg is the duck duck go wrapper, but I don’t remember seeing that context manager error using it. Without the context manager (the with statement) does it work?
@@SamuelChan the issue seems to lie with duck duck go, is there a way to amend this to use serpapi?
yeah that should work as well - might require an account token for Google’s API but otherwise it’s a good alternative
@@SamuelChan thanks, works great now!
Thanks for updating! Great to hear!
Hi thank you. I tried the simple code and seens no matter the question it always use the agent instead to chat. Simple question gets an error. I was wondering use an agent only when it is need. Is that correct?
Hey! What's the error and what's the question + your set up to reproduce said error?
@@SamuelChan Entering new AgentExecutor chain...
Thought: Do I need to use a tool? No
AI: Thank you for letting me know that this is only a test. How can I assist you further?
> Finished chain.
> Entering new AgentExecutor chain...
Thought: Do I need to use a tool? Yes
Action: duckduckgo_search
Action Input: Who discovered America?
Observation: Christopher Columbus is credited with discovering the Americas in 1492. Americans get a day off work on October 10 to celebrate Columbus Day. It's an annual holiday that commemorates the day on... While many schoolchildren are taught that Christopher Columbus was responsible for the discovery of America in 1492, the true history of the land's exploration stretches back long before Columbus was even born. But did Christopher Columbus discover America before other Europeans? Modern research has suggested that wasn't even the case. Quick Fact! Christopher Columbus commandeered the three ships Nina, Santa Maria and Pinta during his voyage which started off from Palos, Spain on August 3, 1492. America had often been discovered before Columbus, but it had always been hushed up. He wasn't the first person to discover the continent. Instead, his discovery was the last of many discoveries. In all, people found the Americas at least seven different times. Though much happened before Christopher Columbus' famous journey (such as Leif Ericsson's landing in North America about five centuries prior), it remains a significant event in history and is...
Thought:Could not parse LLM output: `Do I need to use a tool? No`
Observation: Could not parse LLM output: `Do I need to use a to
Thought:Could not parse LLM output: `Do I need to use a tool? No`
Observation: Could not parse LLM output: `Do I need to use a to
Thought:
Its possible to combinate the pdf file with this one?
can you do it with chainlit
I’ll add that to my watchlist ;) currently a bit busy with building LLM apps for clients, but hoping to get back to making video lessons soon!
@@SamuelChan ok
No problem 😊
Could you upload the code
Hey have you taken a look at the repo? It should be there!
GitHub.com/onlyphantom/llm-python
I downloaded the repo and do not see it there for some reason. 🤔 @@SamuelChan
great video how you get all that information about the functions on vscode? ua-cam.com/video/7QR6hXx_Nms/v-deo.html
Could have been the official Python extension in VS Code (formerly Pylance, published by Microsoft), besides that and Intellicode (also by Microsoft) I don't have much else installed.
@@SamuelChan thanks for the quick reply, is weird I think I have both but never saw that pane for langchain functions.