diff --git a/GPT35-Instruct/azure.env b/GPT35-Instruct/azure.env new file mode 100644 index 0000000..1d22e69 --- /dev/null +++ b/GPT35-Instruct/azure.env @@ -0,0 +1,4 @@ +# Azure Open AI +OPENAI_API_BASE = "tobereplaced" +OPENAI_API_KEY = "tobereplaced" +OPENAI_API_VERSION = "2023-05-15" diff --git a/GPT35-Instruct/gpt-35-turbo-instruct.ipynb b/GPT35-Instruct/gpt-35-turbo-instruct.ipynb new file mode 100644 index 0000000..db83f6b --- /dev/null +++ b/GPT35-Instruct/gpt-35-turbo-instruct.ipynb @@ -0,0 +1,388 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "9b943d93", + "metadata": {}, + "source": [ + "# gpt-35 turbo instruct model with Azure Open AI\n", + "\n", + "- OpenAI introduces \"gpt-3.5-turbo-instruct\", a new instruction language model that is as efficient as the chat-optimized GPT-3.5 Turbo. \n", + "- The new model replaces several previous Instruct models and language models that will be retired in January 2024. The model's training data is current as of September 2021." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "7b405ab5", + "metadata": {}, + "outputs": [], + "source": [ + "import datetime\n", + "import os\n", + "import openai\n", + "import sys\n", + "\n", + "from dotenv import load_dotenv" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b9b8b4c8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Open AI version: 0.28.1\n" + ] + } + ], + "source": [ + "load_dotenv(\"azure.env\")\n", + "\n", + "# Azure Open AI\n", + "openai.api_type: str = \"azure\"\n", + "openai.api_key = os.getenv(\"OPENAI_API_KEY\")\n", + "openai.api_base = os.getenv(\"OPENAI_API_BASE\")\n", + "openai.api_version = \"2023-09-15-preview\"\n", + "\n", + "print(\"Open AI version:\", openai.__version__)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "5c7f27a6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Today is: 12-Oct-2023 15:01:38\n" + ] + } + ], + "source": [ + "print(\"Today is:\", datetime.datetime.today().strftime(\"%d-%b-%Y %H:%M:%S\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "64d21e4b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3.10.10 (main, Mar 21 2023, 18:45:11) [GCC 11.2.0]'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sys.version" + ] + }, + { + "cell_type": "markdown", + "id": "283a29c5", + "metadata": {}, + "source": [ + "## Completion example" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "fa4cdafd", + "metadata": {}, + "outputs": [], + "source": [ + "model = \"gpt-35-turbo-instruct\"" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "68a5ce60", + "metadata": {}, + "outputs": [], + "source": [ + "def gpt35instruct(prompt):\n", + " \"\"\"\n", + " GPT35 Instructs\n", + " \"\"\"\n", + " response = openai.Completion.create(\n", + " engine=model,\n", + " prompt=prompt,\n", + " temperature=0.8,\n", + " max_tokens=1000,\n", + " top_p=1,\n", + " frequency_penalty=0,\n", + " presence_penalty=0,\n", + " best_of=1,\n", + " stop=None,\n", + " )\n", + "\n", + " return response" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "b82939ab", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Write a story about AI in 2050 in 50 lines\n", + "\n", + "{\n", + " \"id\": \"cmpl-88rTyH7B8pAUDkK5F0C1waapiQZ6Z\",\n", + " \"object\": \"text_completion\",\n", + " \"created\": 1697122902,\n", + " \"model\": \"gpt-35-turbo-instruct\",\n", + " \"prompt_filter_results\": [\n", + " {\n", + " \"prompt_index\": 0,\n", + " \"content_filter_results\": {\n", + " \"hate\": {\n", + " \"filtered\": false,\n", + " \"severity\": \"safe\"\n", + " },\n", + " \"self_harm\": {\n", + " \"filtered\": false,\n", + " \"severity\": \"safe\"\n", + " },\n", + " \"sexual\": {\n", + " \"filtered\": false,\n", + " \"severity\": \"safe\"\n", + " },\n", + " \"violence\": {\n", + " \"filtered\": false,\n", + " \"severity\": \"safe\"\n", + " }\n", + " }\n", + " }\n", + " ],\n", + " \"choices\": [\n", + " {\n", + " \"text\": \"\\n\\nIn the year 2050, artificial intelligence had become an integral part of everyday life. It had advanced far beyond what anyone could have ever imagined. AI now had the ability to think, learn, and adapt on its own, making life easier and more convenient for humans.\\n\\nOne of the most significant changes brought about by AI was in the field of medicine. With the help of advanced algorithms and data analysis, AI could accurately diagnose diseases and develop personalized treatment plans for patients. It had significantly reduced the error rate in diagnoses and improved the overall healthcare system.\\n\\nIn the education sector, AI had revolutionized the way students learned. Virtual and augmented reality technology allowed students to experience hands-on learning like never before. AI-powered tutors were also available to assist and guide students through their studies. This had led to a significant increase in academic success rates.\\n\\nThe transportation industry had also been transformed by AI. Self-driving cars and drones were now the primary modes of transportation. They were equipped with advanced sensors and algorithms that made them safer and more efficient than human drivers. Traffic congestion and accidents were almost non-existent, and the environment had significantly benefited from reduced carbon emissions.\\n\\nAs AI continued to evolve, it became an essential part of the workforce. Many jobs that were previously done by humans were now automated, leading to a decrease in unemployment rates. However, this also brought about ethical concerns and debates about the role of AI in society.\\n\\nOne of the most significant developments in AI was the creation of humanoid robots. These robots had human-like features and abilities, and they were used for various tasks, from household chores to dangerous missions that were too risky for humans. Some people even formed emotional attachments to these robots, considering them as companions.\\n\\nHowever, not everyone was happy with the rapid advancement of AI. There were fears of AI becoming more intelligent than humans and taking over the world. To prevent this, strict regulations and guidelines were put in place to ensure that AI remained under human control.\\n\\nDespite the controversies, AI continued to progress, and soon, it became a part of every household. Smart homes were now the norm, with AI-powered assistants managing daily tasks and providing personalized services to each family member.\\n\\nIn the workplace, AI had become a valuable asset for businesses. It could process data and make decisions at lightning speed, leading to increased productivity and profitability. However, some people feared that AI would replace human workers, making them obsolete.\\n\\nThe entertainment industry had also been transformed by AI. Virtual reality games and movies allowed people to immerse themselves in a whole new world, while AI-powered characters in movies and TV shows were indistinguishable from real actors.\\n\\nAI had also played a significant role in disaster management. With its ability to analyze data and predict outcomes, it had helped in preventing and responding to natural disasters. It had also assisted in search and rescue missions, saving countless lives.\\n\\nAs AI continued to evolve, it had also become more integrated with human brains. Brain-computer interfaces were now a reality, allowing people to control machines with their thoughts. This had opened up a whole new world of possibilities, from medical treatments to enhancing human abilities.\\n\\nBut with the rise of AI came the threat of hacking and cyber attacks. AI systems were vulnerable to malicious attacks, and this posed a significant risk to society. To combat this, AI developers worked tirelessly to create more secure systems.\\n\\nIn the year 2050, AI had become an essential part of society. It had brought about significant advancements in every aspect of life, making it easier, safer, and more efficient. However, it also raised important questions about the role of AI in society and the future of humanity. As AI continued to evolve, one thing was certain: it would continue to shape the world in ways we could never have imagined. \",\n", + " \"index\": 0,\n", + " \"finish_reason\": \"stop\",\n", + " \"logprobs\": null,\n", + " \"content_filter_results\": {\n", + " \"hate\": {\n", + " \"filtered\": false,\n", + " \"severity\": \"safe\"\n", + " },\n", + " \"self_harm\": {\n", + " \"filtered\": false,\n", + " \"severity\": \"safe\"\n", + " },\n", + " \"sexual\": {\n", + " \"filtered\": false,\n", + " \"severity\": \"safe\"\n", + " },\n", + " \"violence\": {\n", + " \"filtered\": false,\n", + " \"severity\": \"safe\"\n", + " }\n", + " }\n", + " }\n", + " ],\n", + " \"usage\": {\n", + " \"completion_tokens\": 758,\n", + " \"prompt_tokens\": 13,\n", + " \"total_tokens\": 771\n", + " }\n", + "}\n", + "\n" + ] + } + ], + "source": [ + "prompt = \"Write a story about AI in 2050 in 50 lines\"\n", + "\n", + "print(prompt)\n", + "print()\n", + "response = gpt35instruct(prompt)\n", + "print(response)\n", + "print()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "f4509ee8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "In the year 2050, artificial intelligence had become an integral part of everyday life. It had advanced far beyond what anyone could have ever imagined. AI now had the ability to think, learn, and adapt on its own, making life easier and more convenient for humans.\n", + "\n", + "One of the most significant changes brought about by AI was in the field of medicine. With the help of advanced algorithms and data analysis, AI could accurately diagnose diseases and develop personalized treatment plans for patients. It had significantly reduced the error rate in diagnoses and improved the overall healthcare system.\n", + "\n", + "In the education sector, AI had revolutionized the way students learned. Virtual and augmented reality technology allowed students to experience hands-on learning like never before. AI-powered tutors were also available to assist and guide students through their studies. This had led to a significant increase in academic success rates.\n", + "\n", + "The transportation industry had also been transformed by AI. Self-driving cars and drones were now the primary modes of transportation. They were equipped with advanced sensors and algorithms that made them safer and more efficient than human drivers. Traffic congestion and accidents were almost non-existent, and the environment had significantly benefited from reduced carbon emissions.\n", + "\n", + "As AI continued to evolve, it became an essential part of the workforce. Many jobs that were previously done by humans were now automated, leading to a decrease in unemployment rates. However, this also brought about ethical concerns and debates about the role of AI in society.\n", + "\n", + "One of the most significant developments in AI was the creation of humanoid robots. These robots had human-like features and abilities, and they were used for various tasks, from household chores to dangerous missions that were too risky for humans. Some people even formed emotional attachments to these robots, considering them as companions.\n", + "\n", + "However, not everyone was happy with the rapid advancement of AI. There were fears of AI becoming more intelligent than humans and taking over the world. To prevent this, strict regulations and guidelines were put in place to ensure that AI remained under human control.\n", + "\n", + "Despite the controversies, AI continued to progress, and soon, it became a part of every household. Smart homes were now the norm, with AI-powered assistants managing daily tasks and providing personalized services to each family member.\n", + "\n", + "In the workplace, AI had become a valuable asset for businesses. It could process data and make decisions at lightning speed, leading to increased productivity and profitability. However, some people feared that AI would replace human workers, making them obsolete.\n", + "\n", + "The entertainment industry had also been transformed by AI. Virtual reality games and movies allowed people to immerse themselves in a whole new world, while AI-powered characters in movies and TV shows were indistinguishable from real actors.\n", + "\n", + "AI had also played a significant role in disaster management. With its ability to analyze data and predict outcomes, it had helped in preventing and responding to natural disasters. It had also assisted in search and rescue missions, saving countless lives.\n", + "\n", + "As AI continued to evolve, it had also become more integrated with human brains. Brain-computer interfaces were now a reality, allowing people to control machines with their thoughts. This had opened up a whole new world of possibilities, from medical treatments to enhancing human abilities.\n", + "\n", + "But with the rise of AI came the threat of hacking and cyber attacks. AI systems were vulnerable to malicious attacks, and this posed a significant risk to society. To combat this, AI developers worked tirelessly to create more secure systems.\n", + "\n", + "In the year 2050, AI had become an essential part of society. It had brought about significant advancements in every aspect of life, making it easier, safer, and more efficient. However, it also raised important questions about the role of AI in society and the future of humanity. As AI continued to evolve, one thing was certain: it would continue to shape the world in ways we could never have imagined. \n" + ] + } + ], + "source": [ + "print(response[\"choices\"][0][\"text\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "cd17e85b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "En l'an 2050, l'intelligence artificielle était devenue une partie intégrante de la vie quotidienne. Elle avait progressé bien au-delà de ce que quiconque aurait pu imaginer. L'IA avait désormais la capacité de penser, d'apprendre et de s'adapter par elle-même, rendant la vie plus facile et plus pratique pour les humains.\n", + "\n", + "L'un des changements les plus significatifs apportés par l'IA était dans le domaine de la médecine. Avec l'aide d'algorithmes avancés et d'analyses de données, l'IA pouvait diagnostiquer avec précision des maladies et élaborer des plans de traitement personnalisés pour les patients. Elle avait considérablement réduit le taux d'erreur dans les diagnostics et amélioré le système de santé dans son ensemble.\n", + "\n", + "Dans le secteur de l'éducation, l'IA avait révolutionné la façon dont les étudiants apprenaient. Les technologies de réalité virtuelle et augmentée permettaient aux étudiants de vivre une expérience d'apprentissage pratique comme jamais auparavant. Des tuteurs alimentés par l'IA étaient également disponibles pour aider et guider les étudiants dans leurs études. Cela avait entraîné une augmentation significative du taux de réussite scolaire.\n", + "\n", + "L'industrie des transports avait également été transformée par l'IA. Les voitures autonomes et les drones étaient désormais les principaux modes de transport. Ils étaient équipés de capteurs et d'algorithmes avancés qui les rendaient plus sûrs et plus efficaces que les conducteurs humains. La congestion du trafic et les accidents étaient presque inexistants, et l'environnement avait considérablement bénéficié de la réduction des émissions de carbone.\n", + "\n", + "À mesure que l'IA continuait d'évoluer, elle devenait une partie essentielle de la main-d'œuvre. De nombreux emplois qui étaient auparavant effectués par des humains étaient désormais automatisés, entraînant une baisse du taux de chômage. Cependant, cela a également suscité des préoccupations éthiques et des débats sur le rôle de l'IA dans la société.\n", + "\n", + "L'un des développements les plus importants de l'IA a été la création de robots humanoïdes. Ces robots avaient des caractéristiques et des capacités similaires à celles des humains, et ils étaient utilisés pour différentes tâches, allant des tâches ménagères aux missions dangereuses trop risquées pour les humains. Certaines personnes se sont même attachées émotionnellement à ces robots, les considérant comme des compagnons.\n", + "\n", + "Cependant, tout le monde n'était pas satisfait de l'avancement rapide de l'IA. Il y avait des craintes que l'IA devienne plus intelligente que les humains et prenne le contrôle du monde. Pour éviter cela, des règlements et des lignes directrices stricts ont été mis en place pour s'assurer que l'IA reste sous le contrôle humain.\n", + "\n", + "Malgré les controverses, l'IA a continué de progresser et est bientôt devenue une partie de chaque foyer. Les maisons intelligentes étaient maintenant la norme, avec des assistants alimentés par l'IA gérant les tâches quotidiennes et fournissant des services personnalisés à chaque membre de la famille.\n", + "\n", + "Sur le lieu de travail, l'IA était devenue un atout précieux pour les entreprises. Elle pouvait traiter les données et prendre des décisions à la vitesse de l'éclair, ce qui entraînait une augmentation de la productivité et de la rentabilité. Cependant, certaines personnes craignaient que l'IA ne remplace les travailleurs humains, les rendant obsolètes.\n", + "\n", + "L'industrie du divertissement avait également été transformée par l'IA. Les jeux et les films en réalité virtuelle permettaient aux gens de se plonger dans un tout nouveau monde, tandis que les personnages alimentés par l'IA dans les films et les émissions de télévision étaient indiscernables des acteurs réels.\n", + "\n", + "L'IA avait également joué un rôle important dans la gestion des catastrophes. Avec sa capacité à analyser les données et à prédire les résultats, elle avait contribué à\n" + ] + } + ], + "source": [ + "prompt = (\n", + " \"Translate this text from English into French:\" + response[\"choices\"][0][\"text\"]\n", + ")\n", + "response = gpt35instruct(prompt)\n", + "\n", + "print(response[\"choices\"][0][\"text\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "b779709b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " prévenir et à minimiser les effets de catastrophes naturelles telles que les ouragans et les tremblements de terre.\n", + "\n", + "En somme, l'arrivée de l'IA avait apporté de nombreux avantages à la société, mais elle avait également suscité des préoccupations et des débats sur son utilisation et son impact futur. Il restait à voir comment l'humanité allait gérer cette technologie en constante évolution dans les années à venir.\n", + "\n", + "Nell'anno 2050, l'intelligenza artificiale era diventata una parte integrante della vita quotidiana. Era progredita ben oltre ciò che chiunque potesse immaginare. L'IA ora aveva la capacità di pensare, imparare e adattarsi da sola, rendendo la vita più facile e conveniente per gli esseri umani.\n", + "\n", + "Uno dei cambiamenti più significativi portati dall'IA era nel campo della medicina. Con l'aiuto di algoritmi avanzati e analisi dei dati, l'IA poteva diagnosticare con precisione malattie e creare piani di trattamento personalizzati per i pazienti. Aveva notevolmente ridotto il tasso di errore nelle diagnosi e migliorato il sistema sanitario nel suo complesso.\n", + "\n", + "Nel settore dell'istruzione, l'IA aveva rivoluzionato il modo in cui gli studenti imparavano. Le tecnologie di realtà virtuale e aumentata permettevano agli studenti di vivere un'esperienza di apprendimento pratica come mai prima d'ora. I tutor alimentati dall'IA erano anche disponibili per aiutare e guidare gli studenti nei loro studi. Ciò aveva portato a un significativo aumento del tasso di successo scolastico.\n", + "\n", + "Anche l'industria dei trasporti era stata trasformata dall'IA. Le auto autonome e i droni erano ora i principali modi di trasporto. Erano dotati di sensori e algoritmi avanzati che li rendevano più sicuri ed efficienti dei conducenti umani. La congestione del traffico e gli incidenti erano quasi inesistenti e l'ambiente aveva notevolmente beneficiato della riduzione delle emissioni di carbonio.\n", + "\n", + "Man mano che l'IA continuava a evolversi, diventava una parte essenziale della forza lavoro. Molti lavori che un tempo erano svolti da esseri umani erano ora automatizzati, portando a una diminuzione del tasso di disoccupazione. Tuttavia, ciò aveva anche sollevato preoccupazioni etiche e dibattiti sul ruolo dell'IA nella società.\n", + "\n", + "Uno degli sviluppi più importanti dell'IA è stata la creazione di robot umanoidi. Questi robot avevano caratteristiche e abilità simili a quelle degli esseri umani e venivano utilizzati per varie mansioni, dalle faccende domestiche a missioni pericolose troppo rischiose per gli esseri umani. Alcune persone si erano persino legate emotivamente a questi robot, considerandoli compagni.\n", + "\n", + "Tuttavia, non tutti erano soddisfatti della rapida avanzata dell'IA. C'erano timori che l'IA diventasse più intelligente degli esseri umani e prendesse il controllo del mondo. Per evitare ciò, erano state istituite regole e linee guida rigorose per assicurare che l'IA rimanesse sotto il controllo umano.\n", + "\n", + "Nonostante le controversie, l'IA ha continuato a progredire ed è presto diventata una parte di ogni casa. Le case intelligenti erano ora la norma, con assistenti alimentati dall'IA che gestivano le attività quotidiane e fornivano servizi personalizzati a ogni membro della famiglia.\n", + "\n", + "Sul luogo di lavoro, l'IA era diventata un prezioso alleato per le aziende. Poteva elaborare dati e prendere decisioni alla velocità della luce, portando a un aumento della produttività e della redditività. Tuttavia, alcune persone temevano che l'IA sostituisse i lavoratori umani, rendendoli obsoleti.\n", + "\n", + "Anche l'industria dell'intrattenimento era stata trasformata dall'IA.\n" + ] + } + ], + "source": [ + "prompt = \"Translate this text into Italian:\" + response[\"choices\"][0][\"text\"]\n", + "response = gpt35instruct(prompt)\n", + "\n", + "print(response[\"choices\"][0][\"text\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "400a5139", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.10 - SDK v2", + "language": "python", + "name": "python310-sdkv2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}