diff --git a/01-BASIC/04.UsingOpenaiAPI_GPT4o.ipynb b/01-BASIC/04.UsingOpenaiAPI_GPT4o.ipynb index 7f92e2c5..e8c099bd 100644 --- a/01-BASIC/04.UsingOpenaiAPI_GPT4o.ipynb +++ b/01-BASIC/04.UsingOpenaiAPI_GPT4o.ipynb @@ -22,7 +22,7 @@ "\n", "- [Overview](#overview)\n", "- [Environment Setup](#environment-setup)\n", - "- [ChatOpenAI GPT-4o Multimodal](#chatopenai-gpt-4o-multimodal)\n", + "- [ChatOpenAI GPT-4o Multimodal](#using-the-openai-api-gpt-4o-multimodal)\n", "- [Multimodal AI: Text and Image Processing with GPT-4o](#multimodal-ai-text-and-image-processing-with-gpt-4o)\n", "- [Configuring Multimodal AI with System and User Prompts](#configuring-multimodal-ai-with-system-and-user-prompts)\n", "\n", @@ -50,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "cbfb7682", "metadata": {}, "outputs": [], @@ -61,15 +61,7 @@ }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 2, -======= -<<<<<<< HEAD - "execution_count": 30, -======= - "execution_count": 2, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 1, "id": "f7705b37", "metadata": {}, "outputs": [], @@ -81,6 +73,7 @@ " [\n", " \"langchain\",\n", " \"langchain_openai\",\n", + " \"langchain-teddynote\"\n", " ],\n", " verbose=False,\n", " upgrade=False,\n", @@ -89,68 +82,7 @@ }, { "cell_type": "code", -<<<<<<< HEAD - "execution_count": 31, - "id": "17971dad", -======= "execution_count": 3, - "id": "cf6c239d", -<<<<<<< Updated upstream -======= ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, -<<<<<<< Updated upstream - "execution_count": 3, -======= -<<<<<<< HEAD - "execution_count": 31, -======= - "execution_count": 3, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ -<<<<<<< Updated upstream - "from dotenv import load_dotenv\n", - "\n", - "load_dotenv(override=True)\n" -======= -<<<<<<< HEAD - "# Configuration file to manage the API KEY as an global environment variable\n", - "from dotenv import load_dotenv\n", - "\n", - "# Load API KEY information\n", - "load_dotenv(override=True)" -======= - "from dotenv import load_dotenv\n", - "\n", - "load_dotenv(override=True)\n" ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes - ] - }, - { - "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 4, -======= -<<<<<<< HEAD - "execution_count": 32, -======= - "execution_count": 4, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes "id": "4454c8ed", "metadata": {}, "outputs": [ @@ -163,21 +95,13 @@ } ], "source": [ - "# Set local environment variables\n", + "# Set environment variables\n", "from langchain_opentutorial import set_env\n", "\n", "set_env(\n", " {\n", -<<<<<<< Updated upstream - " # \"OPENAI_API_KEY\": \"\",\n", - " # \"LANGCHAIN_API_KEY\": \"\",\n", -======= -<<<<<<< HEAD -======= - " # \"OPENAI_API_KEY\": \"\",\n", - " # \"LANGCHAIN_API_KEY\": \"\",\n", ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + " \"OPENAI_API_KEY\": \"\",\n", + " \"LANGCHAIN_API_KEY\": \"\",\n", " \"LANGCHAIN_TRACING_V2\": \"true\",\n", " \"LANGCHAIN_ENDPOINT\": \"https://api.smith.langchain.com\",\n", " \"LANGCHAIN_PROJECT\": \"Using-OpenAI-API\", \n", @@ -185,6 +109,31 @@ ")" ] }, + { + "cell_type": "code", + "execution_count": 2, + "id": "17971dad", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Configuration file to manage the API KEY as an environment variable\n", + "from dotenv import load_dotenv\n", + "\n", + "# Load API KEY information\n", + "load_dotenv()\n" + ] + }, { "cell_type": "markdown", "id": "6a95de64", @@ -209,7 +158,7 @@ "- `gpt-4o-mini`\n", "- `o1-preview`, `o1-preview-mini` : Available only for Tier 5 accounts, which require a minimum recharge of $1,000 to access.\n", "\n", - "![gpt-models.png](./assets/04-using-openai-api-gpt4o-get-models.png)\n", + "![gpt-models.png](./assets/gpt-models.png)\n", "\n", "- Link: https://platform.openai.com/docs/models\n", "\n" @@ -217,15 +166,7 @@ }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 5, -======= -<<<<<<< HEAD - "execution_count": 33, -======= - "execution_count": 5, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 3, "id": "c2f2222d", "metadata": {}, "outputs": [ @@ -233,19 +174,7 @@ "name": "stdout", "output_type": "stream", "text": [ -<<<<<<< HEAD -<<<<<<< Updated upstream - "[Answer]: content='The capital of South Korea is Seoul.' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': None} id='run-64bb50ae-2275-4886-88b8-d99a064b4724-0' usage_metadata={'input_tokens': 15, 'output_tokens': 9, 'total_tokens': 24, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}\n" -======= -<<<<<<< HEAD - "[Answer]: content='The capital of South Korea is Seoul.' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': None} id='run-e3a5b3a8-c086-47a1-b749-a4c1c53af7fb-0' usage_metadata={'input_tokens': 15, 'output_tokens': 9, 'total_tokens': 24, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}\n" -======= - "[Answer]: content='The capital of South Korea is Seoul.' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': None} id='run-64bb50ae-2275-4886-88b8-d99a064b4724-0' usage_metadata={'input_tokens': 15, 'output_tokens': 9, 'total_tokens': 24, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}\n" ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes -======= - "[Answer]: content='The capital of South Korea is Seoul.' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': None} id='run-969a6359-97b6-446f-b4c1-73f13abad8ef-0' usage_metadata={'input_tokens': 15, 'output_tokens': 9, 'total_tokens': 24, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}\n" ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 + "[Answer]: content='The capital of South Korea is Seoul.' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': None} id='run-c8f54250-331c-461c-ae99-4d836c5d5f4d-0' usage_metadata={'input_tokens': 15, 'output_tokens': 9, 'total_tokens': 24, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}\n" ] } ], @@ -294,15 +223,7 @@ }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 6, -======= -<<<<<<< HEAD - "execution_count": 7, -======= - "execution_count": 6, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 4, "id": "05170153", "metadata": {}, "outputs": [], @@ -316,43 +237,17 @@ }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 7, -======= -<<<<<<< HEAD - "execution_count": 8, -======= - "execution_count": 7, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 5, "id": "e22fe233", "metadata": {}, "outputs": [ { "data": { "text/plain": [ -<<<<<<< HEAD -<<<<<<< Updated upstream - "AIMessage(content='The capital of South Korea is Seoul.', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_d02d531b47', 'finish_reason': 'stop', 'logprobs': None}, id='run-6106febf-7899-407d-a17e-9019dc7110d0-0', usage_metadata={'input_tokens': 15, 'output_tokens': 9, 'total_tokens': 24, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})" -======= - "AIMessage(content='The capital of South Korea is Seoul.', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': None}, id='run-9b339231-7917-49bb-b6d1-aeaaf4629d2a-0', usage_metadata={'input_tokens': 15, 'output_tokens': 9, 'total_tokens': 24, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})" ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 + "AIMessage(content='The capital of South Korea is Seoul.', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_d02d531b47', 'finish_reason': 'stop', 'logprobs': None}, id='run-4b09d775-ad56-411e-b299-d94de39ac7aa-0', usage_metadata={'input_tokens': 15, 'output_tokens': 9, 'total_tokens': 24, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})" ] }, - "execution_count": 7, -======= -<<<<<<< HEAD - "AIMessage(content='The capital of South Korea is Seoul.', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': None}, id='run-60e949fd-4fee-4241-88e2-9438414a3797-0', usage_metadata={'input_tokens': 15, 'output_tokens': 9, 'total_tokens': 24, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})" - ] - }, - "execution_count": 8, -======= - "AIMessage(content='The capital of South Korea is Seoul.', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_d02d531b47', 'finish_reason': 'stop', 'logprobs': None}, id='run-6106febf-7899-407d-a17e-9019dc7110d0-0', usage_metadata={'input_tokens': 15, 'output_tokens': 9, 'total_tokens': 24, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})" - ] - }, - "execution_count": 7, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -363,15 +258,7 @@ }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 8, -======= -<<<<<<< HEAD - "execution_count": 9, -======= - "execution_count": 8, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 6, "id": "92bddfef", "metadata": {}, "outputs": [ @@ -415,15 +302,7 @@ }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 9, -======= -<<<<<<< HEAD - "execution_count": 10, -======= - "execution_count": 9, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 7, "id": "7ed53fa2", "metadata": {}, "outputs": [], @@ -438,15 +317,7 @@ }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 10, -======= -<<<<<<< HEAD - "execution_count": 11, -======= - "execution_count": 10, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 8, "id": "b1fe5071", "metadata": {}, "outputs": [], @@ -460,15 +331,7 @@ }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 11, -======= -<<<<<<< HEAD - "execution_count": 12, -======= - "execution_count": 11, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 9, "id": "cacd3144", "metadata": {}, "outputs": [ @@ -476,19 +339,7 @@ "name": "stdout", "output_type": "stream", "text": [ -<<<<<<< HEAD -<<<<<<< Updated upstream - "{'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': {'content': [{'token': 'The', 'bytes': [84, 104, 101], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' capital', 'bytes': [32, 99, 97, 112, 105, 116, 97, 108], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' of', 'bytes': [32, 111, 102], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' South', 'bytes': [32, 83, 111, 117, 116, 104], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' Korea', 'bytes': [32, 75, 111, 114, 101, 97], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' is', 'bytes': [32, 105, 115], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' Seoul', 'bytes': [32, 83, 101, 111, 117, 108], 'logprob': -5.550411e-05, 'top_logprobs': []}, {'token': '.', 'bytes': [46], 'logprob': -1.0280384e-06, 'top_logprobs': []}], 'refusal': None}}\n" -======= -<<<<<<< HEAD - "{'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': {'content': [{'token': 'The', 'bytes': [84, 104, 101], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' capital', 'bytes': [32, 99, 97, 112, 105, 116, 97, 108], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' of', 'bytes': [32, 111, 102], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' South', 'bytes': [32, 83, 111, 117, 116, 104], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' Korea', 'bytes': [32, 75, 111, 114, 101, 97], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' is', 'bytes': [32, 105, 115], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' Seoul', 'bytes': [32, 83, 101, 111, 117, 108], 'logprob': -5.5146502e-05, 'top_logprobs': []}, {'token': '.', 'bytes': [46], 'logprob': -7.89631e-07, 'top_logprobs': []}], 'refusal': None}}\n" -======= - "{'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': {'content': [{'token': 'The', 'bytes': [84, 104, 101], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' capital', 'bytes': [32, 99, 97, 112, 105, 116, 97, 108], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' of', 'bytes': [32, 111, 102], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' South', 'bytes': [32, 83, 111, 117, 116, 104], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' Korea', 'bytes': [32, 75, 111, 114, 101, 97], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' is', 'bytes': [32, 105, 115], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' Seoul', 'bytes': [32, 83, 101, 111, 117, 108], 'logprob': -5.550411e-05, 'top_logprobs': []}, {'token': '.', 'bytes': [46], 'logprob': -1.0280384e-06, 'top_logprobs': []}], 'refusal': None}}\n" ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes -======= - "{'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': {'content': [{'token': 'The', 'bytes': [84, 104, 101], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' capital', 'bytes': [32, 99, 97, 112, 105, 116, 97, 108], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' of', 'bytes': [32, 111, 102], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' South', 'bytes': [32, 83, 111, 117, 116, 104], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' Korea', 'bytes': [32, 75, 111, 114, 101, 97], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' is', 'bytes': [32, 105, 115], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' Seoul', 'bytes': [32, 83, 101, 111, 117, 108], 'logprob': -4.596782e-05, 'top_logprobs': []}, {'token': '.', 'bytes': [46], 'logprob': -9.0883464e-07, 'top_logprobs': []}], 'refusal': None}}\n" ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 + "{'token_usage': {'completion_tokens': 9, 'prompt_tokens': 15, 'total_tokens': 24, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_0aa8d3e20b', 'finish_reason': 'stop', 'logprobs': {'content': [{'token': 'The', 'bytes': [84, 104, 101], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' capital', 'bytes': [32, 99, 97, 112, 105, 116, 97, 108], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' of', 'bytes': [32, 111, 102], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' South', 'bytes': [32, 83, 111, 117, 116, 104], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' Korea', 'bytes': [32, 75, 111, 114, 101, 97], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' is', 'bytes': [32, 105, 115], 'logprob': 0.0, 'top_logprobs': []}, {'token': ' Seoul', 'bytes': [32, 83, 101, 111, 117, 108], 'logprob': -6.062987e-05, 'top_logprobs': []}, {'token': '.', 'bytes': [46], 'logprob': -1.0280384e-06, 'top_logprobs': []}], 'refusal': None}}\n" ] } ], @@ -511,15 +362,7 @@ }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 12, -======= -<<<<<<< HEAD - "execution_count": 13, -======= - "execution_count": 12, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 10, "id": "dea59d60", "metadata": {}, "outputs": [], @@ -530,15 +373,7 @@ }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 13, -======= -<<<<<<< HEAD - "execution_count": 14, -======= - "execution_count": 13, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 11, "id": "cab9a96f", "metadata": {}, "outputs": [ @@ -551,15 +386,11 @@ "1. **Gyeongbokgung Palace**\n", " - Address: 161 Sajik-ro, Sejongno, Jongno-gu, Seoul, South Korea\n", "\n", - "2. **Namsan Seoul Tower**\n", + "2. **Namsan Tower (N Seoul Tower)**\n", " - Address: 105 Namsangongwon-gil, Yongsan-gu, Seoul, South Korea\n", "\n", "3. **Jeju Island**\n", -<<<<<<< HEAD - " - Address: Jeju-do, South Korea (Note: Jeju Island is a large area; specific attractions can be found throughout the island)\n", -======= " - Address: Jeju Special Self-Governing Province, South Korea\n", ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 "\n", "4. **Bukchon Hanok Village**\n", " - Address: 37, Gyedong-gil, Jongno-gu, Seoul, South Korea\n", @@ -567,51 +398,22 @@ "5. **Seoraksan National Park**\n", " - Address: 1730 Seoraksan-ro, Sokcho-si, Gangwon-do, South Korea\n", "\n", -<<<<<<< Updated upstream "6. **Changdeokgung Palace and Huwon (Secret Garden)**\n", - " - Address: 99 Yulgok-ro, Waryong-dong, Jongno-gu, Seoul, South Korea\n", -======= -<<<<<<< HEAD - "6. **Changdeokgung Palace and Secret Garden**\n", " - Address: 99 Yulgok-ro, Jongno-gu, Seoul, South Korea\n", -======= - "6. **Changdeokgung Palace and Huwon (Secret Garden)**\n", - " - Address: 99 Yulgok-ro, Waryong-dong, Jongno-gu, Seoul, South Korea\n", ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes "\n", - "7. **Haeinsa Temple**\n", - " - Address: 15 Haeinsa-gil, Haeinsa-myeon, Hapcheon-gun, Gyeongsangnam-do, South Korea\n", - "\n", - "8. **Busan Haeundae Beach**\n", + "7. **Busan Haeundae Beach**\n", " - Address: Haeundae Beach, Haeundae-gu, Busan, South Korea\n", "\n", -<<<<<<< HEAD - "9. **Nami Island**\n", - " - Address: 1 Namisum-gil, Namsan-myeon, Chuncheon-si, Gangwon-do, South Korea\n", -======= "8. **Gyeongju Historic Areas**\n", -<<<<<<< HEAD - " - Address: Gyeongju, Gyeongsangbuk-do, South Korea\n", -<<<<<<< Updated upstream -======= ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes -======= " - Address: 1, Hwangnam-dong, Gyeongju-si, Gyeongsangbuk-do, South Korea\n", ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 "\n", - "10. **Incheon Songdo Central Park**\n", - " - Address: 1-1 Songdo-dong, Yeonsu-gu, Incheon, South Korea\n", + "9. **Incheon Songdo Central Park**\n", + " - Address: 1-1 Songdo-dong, Yeonsu-gu, Incheon, South Korea\n", "\n", -<<<<<<< HEAD - "These destinations showcase the rich culture, natural beauty, and modern attractions of South Korea. Enjoy your travels!" -======= "10. **Nami Island**\n", - " - Address: 1 Namiseom-gil, Namsan-myeon, Chuncheon-si, Gangwon-do, South Korea\n", + " - Address: 1 Namisum-gil, Namsan-myeon, Chuncheon-si, Gangwon-do, South Korea\n", "\n", "These destinations showcase the rich culture, history, and natural beauty of South Korea. Enjoy your travels!" ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ] } ], @@ -623,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "id": "859a276e", "metadata": {}, "outputs": [ @@ -636,67 +438,44 @@ "1. **Gyeongbokgung Palace**\n", " - Address: 161 Sajik-ro, Sejongno, Jongno-gu, Seoul, South Korea\n", "\n", - "2. **Namsan Seoul Tower**\n", + "2. **Namsan Tower (N Seoul Tower)**\n", " - Address: 105 Namsangongwon-gil, Yongsan-gu, Seoul, South Korea\n", "\n", "3. **Jeju Island**\n", - " - Address: Jeju Special Self-Governing Province, South Korea (Note: Jeju Island is a large area; specific attractions can be found within it.)\n", + " - Address: Jeju Special Self-Governing Province, South Korea\n", "\n", "4. **Bukchon Hanok Village**\n", - " - Address: 37 Gyedong-gil, Jongno-gu, Seoul, South Korea\n", + " - Address: 37, Gyedong-gil, Jongno-gu, Seoul, South Korea\n", "\n", "5. **Seoraksan National Park**\n", " - Address: 1730 Seoraksan-ro, Sokcho-si, Gangwon-do, South Korea\n", "\n", -<<<<<<< Updated upstream - "6. **Changdeokgung Palace and Huwon**\n", -======= -<<<<<<< HEAD - "6. **Changdeokgung Palace and Huwon (Secret Garden)**\n", -======= - "6. **Changdeokgung Palace and Huwon**\n", ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "6. **Changdeokgung Palace and Secret Garden**\n", " - Address: 99 Yulgok-ro, Jongno-gu, Seoul, South Korea\n", "\n", - "7. **Busan Haeundae Beach**\n", - " - Address: Haeundae Beach, Haeundae-gu, Busan, South Korea\n", + "7. **Haeinsa Temple**\n", + " - Address: 15 Haeinsa-gil, Haein-myeon, Hapcheon-gun, Gyeongsangnam-do, South Korea\n", "\n", -<<<<<<< Updated upstream -======= -<<<<<<< HEAD - "8. **Gyeongju Historic Areas**\n", -<<<<<<< HEAD - " - Address: 1 Hwangnam-dong, Gyeongju, Gyeongsangbuk-do, South Korea\n", -======= ->>>>>>> Stashed changes - "8. **Nami Island**\n", - " - Address: 1 Namisum-gil, Namsan-myeon, Chuncheon-si, Gangwon-do, South Korea\n", + "8. **Busan Haeundae Beach**\n", + " - Address: Haeundae Beach, Haeundae-gu, Busan, South Korea\n", "\n", "9. **Gyeongju Historic Areas**\n", " - Address: 1, Hwangnam-dong, Gyeongju-si, Gyeongsangbuk-do, South Korea\n", ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc -======= - " - Address: 1, Hwangnam-dong, Gyeongju-si, Gyeongsangbuk-do, South Korea (Note: Gyeongju is a city with multiple historic sites.)\n", ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 - "\n", - "9. **Incheon Songdo Central Park**\n", - " - Address: 1-1 Songdo-dong, Yeonsu-gu, Incheon, South Korea\n", "\n", - "10. **Nami Island**\n", - " - Address: 1 Namisum-gil, Namsan-myeon, Chuncheon-si, Gangwon-do, South Korea\n", + "10. **Incheon Songdo Central Park**\n", + " - Address: 1-1 Songdo-dong, Yeonsu-gu, Incheon, South Korea\n", "\n", - "These destinations showcase the rich culture, stunning landscapes, and historical significance of South Korea. Enjoy your travels!" + "These destinations showcase the rich culture, history, and natural beauty of South Korea. Enjoy your travels!" ] } ], "source": [ - "answer = llm.stream(\"Provide 10 beautiful tourist destinations in South Korea along with their addresses!\")\n", + "from langchain_teddynote.messages import stream_response\n", "\n", - "# Streaming real-time output\n", - "for token in answer:\n", - " print(token.content, end=\"\", flush=True)\n", - "\n" + "# Streaming query\n", + "# The variable `answer` receives the streaming response result.\n", + "answer = llm.stream(\"Provide 10 beautiful tourist destinations in South Korea along with their addresses!\")\n", + "stream_response(answer)\n" ] }, { @@ -713,7 +492,7 @@ "- Audio: Auditory information, such as speech, music, or sound effects.\n", "- Video: A combination of visual and auditory information, including video clips or real-time streaming.\n", "\n", - "`gpt-4o` and `gpt-4-turbo` support vision capabilities, enabling them to process and understand images alongside text inputs. In this tutorial, we’ll explore how to process images and analyze them using GPT-4o." + "`gpt-4o` and `gpt-4-turbo` are equipped with vision capabilities, enabling them to process and recognize images alongside textual inputs. " ] }, { @@ -721,117 +500,60 @@ "id": "d783c005", "metadata": {}, "source": [ - "### Step 1. Setting up ChatOpenAI\n", - "\n", - "First, create a `ChatOpenAI` object with the `gpt-4o` model and streaming capabilities enabled." + "1. Create a `ChatOpenAI` object(`llm` )." ] }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 15, -======= -<<<<<<< HEAD - "execution_count": 22, -======= - "execution_count": 15, ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes + "execution_count": 12, "id": "2c0393e7", "metadata": {}, "outputs": [], "source": [ + "from langchain_teddynote.models import MultiModal\n", + "from langchain_teddynote.messages import stream_response\n", + "\n", "# Create the ChatOpenAI object\n", "llm = ChatOpenAI(\n", - " temperature=0.1,\n", - " model_name=\"gpt-4o\",\n", - " streaming=True # Enable streaming for real-time output\n", - ")\n" + " temperature=0.1, \n", + " model_name=\"gpt-4o\", \n", + ")" ] }, { "cell_type": "markdown", - "id": "c6d8c627", + "id": "5596e60a", "metadata": {}, "source": [ - "### Step 2. Encoding Images\n", - "Images need to be encoded into **Base64** format for the model to process them. The following function handles both URL-based and local image files:" + "2. Create a `MultiModal` Object.\n", + "- The `ChatOpenAI` object (`llm` ) primarily supports text-based tasks by default.\n", + "- The `MultiModal` class extends this functionality, enabling the processing of non-text data such as image." ] }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 16, - "id": "d0cc8dd0", -======= -<<<<<<< HEAD - "execution_count": 23, + "execution_count": 13, "id": "506405fe", -======= - "execution_count": 16, - "id": "d0cc8dd0", ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes "metadata": {}, "outputs": [], "source": [ - "import requests\n", - "import base64\n", - "import mimetypes\n", - "from IPython.display import display, HTML, Image\n", - "\n", - "def encode_image(image_path_or_url):\n", - " if image_path_or_url.startswith(\"http://\") or image_path_or_url.startswith(\"https://\"):\n", - " # Download image from URL\n", - " response = requests.get(image_path_or_url)\n", - " if response.status_code == 200:\n", - " image_content = response.content\n", - " else:\n", - " raise Exception(f\"Failed to download image: {response.status_code}\")\n", - " # Guess MIME type based on URL\n", - " mime_type, _ = mimetypes.guess_type(image_path_or_url)\n", - " if mime_type is None:\n", - " mime_type = \"application/octet-stream\" # Default MIME type for unknown files\n", - " else:\n", - " # Read image from local file\n", - " try:\n", - " with open(image_path_or_url, \"rb\") as image_file:\n", - " image_content = image_file.read()\n", - " # Guess MIME type based on file extension\n", - " mime_type, _ = mimetypes.guess_type(image_path_or_url)\n", - " if mime_type is None:\n", - " mime_type = \"application/octet-stream\" # Default MIME type for unknown files\n", - " except FileNotFoundError:\n", - " raise Exception(f\"File not found: {image_path_or_url}\")\n", - "\n", - " # Base64 encode the image\n", - " return f\"data:{mime_type};base64,{base64.b64encode(image_content).decode()}\"\n" + "# Create the multimodal object\n", + "multimodal_llm = MultiModal(llm)" ] }, { "cell_type": "markdown", - "id": "368935d0", + "id": "1a41a3db", "metadata": {}, "source": [ - "**Example: Encode and Display an Image** \n", - "\n", - "* URL-based Image:" + "3. Provide an image file as input for analysis.\n", + "- The image can either be stored locally or accessed through a URL." ] }, { "cell_type": "code", -<<<<<<< Updated upstream - "execution_count": 17, - "id": "2fc34e8e", -======= -<<<<<<< HEAD - "execution_count": 25, + "execution_count": 14, "id": "5a4f1fa1", -======= - "execution_count": 17, - "id": "2fc34e8e", ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes "metadata": {}, "outputs": [ { @@ -845,357 +567,55 @@ }, "metadata": {}, "output_type": "display_data" -<<<<<<< Updated upstream -======= -<<<<<<< HEAD }, { "name": "stdout", "output_type": "stream", "text": [ - "The image is a table labeled \"TABLE 001: LOREM IPSUM DOLOR AMIS ENIMA ACCUMER TUNA.\" It contains eight rows and five columns, with the first row serving as the header. Here's a breakdown of the table:\n", - "\n", - "### Columns:\n", - "1. **First Column (No Header):** \n", - " - Contains placeholder text phrases like \"Lorem dolor siamet\" and \"Consecter odio.\"\n", - "\n", - "2. **Loremis:**\n", - " - Numerical values ranging from 5 to 8,288.\n", - "\n", - "3. **Amis terim:**\n", - " - Percentage values ranging from 2% to 123%.\n", + "The image is a table with a header labeled \"TABLE 001: LOREM IPSUM DOLOR AMIS ENIMA ACCUMER TUNA.\" It contains five columns with the following headings:\n", "\n", - "4. **Gáto lepis:**\n", - " - Contains \"YES,\" \"NO,\" or \"N/A.\"\n", + "1. **Loremis**\n", + "2. **Amis terim**\n", + "3. **Gāto lepis**\n", + "4. **Tortores**\n", "\n", - "5. **Tortores:**\n", - " - Monetary values in dollars, ranging from $89 to $999.\n", + "Each row under these headings contains various data points:\n", "\n", - "### Rows:\n", - "- Each row represents a different set of data, with the first column providing a label or category.\n", - "- The data in the columns vary, with some rows having \"N/A\" in the \"Gáto lepis\" column.\n", + "- **Loremis**: Numerical values ranging from 5 to 8,288.\n", + "- **Amis terim**: Percentage values from 2% to 123%.\n", + "- **Gāto lepis**: Text values, either \"YES,\" \"NO,\" or \"N/A.\"\n", + "- **Tortores**: Monetary values in dollars, ranging from $89 to $999.\n", "\n", - "### Additional Text:\n", - "- Below the table, there is a block of placeholder text in Latin, commonly used as filler text in design.\n", + "The rows have different labels, such as \"Lorem dolor siamet,\" \"Consecter odio,\" and others, which appear to be placeholder text (Lorem Ipsum).\n", "\n", - "This table appears to be a mock-up or template, using placeholder text and data for illustrative purposes." + "The table is visually organized with alternating row colors for clarity, and the first column is highlighted in blue. There is also a block of placeholder text at the bottom, typical of Lorem Ipsum, used to fill space in design templates." ] -======= ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes } ], "source": [ + "# Sample image URL \n", "IMAGE_URL = \"https://t3.ftcdn.net/jpg/03/77/33/96/360_F_377339633_Rtv9I77sSmSNcev8bEcnVxTHrXB4nRJ5.jpg\"\n", - "encoded_image_url = encode_image(IMAGE_URL)\n", - "display(Image(url=encoded_image_url)) # Display the image" - ] - }, - { - "cell_type": "markdown", - "id": "34f26ffa", - "metadata": {}, - "source": [ - "* Local Image:" - ] - }, - { - "cell_type": "code", -<<<<<<< HEAD -<<<<<<< Updated upstream - "execution_count": 18, -======= - "execution_count": 19, ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 - "id": "466d22d8", -======= -<<<<<<< HEAD - "execution_count": 26, - "id": "8d251172", -======= - "execution_count": 18, - "id": "466d22d8", ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\"Image\"" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "IMAGE_PATH = \"./assets/04-using-openai-api-gpt4o-sample-image.png\"\n", - "encoded_image_file = encode_image(IMAGE_PATH)\n", - "html_code = f'\"Image\"'\n", - "display(HTML(html_code)) # Display the image" - ] - }, - { - "cell_type": "markdown", - "id": "7717f61d", - "metadata": {}, - "source": [ - "### Step 3: Creating Messages\n", - "Define a function to generate the messages required for the model. This includes:\n", "\n", - "- **System Prompt**: Defines the role and task for the AI.\n", - "- **User Prompt**: Provides the specific task instructions.\n", - "- **Encoded Image**: Includes the Base64 image data." - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "id": "1d546e55", - "metadata": {}, - "outputs": [], - "source": [ - "# Function to create messages for the AI\n", - "def create_messages(encoded_image):\n", - " system_prompt = \"You are a helpful assistant on parsing images.\"\n", - " user_prompt = \"Explain the given images in-depth.\"\n", - " return [\n", - " {\"role\": \"system\", \"content\": system_prompt},\n", - " {\n", - " \"role\": \"user\",\n", - " \"content\": [\n", - " {\"type\": \"text\", \"text\": user_prompt},\n", - " {\"type\": \"image_url\", \"image_url\": {\"url\": encoded_image}},\n", - " ],\n", - " },\n", - " ]" - ] - }, - { - "cell_type": "markdown", - "id": "7771a461", - "metadata": {}, - "source": [ - "### Step 4: Model Interaction\n", - "Now, send the generated messages to the model and stream the results in real time." - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "id": "60bf1642", - "metadata": {}, - "outputs": [], - "source": [ - "def stream_response(llm, messages):\n", - " response = llm.stream(messages) # Stream AI response\n", - " print(\"Streaming response:\")\n", - " for chunk in response:\n", - " print(chunk.content, end=\"\", flush=True) # Print each response chunk in real time" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "id": "19ee60e7", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ -<<<<<<< Updated upstream - "Streaming response:\n", -<<<<<<< HEAD - "The image is a table with a header labeled \"TABLE 001: LOREM IPSUM DOLOR AMIS ENIMA ACCUMER TUNA.\" It contains five columns with the following headings:\n", - "\n", - "1. **Loremis**: Contains numerical values.\n", - "2. **Amis terim**: Contains percentages.\n", - "3. **Gāto lepis**: Contains \"YES,\" \"NO,\" or \"N/A.\"\n", - "4. **Tortores**: Contains monetary values in dollars.\n", - "\n", - "The rows are labeled with placeholder text such as \"Lorem dolor siamet,\" \"Consecter odio,\" etc. Each row contains data corresponding to the column headings.\n", - "\n", - "The table is visually divided with alternating row colors for clarity. Below the table, there is a block of placeholder text in smaller font, typical of \"Lorem ipsum\" filler text used in design to simulate content." -======= -<<<<<<< HEAD - "The image is an infographic detailing the highlights of the first OpenAI DevDay event held on November 6, 2023. It is presented by Astra Techz and includes a summary of key updates and features announced during the event.\n", - "\n", - "### Header Information:\n", - "- **Event Name:** First OpenAI DevDay Event\n", - "- **Date:** November 6, 2023\n", - "- **Key Announcements:**\n", - " - GPT 4 Turbo\n", - " - 128k Tokens\n", - " - Custom GPTs\n", - " - Assistant API\n", - " - Price Reduction\n", - "\n", - "### Source:\n", - "- A YouTube link is provided for more details: [OpenAI DevDay Event](https://www.youtube.com/watch?v=U9mjJuUkhUzk)\n", - "\n", - "### Main Updates Summarized:\n", - "1. **Token Length:** \n", - " - Increased to 128K tokens.\n", - " \n", - "2. **Custom GPTs:** \n", - " - Available as private or public options.\n", - " \n", - "3. **Multi Modal:** \n", - " - Supports images, video, and voice inputs.\n", - " \n", - "4. **JSON Mode:** \n", - " - Guaranteed functionality.\n", - " \n", - "5. **Assistant API:** \n", - " - Available for developers.\n", - " \n", - "6. **Text to Speech:** \n", - " - Beta release with 6 natural voice options.\n", - " \n", - "7. **GPT Store:** \n", - " - Revenue sharing model.\n", - " \n", - "8. **Conversation Threading:** \n", - " - Per conversation basis.\n", - " \n", - "9. **File Uploading:** \n", - " - Supports multiple files.\n", - " \n", - "10. **API Price Reduction:** \n", - " - Reduced by 2.5x to 3.5x.\n", - " \n", - "11. **Code Interpreter:** \n", - " - Built-in feature.\n", - " \n", - "12. **Function Calling:** \n", - " - Built-in feature.\n", - "\n", - "### Footer:\n", - "- The website www.astratechz.com is mentioned for building AI solutions.\n", - "\n", - "This infographic provides a concise overview of the new features and improvements introduced by OpenAI, emphasizing enhanced capabilities, developer tools, and cost efficiency." -======= - "Streaming response:\n", - "The image is a table with a header labeled \"TABLE 001: LOREM IPSUM DOLOR AMIS ENIMA ACCUMER TUNA.\" It contains five columns with the following headings:\n", - "\n", - "1. **Loremis**: Contains numerical values.\n", - "2. **Amis terim**: Contains percentages.\n", - "3. **Gāto lepis**: Contains \"YES,\" \"NO,\" or \"N/A.\"\n", - "4. **Tortores**: Contains monetary values in dollars.\n", - "\n", - "The rows are labeled with placeholder text such as \"Lorem dolor siamet,\" \"Consecter odio,\" etc. Each row contains data corresponding to the column headings.\n", - "\n", - "The table is visually divided with alternating row colors for clarity. Below the table, there is a block of placeholder text in smaller font, typical of \"Lorem ipsum\" filler text used in design to simulate content." ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes -======= - "The image is a table labeled \"TABLE 001: LOREM IPSUM DOLOR AMIS ENIMA ACCUMER TUNA.\" It contains eight rows and five columns, with the following details:\n", - "\n", - "### Columns:\n", - "1. **First Column (No Header):** Contains placeholder text phrases.\n", - "2. **Loremis:** Numerical values.\n", - "3. **Amis terim:** Percentage values.\n", - "4. **Gáto lepis:** Contains \"YES,\" \"NO,\" or \"N/A.\"\n", - "5. **Tortores:** Monetary values in dollars.\n", - "\n", - "### Rows:\n", - "1. **Lorem dolor siamet:** \n", - " - Loremis: 8,288\n", - " - Amis terim: 123%\n", - " - Gáto lepis: YES\n", - " - Tortores: $89\n", - "\n", - "2. **Consecter odio:** \n", - " - Loremis: 123\n", - " - Amis terim: 87%\n", - " - Gáto lepis: NO\n", - " - Tortores: $129\n", - "\n", - "3. **Gatoque accums:** \n", - " - Loremis: 1,005\n", - " - Amis terim: 12%\n", - " - Gáto lepis: NO\n", - " - Tortores: $199\n", - "\n", - "4. **Sed hac enim rem:** \n", - " - Loremis: 56\n", - " - Amis terim: 69%\n", - " - Gáto lepis: N/A\n", - " - Tortores: $199\n", - "\n", - "5. **Rempus tortor just:** \n", - " - Loremis: 5,554\n", - " - Amis terim: 18%\n", - " - Gáto lepis: YES\n", - " - Tortores: $999\n", - "\n", - "6. **Klimas nsecter:** \n", - " - Loremis: 455\n", - " - Amis terim: 56%\n", - " - Gáto lepis: NO\n", - " - Tortores: $245\n", - "\n", - "7. **Babiask atoque accu:** \n", - " - Loremis: 1,222\n", - " - Amis terim: 2%\n", - " - Gáto lepis: YES\n", - " - Tortores: $977\n", - "\n", - "8. **Enim rem kós:** \n", - " - Loremis: 5,002\n", - " - Amis terim: 91%\n", - " - Gáto lepis: N/A\n", - " - Tortores: $522\n", - "\n", - "### Additional Information:\n", - "- There is a block of placeholder text at the bottom, typical of \"Lorem Ipsum\" used for design purposes. \n", - "\n", - "The table appears to be a mock-up or template, likely used for design or layout purposes, with placeholder text and data." ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 - ] - } - ], - "source": [ - "# Display the image\n", - "display(Image(url=IMAGE_URL))\n", - "encoded_image_url = encode_image(IMAGE_URL)\n", + "# Query based on an image file\n", + "answer = multimodal_llm.stream(IMAGE_URL)\n", "\n", - "# Create messages and stream responses\n", - "messages_url = create_messages(encoded_image_url)\n", - "stream_response(llm, messages_url)\n", - "\n" + "\n", + "stream_response(answer) # print each token in real time" ] }, { "cell_type": "code", - "execution_count": 23, - "id": "04bb6a6e", + "execution_count": 15, + "id": "8d251172", "metadata": {}, "outputs": [ { "data": { "text/html": [ - "\"Image\"" + "" ], "text/plain": [ - "" + "" ] }, "metadata": {}, @@ -1205,67 +625,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Streaming response:\n", -<<<<<<< HEAD - "The image is an informational poster about the \"First OpenAI DevDay Event\" held on November 6, 2023. It highlights key updates and features announced during the event. Here's a detailed breakdown:\n", - "\n", - "### Event Details:\n", - "- **Date:** November 6, 2023\n", - "- **Key Announcements:**\n", - " - GPT 4 Turbo\n", - " - 128k Tokens\n", - " - Custom GPTs\n", - " - Assistant API\n", - " - Price Reduction\n", - "\n", - "### Main Updates Summarized:\n", - "1. **Token Length:**\n", - " - Increased to 128K tokens.\n", - "\n", - "2. **Custom GPTs:**\n", - " - Options for private or public customization.\n", - "\n", - "3. **Multi Modal:**\n", - " - Supports image, video, and voice inputs.\n", - "\n", - "4. **JSON Mode:**\n", - " - Guaranteed support for JSON format.\n", - "\n", - "5. **Assistant API:**\n", - " - Available for developers.\n", - "\n", - "6. **Text to Speech:**\n", - " - Beta release with this feature.\n", - "\n", - "7. **Natural Voice Options:**\n", - " - Six different voices available.\n", - "\n", - "8. **GPT Store:**\n", - " - Revenue sharing model introduced.\n", - "\n", - "9. **Conversation Threading:**\n", - " - Managed per conversation.\n", - "\n", - "10. **File Uploading:**\n", - " - Supports multiple file uploads.\n", - "\n", - "11. **API Price Reduction:**\n", - " - Prices reduced by 2.5x to 3.5x.\n", - "\n", - "12. **Code Interpreter:**\n", - " - Built-in feature.\n", - "\n", - "13. **Function Calling:**\n", - " - Built-in feature.\n", - "\n", - "### Additional Information:\n", - "- The poster includes a logo for \"Astra Techz\" with the tagline \"Simplifying Technology.\"\n", - "- A source link to the event video is provided.\n", - "- The website www.astratechz.com is mentioned for building AI solutions.\n", - "\n", - "This poster serves as a concise summary of the new features and improvements introduced at the OpenAI DevDay event." -======= - "The image is an announcement poster for the \"First OpenAI DevDay Event\" scheduled for November 6, 2023. It highlights several key updates and features related to OpenAI's offerings. Here's a detailed breakdown:\n", + "The image is an infographic summarizing the key updates from the \"First OpenAI DevDay Event\" held on November 6, 2023. It highlights several new features and improvements related to OpenAI's offerings. Here's a detailed breakdown:\n", "\n", "### Event Details\n", "- **Title:** First OpenAI DevDay Event\n", @@ -1280,39 +640,38 @@ "- **Price Reduction:** Lower costs for using OpenAI services.\n", "\n", "### Main Updates Summarized\n", - "- **Token Length:** Increased to 128K.\n", - "- **Custom GPTs:** Available as private or public.\n", - "- **Multi Modal:** Supports image, video, and voice inputs.\n", - "- **JSON Mode:** Guaranteed support for JSON.\n", - "- **Assistant API:** Available for developers.\n", - "- **Text to Speech:** Beta release with 6 natural voice options.\n", - "- **GPT Store:** Revenue sharing model.\n", - "- **Conversation Threading:** Managed per conversation.\n", - "- **File Uploading:** Supports multiple files.\n", - "- **API Price Reduction:** Costs reduced by 2.5x to 3.5x.\n", - "- **Code Interpreter:** Built-in feature.\n", - "- **Function Calling:** Built-in capability.\n", + "1. **Token Length:** Increased to 128K.\n", + "2. **Custom GPTs:** Available as private or public models.\n", + "3. **Multi Modal:** Supports image, video, and voice inputs.\n", + "4. **JSON Mode:** Guaranteed support for JSON format.\n", + "5. **Assistant API:** Available for developers.\n", + "6. **Text to Speech:** Beta release with 6 natural voice options.\n", + "7. **Natural Voice Options:** Six different voices available.\n", + "8. **GPT Store:** Revenue-sharing model.\n", + "9. **Conversation Threading:** Managed per conversation.\n", + "10. **File Uploading:** Supports multiple file uploads.\n", + "11. **API Price Reduction:** Costs reduced by 2.5x to 3.5x.\n", + "12. **Code Interpreter:** Built-in feature.\n", + "13. **Function Calling:** Built-in capability.\n", "\n", "### Branding and Contact\n", "- **Company:** Astra Techz\n", - "- **Slogan:** \"Simplifying Technology\"\n", + "- **Tagline:** Simplifying Technology\n", "- **Website:** www.astratechz.com\n", "\n", - "The poster is designed to inform developers and interested parties about the latest advancements and opportunities with OpenAI's technology, emphasizing new features, improvements, and cost benefits." ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 + "This infographic provides a concise overview of the latest advancements and features introduced by OpenAI, aimed at enhancing user experience and developer capabilities." ] } ], "source": [ - "# 1. Encoding image\n", - "IMAGE_PATH = \"./assets/04-using-openai-api-gpt4o-sample-image.png\"\n", - "encoded_image_file = encode_image(IMAGE_PATH)\n", - "html_code = f'\"Image\"'\n", - "display(HTML(html_code))\n", + "# Input the path to an image stored locally on the PC\n", + "IMAGE_PATH_FROM_FILE = \"./assets/sample-image.png\"\n", "\n", - "# 2. Create messages and stream responses\n", - "messages_file = create_messages(encoded_image_file)\n", - "stream_response(llm, messages_file)" + "# Query based on the image file (streaming mode)\n", + "answer = multimodal_llm.stream(IMAGE_PATH_FROM_FILE)\n", + "\n", + "# Stream and print each token in real time\n", + "stream_response(answer)\n" ] }, { @@ -1321,112 +680,28 @@ "metadata": {}, "source": [ "## Configuring Multimodal AI with System and User Prompts\n", - "This tutorial demonstrates how to configure a multimodal AI using **system prompts** and **user prompts**, and how to process and interpret an image-based financial table.\n", - "\n", - "\n", - "### What Are Prompts? \n", + "In the `MultiModal` class, the `system_prompt` and `user_prompt` play crucial roles in defining how the AI operates and interacts with input data:\n", "\n", - "**System Prompt**\n", - "Defines the AI's identity, responsibilities, and behavior for the session:\n", + "- `system_prompt`: define the AI's identity, responsibilities, and behavior.\n", + " - It establishes the overarching context for the AI, ensuring that its responses align with the intended purpose throughout the session.\n", + "- `user_prompt`: delivers **task-specific directions** to guide the AI on how to process the given input.\n", + " - It acts as a direct instruction for the current task, specifying what the user expects from the AI.\n", "\n", - "* Sets the AI's context, ensuring consistent responses.\n", - "* Example: \"You are a financial assistant specializing in interpreting tables.\"\n", - "\n", - "**User Prompt**\n", - "Gives task-specific instructions to guide the AI:\n", - "\n", - "* Specifies what the user expects the AI to do.\n", - "* Example: \"Analyze this financial table and summarize the insights.\"" + "Together, these prompts enable the `MultiModal` object to function effectively, balancing general behavior with specific task execution. " ] }, { "cell_type": "markdown", - "id": "a04f0fc5", + "id": "f5936926", "metadata": {}, "source": [ - "### Step 1: Set Up the ChatOpenAI Object\n", - "The `ChatOpenAI` object initializes the model with the desired configurations, such as temperature and model type." + "1. Initialize a `MultiModal` object with a predefined `system_prompt` and a `user_prompt` for analyzing and summarizing financial tables." ] }, { "cell_type": "code", -<<<<<<< HEAD -<<<<<<< Updated upstream -======= -<<<<<<< HEAD - "execution_count": 27, + "execution_count": 19, "id": "97b6dd22", -======= ->>>>>>> Stashed changes - "execution_count": 23, -======= - "execution_count": 24, ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 - "id": "16f2b785", - "metadata": {}, - "outputs": [], - "source": [ - "# Create the ChatOpenAI object\n", - "llm = ChatOpenAI(\n", - " temperature=0.1, \n", - " model_name=\"gpt-4o\", \n", - " streaming=True\n", - ")" - ] - }, - { - "cell_type": "markdown", - "id": "ca729b02", - "metadata": {}, - "source": [ - "### Step2: Encode and Display the Image\n", - "Images need to be encoded into Base64 format so the AI can process them. " - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "id": "8e13521f", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "\n", - "IMAGE_URL = \"https://media.wallstreetprep.com/uploads/2022/05/24100154/NVIDIA-Income-Statement.jpg?_gl=1*zqx63z*_gcl_au*MTI3Njg2MTE3Mi4xNzM1NDg1OTky*_ga*Mjg1MjY3NTAzLjE3MzU0ODU5OTI.*_ga_0X18K5P59L*MTczNTQ4NTk5MS4xLjAuMTczNTQ4NTk5MS42MC4wLjE1OTkyODA0MTI.\"\n", - "\n", - "encoded_image_url = encode_image(IMAGE_URL) \n", - "display(Image(url=encoded_image_url)) # Display the original image." - ] - }, - { - "cell_type": "markdown", - "id": "aa85bca0", - "metadata": {}, - "source": [ - "### Step 3: Define System and User Prompts\n", - "Set up the prompts to guide the AI’s behavior and task execution.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "id": "6103da56", -<<<<<<< Updated upstream -======= ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc ->>>>>>> Stashed changes "metadata": {}, "outputs": [], "source": [ @@ -1435,122 +710,35 @@ "Your mission is to analyze the provided table-format financial statements and summarize interesting insights in a friendly and clear manner.\"\"\"\n", "\n", "# User prompt: Provide instructions for the task\n", - "user_prompt = \"\"\"The table provided to you represents a company's financial statements. Summarize the interesting insights from the table.\"\"\"" - ] - }, - { - "cell_type": "markdown", - "id": "ea883163", - "metadata": {}, - "source": [ - "### Step 4: Create Messages for the AI\n", - "Combine the system prompt, user prompt, and the encoded image into a structured message format." - ] - }, - { - "cell_type": "code", -<<<<<<< HEAD -<<<<<<< Updated upstream - "execution_count": 26, -======= - "execution_count": 27, ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 - "id": "d41b29b0", - "metadata": {}, - "outputs": [], - "source": [ - "messages = [\n", - " {\"role\": \"system\", \"content\": system_prompt},\n", - " {\n", - " \"role\": \"user\",\n", - " \"content\": [\n", - " {\"type\": \"text\", \"text\": user_prompt},\n", - " {\"type\": \"image_url\", \"image_url\": {\"url\": encoded_image_url}},\n", - " ],\n", - " },\n", - "]" + "user_prompt = \"\"\"The table provided to you represents a company's financial statements. Summarize the interesting insights from the table.\"\"\"\n", + "\n", + "\n", + "# Create the multimodal object with prompts\n", + "multimodal_llm_with_prompt = MultiModal(\n", + " llm, \n", + " system_prompt=system_prompt, \n", + " user_prompt=user_prompt \n", + ")" ] }, { "cell_type": "markdown", - "id": "317bb189", + "id": "a20f6814", "metadata": {}, "source": [ - "### Step 5: Stream the AI's Response\n", - "Use the AI model to process the messages and stream the results in real time." + "2. Process an image of a financial statemen using the `MultiModal`, displaying the response token-by-token in real time." ] }, { "cell_type": "code", - "execution_count": 28, - "id": "6b6dfa6a", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Streaming response:\n", - "Here are some interesting insights from NVIDIA's financial statements:\n", - "\n", -<<<<<<< HEAD - "1. **Revenue Growth**: \n", - " - Revenue has shown significant growth over the three years, increasing from $10,918 million in 2020 to $26,914 million in 2022. This indicates strong business expansion.\n", - "\n", - "2. **Gross Profit**:\n", - " - Gross profit has also increased substantially, from $6,768 million in 2020 to $17,475 million in 2022, reflecting efficient cost management and increased sales.\n", - "\n", - "3. **Operating Expenses**:\n", - " - Operating expenses have risen, particularly in research and development, which increased from $2,829 million in 2020 to $5,268 million in 2022. This suggests a focus on innovation and product development.\n", - "\n", - "4. **Net Income**:\n", - " - Net income has more than tripled from $2,796 million in 2020 to $9,752 million in 2022, indicating improved profitability.\n", - "\n", - "5. **Net Income Per Share**:\n", - " - Basic net income per share increased from $1.15 in 2020 to $3.91 in 2022, showing enhanced shareholder value.\n", - "\n", - "6. **Income Tax Expense**:\n", - " - The income tax expense increased significantly in 2022 to $189 million, up from $77 million in 2021, which aligns with the higher income before tax.\n", - "\n", - "Overall, NVIDIA has demonstrated strong financial performance with substantial growth in revenue, profitability, and investment in research and development." -======= - "1. **Revenue Growth**: The company has shown significant revenue growth over the three years. Revenue increased from $10,918 million in 2020 to $26,914 million in 2022, more than doubling in this period.\n", - "\n", - "2. **Gross Profit Increase**: Gross profit also saw a substantial rise, from $6,768 million in 2020 to $17,475 million in 2022. This indicates effective management of cost of revenue, which increased at a slower rate than revenue.\n", - "\n", - "3. **Operating Expenses**: Operating expenses have increased, particularly in research and development, which rose from $2,829 million in 2020 to $5,268 million in 2022. This suggests a strong focus on innovation and product development.\n", - "\n", - "4. **Net Income Surge**: Net income has more than tripled from $2,796 million in 2020 to $9,752 million in 2022, reflecting improved profitability.\n", - "\n", - "5. **Earnings Per Share (EPS)**: Both basic and diluted EPS have increased significantly. Basic EPS rose from $1.15 in 2020 to $3.91 in 2022, indicating strong earnings growth per share.\n", - "\n", - "6. **Interest and Other Income**: Interest income decreased over the years, while interest expense increased slightly. Other income (expense), net, showed fluctuations, with a notable expense in 2021.\n", - "\n", - "Overall, NVIDIA has demonstrated strong financial performance with impressive growth in revenue, gross profit, and net income, alongside strategic investments in research and development." ->>>>>>> 8dd161fa7887f51084c335ac9f7a63b4a653aae4 - ] - } - ], - "source": [ - "def stream_response(llm, messages):\n", - " response = llm.stream(messages) # Stream AI response\n", - " print(\"Streaming response:\")\n", - " for chunk in response:\n", - " print(chunk.content, end=\"\", flush=True) # Print each response chunk in real time\n", - "\n", - "# Execute streaming\n", - "stream_response(llm, messages)\n" - ] -======= -<<<<<<< HEAD - "execution_count": 28, + "execution_count": 20, "id": "5640b8ec", "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -1563,95 +751,42 @@ "name": "stdout", "output_type": "stream", "text": [ - "Here's a summary of the key insights from the financial statements:\n", + "Here's a summary of the financial insights from the table:\n", "\n", - "1. **Revenue Growth**: The company experienced significant revenue growth over the three years. Revenue increased from $10,918 million in 2020 to $26,914 million in 2022, indicating strong business expansion.\n", + "1. **Revenue Growth**: The company has shown significant revenue growth over the three years. Revenue increased from $10,918 million in 2020 to $26,914 million in 2022, indicating strong business expansion.\n", "\n", - "2. **Gross Profit Increase**: Gross profit also saw a substantial rise, from $6,768 million in 2020 to $17,475 million in 2022. This suggests improved efficiency or higher sales margins.\n", + "2. **Gross Profit Increase**: Gross profit has also increased substantially, from $6,768 million in 2020 to $17,475 million in 2022. This suggests improved efficiency or higher sales margins.\n", "\n", - "3. **Operating Expenses**: Operating expenses increased from $3,922 million in 2020 to $7,434 million in 2022. The largest component was research and development, which grew from $2,829 million to $5,268 million, highlighting a focus on innovation.\n", + "3. **Operating Expenses**: Operating expenses have risen, particularly in research and development, which increased from $2,829 million in 2020 to $5,268 million in 2022. This indicates a focus on innovation and product development.\n", "\n", - "4. **Net Income Surge**: Net income more than tripled from $2,796 million in 2020 to $9,752 million in 2022, reflecting strong overall financial performance.\n", + "4. **Net Income Growth**: Net income has more than tripled from $2,796 million in 2020 to $9,752 million in 2022, reflecting strong profitability.\n", "\n", - "5. **Earnings Per Share (EPS)**: Both basic and diluted EPS increased significantly. Basic EPS rose from $1.15 in 2020 to $3.91 in 2022, while diluted EPS increased from $1.13 to $3.85, indicating higher returns for shareholders.\n", -======= - "execution_count": 26, - "id": "d41b29b0", - "metadata": {}, - "outputs": [], - "source": [ - "messages = [\n", - " {\"role\": \"system\", \"content\": system_prompt},\n", - " {\n", - " \"role\": \"user\",\n", - " \"content\": [\n", - " {\"type\": \"text\", \"text\": user_prompt},\n", - " {\"type\": \"image_url\", \"image_url\": {\"url\": encoded_image_url}},\n", - " ],\n", - " },\n", - "]" - ] - }, - { - "cell_type": "markdown", - "id": "317bb189", - "metadata": {}, - "source": [ - "### Step 5: Stream the AI's Response\n", - "Use the AI model to process the messages and stream the results in real time." - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "id": "6b6dfa6a", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Streaming response:\n", - "Here are some interesting insights from NVIDIA's financial statements:\n", - "\n", - "1. **Revenue Growth**: \n", - " - Revenue has shown significant growth over the three years, increasing from $10,918 million in 2020 to $26,914 million in 2022. This indicates strong business expansion.\n", - "\n", - "2. **Gross Profit**:\n", - " - Gross profit has also increased substantially, from $6,768 million in 2020 to $17,475 million in 2022, reflecting efficient cost management and increased sales.\n", - "\n", - "3. **Operating Expenses**:\n", - " - Operating expenses have risen, particularly in research and development, which increased from $2,829 million in 2020 to $5,268 million in 2022. This suggests a focus on innovation and product development.\n", - "\n", - "4. **Net Income**:\n", - " - Net income has more than tripled from $2,796 million in 2020 to $9,752 million in 2022, indicating improved profitability.\n", - "\n", - "5. **Net Income Per Share**:\n", - " - Basic net income per share increased from $1.15 in 2020 to $3.91 in 2022, showing enhanced shareholder value.\n", ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc + "5. **Earnings Per Share (EPS)**: Both basic and diluted EPS have increased significantly. Basic EPS rose from $1.15 in 2020 to $3.91 in 2022, and diluted EPS from $1.13 to $3.85, indicating higher returns for shareholders.\n", "\n", - "6. **Income Tax Expense**:\n", - " - The income tax expense increased significantly in 2022 to $189 million, up from $77 million in 2021, which aligns with the higher income before tax.\n", + "6. **Income Tax Expense**: The income tax expense increased from $174 million in 2020 to $189 million in 2022, which is consistent with the rise in income before tax.\n", "\n", -<<<<<<< HEAD - "Overall, the company demonstrated robust growth in revenue, profitability, and shareholder returns over the three-year period." -======= - "Overall, NVIDIA has demonstrated strong financial performance with substantial growth in revenue, profitability, and investment in research and development." ->>>>>>> f0f4d8b6d3a5cd6a7c69ff85f393674513d757cc + "Overall, the company has demonstrated robust financial performance with strong growth in revenue, profitability, and investment in research and development." ] } ], "source": [ - "def stream_response(llm, messages):\n", - " response = llm.stream(messages) # Stream AI response\n", - " print(\"Streaming response:\")\n", - " for chunk in response:\n", - " print(chunk.content, end=\"\", flush=True) # Print each response chunk in real time\n", + "# Input the path to an image stored locally on the PC\n", + "IMAGE_PATH_FROM_FILE = \"https://media.wallstreetprep.com/uploads/2022/05/24100154/NVIDIA-Income-Statement.jpg?_gl=1*zqx63z*_gcl_au*MTI3Njg2MTE3Mi4xNzM1NDg1OTky*_ga*Mjg1MjY3NTAzLjE3MzU0ODU5OTI.*_ga_0X18K5P59L*MTczNTQ4NTk5MS4xLjAuMTczNTQ4NTk5MS42MC4wLjE1OTkyODA0MTI.\"\n", "\n", - "# Execute streaming\n", - "stream_response(llm, messages)\n" + "# Query based on the image file (streaming mode)\n", + "answer = multimodal_llm_with_prompt.stream(IMAGE_PATH_FROM_FILE)\n", + "\n", + "# Stream and print each token in real time\n", + "stream_response(answer)" ] ->>>>>>> Stashed changes + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d37b2759", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -1670,7 +805,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.11.11" } }, "nbformat": 4,