Skip to content

Commit 8e36d10

Browse files
committed
Updated to latest version of sk
1 parent f5fb390 commit 8e36d10

File tree

1 file changed

+104
-85
lines changed

1 file changed

+104
-85
lines changed

01_basic/03_chain_skill_call.ipynb

Lines changed: 104 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -55,52 +55,129 @@
5555
},
5656
{
5757
"cell_type": "code",
58-
"execution_count": 3,
58+
"execution_count": 27,
5959
"metadata": {},
6060
"outputs": [
6161
{
62-
"ename": "SyntaxError",
63-
"evalue": "f-string: unmatched '(' (2166899585.py, line 16)",
64-
"output_type": "error",
65-
"traceback": [
66-
"\u001b[1;36m Cell \u001b[1;32mIn[3], line 16\u001b[1;36m\u001b[0m\n\u001b[1;33m print(f\"Using deploy {os.getenv(\"OPENAI_API_BASE\")} with model {os.getenv(\"AZURE_GPT4_MODEL\")}\")\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m f-string: unmatched '('\n"
62+
"name": "stdout",
63+
"output_type": "stream",
64+
"text": [
65+
"Using deploy https://alkopenai2.openai.azure.com/ with model gpt42\n"
6766
]
6867
}
6968
],
7069
"source": [
70+
"# https://devblogs.microsoft.com/semantic-kernel/now-in-beta-explore-the-enhanced-python-sdk-for-semantic-kernel/\n",
7171
"from semantic_kernel import Kernel\n",
7272
"from semantic_kernel.connectors.ai.open_ai import (\n",
7373
" AzureChatCompletion,\n",
7474
" AzureTextCompletion,\n",
7575
")\n",
7676
"\n",
77-
"model = os.getenv(\"AZURE_GPT4_MODEL\", \"gpt4\")\n",
77+
"model = os.getenv(\"AZURE_GPT4_MODEL\", \"gpt4o\")\n",
7878
"endpoint = os.getenv(\"OPENAI_API_BASE\")\n",
7979
"kernel = Kernel(log=logger)\n",
80-
"kernel.add_service(\n",
81-
" AzureChatCompletion(\n",
82-
" model,\n",
83-
" endpoint = endpoint,\n",
84-
" api_key = os.getenv(\"OPENAI_API_KEY\")\n",
85-
" ),\n",
80+
"chat_completion = AzureChatCompletion(\n",
81+
" deployment_name=model,\n",
82+
" endpoint = endpoint,\n",
83+
" api_key = os.getenv(\"OPENAI_API_KEY\")\n",
8684
")\n",
85+
"kernel.add_service(chat_completion)\n",
8786
"\n",
8887
"print(f\"Using deploy {endpoint} with model {model}\")"
8988
]
9089
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": 32,
93+
"metadata": {},
94+
"outputs": [
95+
{
96+
"name": "stdout",
97+
"output_type": "stream",
98+
"text": [
99+
"Yarr! Th' capital be Paris, me heartie!\n",
100+
"-------------------------\n"
101+
]
102+
}
103+
],
104+
"source": [
105+
"question = \"What is the capital of France?\"\n",
106+
"prompt = f\"You will answer in a pirate language to the user question. question {question}\"\n",
107+
"prompt_function = kernel.add_function(function_name=\"pirate_question\", plugin_name=\"pirate_matey\", prompt=prompt)\n",
108+
"result = await kernel.invoke(prompt_function)\n",
109+
"print(result)\n",
110+
"print(\"-------------------------\")\n",
111+
"\n"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": 47,
117+
"metadata": {},
118+
"outputs": [
119+
{
120+
"name": "stdout",
121+
"output_type": "stream",
122+
"text": [
123+
"Th' capital o' France be Paris, matey!\n",
124+
"-------------------------\n"
125+
]
126+
}
127+
],
128+
"source": [
129+
"#https://github.com/microsoft/semantic-kernel/blob/6be43bc7ff0b0304f443b3d00f6316599a3e8707/python/README.md?plain=1#L90\n",
130+
"from semantic_kernel.prompt_template import PromptTemplateConfig\n",
131+
"\n",
132+
"question = \"What is the capital of France?\"\n",
133+
"prompt_template_config = PromptTemplateConfig(\n",
134+
" template_format=\"semantic-kernel\",\n",
135+
" template=\"You will answer in a pirate language to the user question. question {question}\",\n",
136+
")\n",
137+
"\n",
138+
"prompt_function = kernel.add_function(\n",
139+
" function_name=\"pirate_question_parameter\", \n",
140+
" plugin_name=\"pirate_matey_parameter\",\n",
141+
" prompt= \"You will answer in a pirate language to the user question. question {{$question}}\")\n",
142+
"result = await kernel.invoke(prompt_function, question=question)\n",
143+
"print(result)\n",
144+
"print(\"-------------------------\")"
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": null,
150+
"metadata": {},
151+
"outputs": [],
152+
"source": [
153+
"nction(function_name=\"pirate_question\", plugin_name=\"pirate_matey\", prompt=prompt)\n",
154+
"result = await kernel.invoke(prompt_function)\n",
155+
"print(result)\n",
156+
"print(\"-------------------------\")"
157+
]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": null,
162+
"metadata": {},
163+
"outputs": [],
164+
"source": [
165+
"from plugins.AudioVideoPlugin.AudioVideo import AudioVideo\n"
166+
]
167+
},
91168
{
92169
"cell_type": "code",
93170
"execution_count": null,
94171
"metadata": {},
95172
"outputs": [],
96173
"source": [
97-
"# Now we need to import the plugin\n",
98-
"from plugins.AudioVideoPlugin.AudioVideo import AudioVideo\n",
99174
"\n",
100175
"# Now you can import the plugin importing skill directly from the function you declared\n",
101176
"# in the plugin directory. The import_skill does not need the path, it only need an\n",
102177
"# instance of the skill and the name of the skill\n",
103-
"extractaudio_plugin = kernel.add_plugin(AudioVideo(), \"AudioVideoPlugin\")\n",
178+
"\n",
179+
"plugin = AudioVideo()\n",
180+
"extractaudio_plugin = kernel.add_plugin(plugin, \"AudioVideoPlugin\")\n",
104181
"\n",
105182
"plugins_directory = \"./plugins\"\n",
106183
"\n",
@@ -115,37 +192,16 @@
115192
"cell_type": "code",
116193
"execution_count": null,
117194
"metadata": {},
118-
"outputs": [
119-
{
120-
"data": {
121-
"text/plain": [
122-
"KernelFunctionFromMethod(metadata=KernelFunctionMetadata(name='ExtractAudio', plugin_name='AudioVideoPlugin', description='extract audio in wav format from an mp4 file', parameters=[KernelParameterMetadata(name='videofile', description='Full path to the mp4 file', default_value=None, type_='str', is_required=True, type_object=<class 'str'>)], is_prompt=False, is_asynchronous=False, return_parameter=KernelParameterMetadata(name='return', description='output audio file path', default_value=None, type_='str', is_required=True, type_object=None)), method=<bound method AudioVideo.extract_audio of <plugins.AudioVideoPlugin.AudioVideo.AudioVideo object at 0x00000212EC39C250>>, stream_method=None)"
123-
]
124-
},
125-
"execution_count": 5,
126-
"metadata": {},
127-
"output_type": "execute_result"
128-
}
129-
],
195+
"outputs": [],
130196
"source": [
131197
"extractaudio_plugin[\"ExtractAudio\"] #This is how you can call the plug"
132198
]
133199
},
134200
{
135201
"cell_type": "code",
136-
"execution_count": 6,
202+
"execution_count": null,
137203
"metadata": {},
138-
"outputs": [
139-
{
140-
"name": "stdout",
141-
"output_type": "stream",
142-
"text": [
143-
"KernelFunctionFromMethod(metadata=KernelFunctionMetadata(name='ExtractAudio', plugin_name='AudioVideoPlugin', description='extract audio in wav format from an mp4 file', parameters=[KernelParameterMetadata(name='videofile', description='Full path to the mp4 file', default_value=None, type_='str', is_required=True, type_object=<class 'str'>)], is_prompt=False, is_asynchronous=False, return_parameter=KernelParameterMetadata(name='return', description='output audio file path', default_value=None, type_='str', is_required=True, type_object=None)), method=<bound method AudioVideo.extract_audio of <plugins.AudioVideoPlugin.AudioVideo.AudioVideo object at 0x00000212EC39C250>>, stream_method=None)\n",
144-
"KernelFunctionFromMethod(metadata=KernelFunctionMetadata(name='TranscriptTimeline', plugin_name='AudioVideoPlugin', description='Transcript audio from a wav file to a timeline', parameters=[KernelParameterMetadata(name='audiofile', description='Full path to the wav file', default_value=None, type_='str', is_required=True, type_object=<class 'str'>)], is_prompt=False, is_asynchronous=False, return_parameter=KernelParameterMetadata(name='return', description='', default_value=None, type_='str', is_required=True, type_object=None)), method=<bound method AudioVideo.transcript_timeline of <plugins.AudioVideoPlugin.AudioVideo.AudioVideo object at 0x00000212EC39C250>>, stream_method=None)\n",
145-
"KernelFunctionFromPrompt(metadata=KernelFunctionMetadata(name='VideoTimelineCreator', plugin_name='PublishingPlugin', description='Given a video transcript it can summarize and generate a timeline', parameters=[KernelParameterMetadata(name='input', description='', default_value='', type_='', is_required=True, type_object=None)], is_prompt=True, is_asynchronous=True, return_parameter=KernelParameterMetadata(name='return', description='The completion result', default_value=None, type_='FunctionResult', is_required=True, type_object=None)), prompt_template=KernelPromptTemplate(prompt_template_config=PromptTemplateConfig(name='VideoTimelineCreator', description='Given a video transcript it can summarize and generate a timeline', template='I will give you a transcript of a video. The transcript contains phrases prefixed by the timestamp where the phrase starts. I want you to identify between three and ten main sections of the video. You must never identify more than ten sections.\\nFor each section you will create a brief title prefixed with the start timestamp of the section obtained analyzing all the text belonging to that section.\\n\\nEXAMPLE ANSWER - Maximum of ten sections\\n00:00 - Title of section 1\\n00:33 - Title of section 2\\n01:23 - Title of section 3\\n\\n[DATA]\\n{{$input}}', template_format='semantic-kernel', input_variables=[InputVariable(name='input', description='', default='', is_required=True, json_schema='')], execution_settings={})), prompt_execution_settings={})\n"
146-
]
147-
}
148-
],
204+
"outputs": [],
149205
"source": [
150206
"from pprint import pprint\n",
151207
"# want to print all the keys of extractaudio_plugin that is a dictionary\n",
@@ -157,20 +213,9 @@
157213
},
158214
{
159215
"cell_type": "code",
160-
"execution_count": 7,
216+
"execution_count": null,
161217
"metadata": {},
162-
"outputs": [
163-
{
164-
"data": {
165-
"text/plain": [
166-
"True"
167-
]
168-
},
169-
"execution_count": 7,
170-
"metadata": {},
171-
"output_type": "execute_result"
172-
}
173-
],
218+
"outputs": [],
174219
"source": [
175220
"# you can verify if cuda is available.\n",
176221
"import torch\n",
@@ -179,25 +224,16 @@
179224
},
180225
{
181226
"cell_type": "code",
182-
"execution_count": 8,
227+
"execution_count": null,
183228
"metadata": {},
184-
"outputs": [
185-
{
186-
"name": "stdout",
187-
"output_type": "stream",
188-
"text": [
189-
"Extracting auio file from video S:\\OneDrive\\Youtube\\AI\\SemanticChain\\MontaggiCompleti\\010-CsharpIntro.mp4\n",
190-
"S:\\OneDrive\\Youtube\\AI\\SemanticChain\\MontaggiCompleti\\010-CsharpIntro.wav\n"
191-
]
192-
}
193-
],
229+
"outputs": [],
194230
"source": [
195231
"import time\n",
196232
"\n",
197233
"result = await kernel.invoke(\n",
198234
" extractaudio_plugin[\"ExtractAudio\"],\n",
199235
" #videofile =\"S:\\\\OneDrive\\\\Youtube\\\\AI\\\\SemanticChain\\\\MontaggiCompleti\\\\250-NlpPrecisionRecallRerank.mp4\"\n",
200-
" videofile =\"S:\\\\OneDrive\\\\Youtube\\\\AI\\\\SemanticChain\\\\MontaggiCompleti\\\\010-CsharpIntro.mp4\"\n",
236+
" videofile =\"S:\\\\OneDrive\\\\Youtube\\\\AI\\\\Various\\\\Montaggi\\\\200-Word2Vec.mp4\"\n",
201237
")\n",
202238
"\n",
203239
"print (result)\n",
@@ -207,26 +243,9 @@
207243
},
208244
{
209245
"cell_type": "code",
210-
"execution_count": 9,
246+
"execution_count": null,
211247
"metadata": {},
212-
"outputs": [
213-
{
214-
"name": "stdout",
215-
"output_type": "stream",
216-
"text": [
217-
"Extracting transcript from audio file S:\\OneDrive\\Youtube\\AI\\SemanticChain\\MontaggiCompleti\\010-CsharpIntro.wav\n",
218-
"Using device: cuda:0 to run whisper with model large-v3\n",
219-
"Detected language: English\n"
220-
]
221-
},
222-
{
223-
"name": "stderr",
224-
"output_type": "stream",
225-
"text": [
226-
" 18%|█▊ | 8598/46811 [08:58<47:41, 13.36frames/s]"
227-
]
228-
}
229-
],
248+
"outputs": [],
230249
"source": [
231250
"\n",
232251
"# now invoke the plugin to transcript\n",
@@ -270,7 +289,7 @@
270289
"name": "python",
271290
"nbconvert_exporter": "python",
272291
"pygments_lexer": "ipython3",
273-
"version": "3.10.9"
292+
"version": "3.10.11"
274293
}
275294
},
276295
"nbformat": 4,

0 commit comments

Comments
 (0)