|  | 
| 55 | 55 |   }, | 
| 56 | 56 |   { | 
| 57 | 57 |    "cell_type": "code", | 
| 58 |  | -   "execution_count": 3, | 
|  | 58 | +   "execution_count": 27, | 
| 59 | 59 |    "metadata": {}, | 
| 60 | 60 |    "outputs": [ | 
| 61 | 61 |     { | 
| 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" | 
| 67 | 66 |      ] | 
| 68 | 67 |     } | 
| 69 | 68 |    ], | 
| 70 | 69 |    "source": [ | 
|  | 70 | +    "# https://devblogs.microsoft.com/semantic-kernel/now-in-beta-explore-the-enhanced-python-sdk-for-semantic-kernel/\n", | 
| 71 | 71 |     "from semantic_kernel import Kernel\n", | 
| 72 | 72 |     "from semantic_kernel.connectors.ai.open_ai import (\n", | 
| 73 | 73 |     "    AzureChatCompletion,\n", | 
| 74 | 74 |     "    AzureTextCompletion,\n", | 
| 75 | 75 |     ")\n", | 
| 76 | 76 |     "\n", | 
| 77 |  | -    "model = os.getenv(\"AZURE_GPT4_MODEL\", \"gpt4\")\n", | 
|  | 77 | +    "model = os.getenv(\"AZURE_GPT4_MODEL\", \"gpt4o\")\n", | 
| 78 | 78 |     "endpoint = os.getenv(\"OPENAI_API_BASE\")\n", | 
| 79 | 79 |     "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", | 
| 86 | 84 |     ")\n", | 
|  | 85 | +    "kernel.add_service(chat_completion)\n", | 
| 87 | 86 |     "\n", | 
| 88 | 87 |     "print(f\"Using deploy {endpoint} with model {model}\")" | 
| 89 | 88 |    ] | 
| 90 | 89 |   }, | 
|  | 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 | +  }, | 
| 91 | 168 |   { | 
| 92 | 169 |    "cell_type": "code", | 
| 93 | 170 |    "execution_count": null, | 
| 94 | 171 |    "metadata": {}, | 
| 95 | 172 |    "outputs": [], | 
| 96 | 173 |    "source": [ | 
| 97 |  | -    "# Now we need to import the plugin\n", | 
| 98 |  | -    "from plugins.AudioVideoPlugin.AudioVideo import AudioVideo\n", | 
| 99 | 174 |     "\n", | 
| 100 | 175 |     "# Now you can import the plugin importing skill directly from the function you declared\n", | 
| 101 | 176 |     "# in the plugin directory. The import_skill does not need the path, it only need an\n", | 
| 102 | 177 |     "# 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", | 
| 104 | 181 |     "\n", | 
| 105 | 182 |     "plugins_directory = \"./plugins\"\n", | 
| 106 | 183 |     "\n", | 
|  | 
| 115 | 192 |    "cell_type": "code", | 
| 116 | 193 |    "execution_count": null, | 
| 117 | 194 |    "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": [], | 
| 130 | 196 |    "source": [ | 
| 131 | 197 |     "extractaudio_plugin[\"ExtractAudio\"] #This is how you can call the plug" | 
| 132 | 198 |    ] | 
| 133 | 199 |   }, | 
| 134 | 200 |   { | 
| 135 | 201 |    "cell_type": "code", | 
| 136 |  | -   "execution_count": 6, | 
|  | 202 | +   "execution_count": null, | 
| 137 | 203 |    "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": [], | 
| 149 | 205 |    "source": [ | 
| 150 | 206 |     "from pprint import pprint\n", | 
| 151 | 207 |     "# want to print all the keys of extractaudio_plugin that is a dictionary\n", | 
|  | 
| 157 | 213 |   }, | 
| 158 | 214 |   { | 
| 159 | 215 |    "cell_type": "code", | 
| 160 |  | -   "execution_count": 7, | 
|  | 216 | +   "execution_count": null, | 
| 161 | 217 |    "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": [], | 
| 174 | 219 |    "source": [ | 
| 175 | 220 |     "# you can verify if cuda is available.\n", | 
| 176 | 221 |     "import torch\n", | 
|  | 
| 179 | 224 |   }, | 
| 180 | 225 |   { | 
| 181 | 226 |    "cell_type": "code", | 
| 182 |  | -   "execution_count": 8, | 
|  | 227 | +   "execution_count": null, | 
| 183 | 228 |    "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": [], | 
| 194 | 230 |    "source": [ | 
| 195 | 231 |     "import time\n", | 
| 196 | 232 |     "\n", | 
| 197 | 233 |     "result = await kernel.invoke(\n", | 
| 198 | 234 |     "    extractaudio_plugin[\"ExtractAudio\"],\n", | 
| 199 | 235 |     "    #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", | 
| 201 | 237 |     ")\n", | 
| 202 | 238 |     "\n", | 
| 203 | 239 |     "print (result)\n", | 
|  | 
| 207 | 243 |   }, | 
| 208 | 244 |   { | 
| 209 | 245 |    "cell_type": "code", | 
| 210 |  | -   "execution_count": 9, | 
|  | 246 | +   "execution_count": null, | 
| 211 | 247 |    "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": [], | 
| 230 | 249 |    "source": [ | 
| 231 | 250 |     "\n", | 
| 232 | 251 |     "# now invoke the plugin to transcript\n", | 
|  | 
| 270 | 289 |    "name": "python", | 
| 271 | 290 |    "nbconvert_exporter": "python", | 
| 272 | 291 |    "pygments_lexer": "ipython3", | 
| 273 |  | -   "version": "3.10.9" | 
|  | 292 | +   "version": "3.10.11" | 
| 274 | 293 |   } | 
| 275 | 294 |  }, | 
| 276 | 295 |  "nbformat": 4, | 
|  | 
0 commit comments