FortiShield commited on
Commit
9eb7cd6
1 Parent(s): 0741d7d

Add files via upload

Browse files
Files changed (1) hide show
  1. L1_Your_First_AI_Agent.ipynb +155 -0
L1_Your_First_AI_Agent.ipynb ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "2df80339",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Lesson 1: Your First AI Agent\n",
9
+ "\n",
10
+ "Welcome to Lesson 1.\n",
11
+ "\n",
12
+ "To access the `requirements.txt` file, please go to the `File` menu and select`Open...`.\n",
13
+ "\n",
14
+ "I hope you enjoy this course!"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "markdown",
19
+ "id": "bfdcabc1",
20
+ "metadata": {},
21
+ "source": [
22
+ "## Setup"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": null,
28
+ "id": "e8a67f41-d133-4e91-b54f-80bb3cd9a666",
29
+ "metadata": {
30
+ "height": 64
31
+ },
32
+ "outputs": [],
33
+ "source": [
34
+ "import os \n",
35
+ "import pandas as pd \n",
36
+ "from IPython.display import Markdown, HTML, display"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "markdown",
41
+ "id": "f4c6e550",
42
+ "metadata": {},
43
+ "source": [
44
+ "## Connect to the Azure OpenAI endpoint\n",
45
+ "\n",
46
+ "**Note**: The pre-configured cloud resource grants you access to the Azure OpenAI GPT model. The key and endpoint provided below are intended for teaching purposes only. Your notebook environment is already set up with the necessary keys, which may differ from those used by the instructor during the filming."
47
+ ]
48
+ },
49
+ {
50
+ "cell_type": "markdown",
51
+ "id": "56216e12",
52
+ "metadata": {},
53
+ "source": [
54
+ "```\n",
55
+ "openai_api_version=\"2023-05-15\"\n",
56
+ "azure_deployment=\"gpt-4-1106\"\n",
57
+ "azure_endpoint=\"https://testadri.openai.azure.com\"\n",
58
+ "\n",
59
+ "```"
60
+ ]
61
+ },
62
+ {
63
+ "cell_type": "markdown",
64
+ "id": "178321d6",
65
+ "metadata": {},
66
+ "source": [
67
+ "## 1. Leveraging Langchain"
68
+ ]
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "execution_count": null,
73
+ "id": "c5e4be2b",
74
+ "metadata": {
75
+ "height": 149
76
+ },
77
+ "outputs": [],
78
+ "source": [
79
+ "from langchain.schema import HumanMessage\n",
80
+ "from langchain_openai import AzureChatOpenAI\n",
81
+ "\n",
82
+ "model = AzureChatOpenAI(\n",
83
+ " openai_api_version=\"2024-04-01-preview\",\n",
84
+ " azure_deployment=\"gpt-4-1106\",\n",
85
+ " azure_endpoint=os.getenv(\"AZURE_OPENAI_ENDPOINT\"),\n",
86
+ ")"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "markdown",
91
+ "id": "9fde1292",
92
+ "metadata": {},
93
+ "source": [
94
+ "## 2. Preparing your prompt"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": null,
100
+ "id": "0d145d0d-30f2-412b-822c-e23ff9bf2bc4",
101
+ "metadata": {
102
+ "height": 98
103
+ },
104
+ "outputs": [],
105
+ "source": [
106
+ "message = HumanMessage(\n",
107
+ " content=\"Translate this sentence from English \"\n",
108
+ " \"to French and Spanish. I like red cars and \"\n",
109
+ " \"blue houses, but my dog is yellow.\"\n",
110
+ ")"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "markdown",
115
+ "id": "94f5e7b6",
116
+ "metadata": {},
117
+ "source": [
118
+ "## 3. Engaging the model to receive a response"
119
+ ]
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "execution_count": null,
124
+ "id": "e49e3b6d-71e8-4906-bf9c-fca78c1fbd4c",
125
+ "metadata": {
126
+ "height": 30
127
+ },
128
+ "outputs": [],
129
+ "source": [
130
+ "model.invoke([message])"
131
+ ]
132
+ }
133
+ ],
134
+ "metadata": {
135
+ "kernelspec": {
136
+ "display_name": "Python 3 (ipykernel)",
137
+ "language": "python",
138
+ "name": "python3"
139
+ },
140
+ "language_info": {
141
+ "codemirror_mode": {
142
+ "name": "ipython",
143
+ "version": 3
144
+ },
145
+ "file_extension": ".py",
146
+ "mimetype": "text/x-python",
147
+ "name": "python",
148
+ "nbconvert_exporter": "python",
149
+ "pygments_lexer": "ipython3",
150
+ "version": "3.11.9"
151
+ }
152
+ },
153
+ "nbformat": 4,
154
+ "nbformat_minor": 5
155
+ }