labs/embed_file_demo.ipynb (150 lines of code) (raw):
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"{\n",
" \"cells\": [\n",
" {\n",
" \"cell_type\": \"markdown\",\n",
" \"metadata\": {},\n",
" \"source\": [\n",
" \"# Demonstration of `embedder.embed_file`\\n\",\n",
" \"\\n\",\n",
" \"This notebook walks you through the process of calling the `embedder.embed_file(file_sas, file_name, sharepoint_file_id)` method from the `file_processing.py` module.\\n\",\n",
" \"We'll illustrate how to:\\n\",\n",
" \"1. Set up environment variables or configuration.\\n\",\n",
" \"2. Obtain an SAS URL (`file_sas`) for a file.\\n\",\n",
" \"3. Provide the file name (`file_name`).\\n\",\n",
" \"4. Define the SharePoint file ID (`sharepoint_file_id`).\\n\",\n",
" \"5. Invoke the `embed_file` function.\\n\"\n",
" ]\n",
" },\n",
" {\n",
" \"cell_type\": \"markdown\",\n",
" \"metadata\": {},\n",
" \"source\": [\n",
" \"## 1. Imports and Setup\\n\\n\",\n",
" \"Make sure you have all dependencies installed (like `azure-functions`, `azure.storage.blob`, and the utilities in your project).\"\n",
" ]\n",
" },\n",
" {\n",
" \"cell_type\": \"code\",\n",
" \"metadata\": {\n",
" \"tags\": []\n",
" },\n",
" \"source\": [\n",
" \"import os\\n\",\n",
" \"from utilities.helpers.env_helper import EnvHelper\\n\",\n",
" \"from utilities.helpers.embedders.embedder_factory import EmbedderFactory\\n\",\n",
" \"\\n\",\n",
" \"# Adjust these to match your environment or local settings\\n\",\n",
" \"os.environ['LOGLEVEL'] = 'DEBUG'\\n\",\n",
" \"\\n\",\n",
" \"# Initialize any environment-specific helpers\\n\",\n",
" \"env_helper = EnvHelper()\"\n",
" ],\n",
" \"execution_count\": null,\n",
" \"outputs\": []\n",
" },\n",
" {\n",
" \"cell_type\": \"markdown\",\n",
" \"metadata\": {},\n",
" \"source\": [\n",
" \"## 2. Example Values for `embed_file`\\n\\n\",\n",
" \"Below, replace the placeholders with real values:\\n\",\n",
" \"- `file_sas`: A valid SAS URL to the blob.\\n\",\n",
" \"- `file_name`: The blob name.\\n\",\n",
" \"- `sharepoint_file_id`: Corresponding ID for the SharePoint file.\"\n",
" ]\n",
" },\n",
" {\n",
" \"cell_type\": \"code\",\n",
" \"metadata\": {\n",
" \"tags\": []\n",
" },\n",
" \"source\": [\n",
" \"# Example placeholders\\n\",\n",
" \"file_sas = \\\"https://mystorageaccount.blob.core.windows.net/container/myfile.txt?sp=rl&st=...\\\" # Example SAS URL\\n\",\n",
" \"file_name = \\\"myfile.txt\\\"\\n\",\n",
" \"sharepoint_file_id = \\\"12345\\\"\\n\"\n",
" ],\n",
" \"execution_count\": null,\n",
" \"outputs\": []\n",
" },\n",
" {\n",
" \"cell_type\": \"markdown\",\n",
" \"metadata\": {},\n",
" \"source\": [\n",
" \"## 3. Create Embedder and Call `embed_file`\\n\\n\",\n",
" \"We create an embedder instance using `EmbedderFactory.create` and call the function with our parameters.\"\n",
" ]\n",
" },\n",
" {\n",
" \"cell_type\": \"code\",\n",
" \"metadata\": {\n",
" \"tags\": []\n",
" },\n",
" \"source\": [\n",
" \"# Create the embedder\\n\",\n",
" \"embedder = EmbedderFactory.create(env_helper)\\n\",\n",
" \"\\n\",\n",
" \"# Call embed_file\\n\",\n",
" \"embedder.embed_file(\\n\",\n",
" \" file_sas=file_sas,\\n\",\n",
" \" file_name=file_name,\\n\",\n",
" \" sharepoint_file_id=sharepoint_file_id\\n\",\n",
" \")\\n\",\n",
" \"\\n\",\n",
" \"print(\\\"Embedding process initiated.\\\")\"\n",
" ],\n",
" \"execution_count\": null,\n",
" \"outputs\": []\n",
" },\n",
" {\n",
" \"cell_type\": \"markdown\",\n",
" \"metadata\": {},\n",
" \"source\": [\n",
" \"## 4. Next Steps\\n\\n\",\n",
" \"1. Check the logs or application output to confirm the embedding was handled.\\n\",\n",
" \"2. Monitor any search or index updates that follow.\\n\",\n",
" \"3. Customize or extend this notebook to run multiple test files.\\n\"\n",
" ]\n",
" }\n",
" ],\n",
" \"metadata\": {\n",
" \"kernelspec\": {\n",
" \"display_name\": \"Python 3\",\n",
" \"language\": \"python\",\n",
" \"name\": \"python3\"\n",
" },\n",
" \"language_info\": {\n",
" \"name\": \"python\",\n",
" \"mimetype\": \"text/x-python\",\n",
" \"codemirror_mode\": {\n",
" \"name\": \"ipython\",\n",
" \"version\": 3\n",
" }\n",
" }\n",
" },\n",
" \"nbformat\": 4,\n",
" \"nbformat_minor\": 5\n",
"}"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}