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