Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deeplearning-ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# DeepLearning AI
File renamed without changes.
File renamed without changes.
121 changes: 71 additions & 50 deletions module-0/basics.ipynb → langchain-academy/module-0/basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,36 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "c2a15227",
"metadata": {},
"outputs": [],
"source": [
"import os, getpass\n",
"# import os, getpass\n",
"\n",
"# def _set_env(var: str):\n",
"# if not os.environ.get(var):\n",
"# os.environ[var] = getpass.getpass(f\"{var}: \")\n",
"\n",
"# _set_env(\"OPENAI_API_KEY\")"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "0ffb6a23",
"metadata": {},
"outputs": [],
"source": [
"# load environment variables\n",
"from dotenv import load_dotenv\n",
"import os\n",
"\n",
"def _set_env(var: str):\n",
" if not os.environ.get(var):\n",
" os.environ[var] = getpass.getpass(f\"{var}: \")\n",
"load_dotenv(dotenv_path='C:\\MIConsulting\\LangChain\\langchain-academy\\.env')\n",
"\n",
"_set_env(\"OPENAI_API_KEY\")"
"# OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\")\n",
"GOOGLEAI_API_KEY = os.getenv(\"GOOGLEAI_API_KEY\")\n",
"TAVILY_API_KEY = os.getenv(\"TAVILY_API_KEY\")"
]
},
{
Expand All @@ -84,14 +102,34 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 10,
"id": "e19a54d3",
"metadata": {},
"outputs": [],
"source": [
"from langchain_openai import ChatOpenAI\n",
"gpt4o_chat = ChatOpenAI(model=\"gpt-4o\", temperature=0)\n",
"gpt35_chat = ChatOpenAI(model=\"gpt-3.5-turbo-0125\", temperature=0)"
"# from langchain_openai import ChatOpenAI\n",
"\n",
"# gpt4o_chat = ChatOpenAI(model=\"gpt-4o\", temperature=0)\n",
"# gpt35_chat = ChatOpenAI(model=\"gpt-3.5-turbo-0125\", temperature=0)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "16e79f2e",
"metadata": {},
"outputs": [],
"source": [
"from langchain_google_genai import ChatGoogleGenerativeAI\n",
"\n",
"gemini15_chat = ChatGoogleGenerativeAI(\n",
" model=\"gemini-1.5-pro\",\n",
" temperature=0,\n",
" max_tokens=None,\n",
" timeout=None,\n",
" max_retries=2,\n",
" api_key=GOOGLEAI_API_KEY,\n",
")"
]
},
{
Expand All @@ -109,17 +147,17 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 19,
"id": "b1280e1b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AIMessage(content='Hello! How can I assist you today?', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 11, 'total_tokens': 20}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_157b3831f5', 'finish_reason': 'stop', 'logprobs': None}, id='run-d3c4bc85-ef14-49f6-ba7e-91bf455cffee-0', usage_metadata={'input_tokens': 11, 'output_tokens': 9, 'total_tokens': 20})"
"AIMessage(content='Hello world back to you!\\n', additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-07967d2a-4feb-48f8-9f50-4c7aee2d331f-0', usage_metadata={'input_tokens': 3, 'output_tokens': 7, 'total_tokens': 10, 'input_token_details': {'cache_read': 0}})"
]
},
"execution_count": 3,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -134,7 +172,9 @@
"messages = [msg]\n",
"\n",
"# Invoke the model with a list of messages \n",
"gpt4o_chat.invoke(messages)"
"# gpt4o_chat.invoke(messages)\n",
"# gpt35_chat.invoke(messages)\n",
"gemini15_chat.invoke(messages)"
]
},
{
Expand All @@ -147,44 +187,24 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 20,
"id": "f27c6c9a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AIMessage(content='Hello! How can I assist you today?', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 9, 'total_tokens': 18}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_157b3831f5', 'finish_reason': 'stop', 'logprobs': None}, id='run-d6f6b682-e29a-44de-b45e-79fad1e405e5-0', usage_metadata={'input_tokens': 9, 'output_tokens': 9, 'total_tokens': 18})"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gpt4o_chat.invoke(\"hello world\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "fdc2f0ca",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AIMessage(content='Hello! How can I assist you today?', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 9, 'total_tokens': 18}, 'model_name': 'gpt-3.5-turbo-0125', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-c75d3f0f-2d71-47be-b14c-42b8dd2b4b08-0', usage_metadata={'input_tokens': 9, 'output_tokens': 9, 'total_tokens': 18})"
"AIMessage(content='Hello world!\\n', additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-add51968-5aad-45f1-b010-25e112d3b76f-0', usage_metadata={'input_tokens': 3, 'output_tokens': 4, 'total_tokens': 7, 'input_token_details': {'cache_read': 0}})"
]
},
"execution_count": 5,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gpt35_chat.invoke(\"hello world\")"
"# gpt4o_chat.invoke(\"hello world\")\n",
"gemini15_chat.invoke(\"hello world\")"
]
},
{
Expand Down Expand Up @@ -214,39 +234,40 @@
"metadata": {},
"outputs": [],
"source": [
"_set_env(\"TAVILY_API_KEY\")"
"# _set_env(\"TAVILY_API_KEY\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 23,
"id": "52d69da9",
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.tools.tavily_search import TavilySearchResults\n",
"\n",
"tavily_search = TavilySearchResults(max_results=3)\n",
"search_docs = tavily_search.invoke(\"What is LangGraph?\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 24,
"id": "d06f87e6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'url': 'https://www.datacamp.com/tutorial/langgraph-tutorial',\n",
"[{'url': 'https://langchain-ai.github.io/langgraph/',\n",
" 'content': 'Overview¶. LangGraph is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. Compared to other LLM frameworks, it offers these core benefits: cycles, controllability, and persistence. LangGraph allows you to define flows that involve cycles, essential for most agentic architectures, differentiating it from DAG-based solutions.'},\n",
" {'url': 'https://www.datacamp.com/tutorial/langgraph-tutorial',\n",
" 'content': 'LangGraph is a library within the LangChain ecosystem designed to tackle these challenges head-on. LangGraph provides a framework for defining, coordinating, and executing multiple LLM agents (or chains) in a structured manner.'},\n",
" {'url': 'https://langchain-ai.github.io/langgraph/',\n",
" 'content': 'Overview LangGraph is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. Compared to other LLM frameworks, it offers these core benefits: cycles, controllability, and persistence. LangGraph allows you to define flows that involve cycles, essential for most agentic architectures, differentiating it from DAG-based solutions. As a ...'},\n",
" {'url': 'https://www.youtube.com/watch?v=nmDFSVRnr4Q',\n",
" 'content': 'LangGraph is an extension of LangChain enabling Multi-Agent conversation and cyclic chains. This video explains the basics of LangGraph and codesLangChain in...'}]"
" {'url': 'https://medium.com/@cplog/introduction-to-langgraph-a-beginners-guide-14f9be027141',\n",
" 'content': 'LangGraph is a versatile tool for building complex, stateful applications with LLMs. By understanding its core concepts and working through simple examples, beginners can start to leverage its'}]"
]
},
"execution_count": 7,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -266,7 +287,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "lc-academy",
"language": "python",
"name": "python3"
},
Expand All @@ -280,7 +301,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down
Binary file not shown.
Loading