|
136 | 136 | "from openai.types import FileObject\n", |
137 | 137 | "from openai.types.beta import Thread\n", |
138 | 138 | "from openai.types.beta.threads import Run\n", |
139 | | - "from openai.types.beta.threads.message_content_image_file import MessageContentImageFile\n", |
140 | | - "from openai.types.beta.threads.message_content_text import MessageContentText\n", |
| 139 | + "from openai.types.beta.threads.text_content_block import TextContentBlock\n", |
| 140 | + "from openai.types.beta.threads.image_file_content_block import ImageFileContentBlock\n", |
141 | 141 | "from openai.types.beta.threads.messages import MessageFile\n", |
142 | 142 | "from PIL import Image" |
143 | 143 | ] |
144 | 144 | }, |
| 145 | + { |
| 146 | + "cell_type": "markdown", |
| 147 | + "metadata": {}, |
| 148 | + "source": [ |
| 149 | + "### Parameters" |
| 150 | + ] |
| 151 | + }, |
| 152 | + { |
| 153 | + "cell_type": "code", |
| 154 | + "execution_count": null, |
| 155 | + "metadata": {}, |
| 156 | + "outputs": [], |
| 157 | + "source": [ |
| 158 | + "import os\n", |
| 159 | + "\n", |
| 160 | + "from dotenv import load_dotenv\n", |
| 161 | + "\n", |
| 162 | + "load_dotenv(\"../.env\") # make sure to have the .env file in the root directory of the project\n", |
| 163 | + "\n", |
| 164 | + "api_endpoint = os.getenv(\"OPENAI_URI\")\n", |
| 165 | + "api_key = os.getenv(\"OPENAI_KEY\")\n", |
| 166 | + "api_version = os.getenv(\"OPENAI_VERSION\")\n", |
| 167 | + "api_deployment_name = os.getenv(\"OPENAI_GPT_DEPLOYMENT\")\n", |
| 168 | + "\n", |
| 169 | + "should_cleanup: bool = False" |
| 170 | + ] |
| 171 | + }, |
145 | 172 | { |
146 | 173 | "cell_type": "markdown", |
147 | 174 | "metadata": {}, |
|
376 | 403 | " for message in message_list:\n", |
377 | 404 | " for item in message.content:\n", |
378 | 405 | " # Determine the content type\n", |
379 | | - " if isinstance(item, MessageContentText):\n", |
| 406 | + " if isinstance(item, TextContentBlock):\n", |
380 | 407 | " print(f\"{message.role}:\\n{item.text.value}\\n\")\n", |
381 | 408 | " file_annotations = item.text.annotations\n", |
382 | 409 | " if file_annotations:\n", |
383 | 410 | " for annotation in file_annotations:\n", |
384 | 411 | " file_id = annotation.file_path.file_id\n", |
385 | 412 | " content = read_assistant_file(file_id)\n", |
386 | 413 | " print(f\"Annotation Content:\\n{str(content)}\\n\")\n", |
387 | | - " elif isinstance(item, MessageContentImageFile):\n", |
| 414 | + " elif isinstance(item, ImageFileContentBlock):\n", |
388 | 415 | " # Retrieve image from file id \n", |
389 | 416 | " data_in_bytes = read_assistant_file(item.image_file.file_id)\n", |
390 | 417 | " # Convert bytes to image\n", |
|
539 | 566 | "name": "python", |
540 | 567 | "nbconvert_exporter": "python", |
541 | 568 | "pygments_lexer": "ipython3", |
542 | | - "version": "3.10.12" |
| 569 | + "version": "3.11.8" |
543 | 570 | } |
544 | 571 | }, |
545 | 572 | "nbformat": 4, |
|
0 commit comments