Skip to content

Instantly share code, notes, and snippets.

@NassimElH01
Created November 26, 2024 10:17
Show Gist options
  • Select an option

  • Save NassimElH01/67a22ab9fddcb5431406aa21eb13ea32 to your computer and use it in GitHub Desktop.

Select an option

Save NassimElH01/67a22ab9fddcb5431406aa21eb13ea32 to your computer and use it in GitHub Desktop.
Kopi af ChatGPT_News_Generator.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/NassimElH01/67a22ab9fddcb5431406aa21eb13ea32/kopi-af-chatgpt_news_generator.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"#News generator"
],
"metadata": {
"id": "wRaQ4yNKXyFA"
}
},
{
"cell_type": "markdown",
"source": [
"###Install OpenAI components"
],
"metadata": {
"id": "R_M3C873eegq"
}
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "mW4Wx25zsIPC",
"outputId": "c5292a9e-0255-4d5d-e62e-9eddbf3362f2"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: openai in /usr/local/lib/python3.10/dist-packages (1.54.4)\n",
"Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from openai) (3.7.1)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /usr/local/lib/python3.10/dist-packages (from openai) (1.9.0)\n",
"Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from openai) (0.27.2)\n",
"Requirement already satisfied: jiter<1,>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from openai) (0.7.1)\n",
"Requirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from openai) (2.9.2)\n",
"Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from openai) (1.3.1)\n",
"Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.10/dist-packages (from openai) (4.66.6)\n",
"Requirement already satisfied: typing-extensions<5,>=4.11 in /usr/local/lib/python3.10/dist-packages (from openai) (4.12.2)\n",
"Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai) (3.10)\n",
"Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai) (1.2.2)\n",
"Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->openai) (2024.8.30)\n",
"Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->openai) (1.0.7)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.14.0)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->openai) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.23.4 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->openai) (2.23.4)\n"
]
}
],
"source": [
"pip install openai"
]
},
{
"cell_type": "code",
"source": [
"pip install python-dotenv"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "zoG7LD58sV6F",
"outputId": "05365541-b67b-429f-8218-f2a7d8015e53"
},
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: python-dotenv in /usr/local/lib/python3.10/dist-packages (1.0.1)\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"###Import various software libraries"
],
"metadata": {
"id": "U-TA7nk-20Tf"
}
},
{
"cell_type": "code",
"source": [
"import time\n",
"import pprint\n",
"from google.colab import output"
],
"metadata": {
"id": "0sRrjYUg29Mw"
},
"execution_count": 12,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"###Mount Google Drive"
],
"metadata": {
"id": "nuqf1lJ3gHVD"
}
},
{
"cell_type": "code",
"source": [
"from google.colab import drive\n",
"drive.mount('/content/drive')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "umDyiesRsj8U",
"outputId": "6abb733e-1b6a-43ca-f2a1-6ab56d8a2672"
},
"execution_count": 13,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"from dotenv import load_dotenv"
],
"metadata": {
"id": "Np47jgufsvjC"
},
"execution_count": 14,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"###Load .env file"
],
"metadata": {
"id": "mFHzjazGgvq2"
}
},
{
"cell_type": "code",
"source": [
"load_dotenv('drive/My Drive/Colab Notebooks/env')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "0fFuJL4Vs7Kx",
"outputId": "f4b51ab3-b836-4325-8727-887481bd5fd6"
},
"execution_count": 15,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"True"
]
},
"metadata": {},
"execution_count": 15
}
]
},
{
"cell_type": "markdown",
"source": [
"###Initialize Open AI client"
],
"metadata": {
"id": "nnOzY4EkhAQG"
}
},
{
"cell_type": "code",
"source": [
"from openai import OpenAI as openai"
],
"metadata": {
"id": "2gSFihVstLPH"
},
"execution_count": 16,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import os\n",
"openai.api_key = os.getenv(\"OPENAI_API_KEY\")\n",
"openai.api_key"
],
"metadata": {
"id": "EiQPc5lgtUMo",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 37
},
"outputId": "3dd08119-d3ff-49c4-aeb5-935f7192ae8a"
},
"execution_count": 17,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'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'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 17
}
]
},
{
"cell_type": "code",
"source": [
"client = openai()"
],
"metadata": {
"id": "ieGjr5HqtfWv"
},
"execution_count": 18,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"###Initialize news variables"
],
"metadata": {
"id": "zP1RaXKt3OFb"
}
},
{
"cell_type": "code",
"source": [
"news1=\"Some news 1\"\n",
"news2=\"Some news 2\"\n",
"news3=\"Some news 3\"\n",
"news4=\"Some news 4\""
],
"metadata": {
"id": "2i5W8l4Ft4zD"
},
"execution_count": 19,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"###Base prompt"
],
"metadata": {
"id": "RtWDzJ1r7lmx"
}
},
{
"cell_type": "code",
"source": [
"prompt_role = '''You are an assistant for journalists.\n",
"Your task is to write articles, based on the FACTS that are given to you.\n",
"You should respect the instructions: the TONE, the LENGTH, and the STYLE'''"
],
"metadata": {
"id": "FHiJJURH7vCq"
},
"execution_count": 20,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"###ChapGPT routines for generating news"
],
"metadata": {
"id": "0eq2R_S176En"
}
},
{
"cell_type": "code",
"source": [
"def ask_chatgpt(messages):\n",
" response = client.chat.completions.create(model=\"gpt-3.5-turbo\",\n",
" messages=messages)\n",
" return (response.choices[0].message.content)\n"
],
"metadata": {
"id": "Ac_UloC1xsUE"
},
"execution_count": 21,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def assist_journalist(\n",
" facts ,\n",
" tone: str, length_words: int, style: str):\n",
" facts = \", \".join(facts)\n",
" prompt = f'{prompt_role}\\nFACTS: {facts}\\nTONE: {tone}\\nLENGTH: {length_words} words\\nSTYLE: {style}'\n",
" print(\"Prompt:\")\n",
" pprint.pprint(prompt)\n",
" return ask_chatgpt([{\"role\": \"user\", \"content\": prompt}])"
],
"metadata": {
"id": "gHd22QUiyPZz"
},
"execution_count": 22,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"###Generate news no. 1"
],
"metadata": {
"id": "MUvc8UXBwGSe"
}
},
{
"cell_type": "code",
"source": [
"facts1 = ['Donald Trump elected for president', 'Putin is confused']\n",
"tone1 = 'formal'\n",
"length_words1 = 100\n",
"style1 = 'blogpost'"
],
"metadata": {
"id": "gVj4VS2VoW4H"
},
"execution_count": 23,
"outputs": []
},
{
"cell_type": "code",
"source": [
"news1= assist_journalist(facts1, tone1, length_words1, style1)\n",
"print()\n",
"print(\"Response:\")\n",
"news1"
],
"metadata": {
"id": "VLdnrznQkIxi",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 258
},
"outputId": "cdd75017-2c53-4672-f56b-8356256b49ed"
},
"execution_count": 24,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Prompt:\n",
"('You are an assistant for journalists.\\n'\n",
" 'Your task is to write articles, based on the FACTS that are given to you.\\n'\n",
" 'You should respect the instructions: the TONE, the LENGTH, and the STYLE\\n'\n",
" 'FACTS: Donald Trump elected for president, Putin is confused\\n'\n",
" 'TONE: formal\\n'\n",
" 'LENGTH: 100 words\\n'\n",
" 'STYLE: blogpost')\n",
"\n",
"Response:\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"\"It's official: Donald Trump has been elected for a second term as President of the United States. The news has left many world leaders scratching their heads, including Russian President Vladimir Putin. Reports suggest that Putin is confused by the outcome of the election, as he had reportedly expected a different result. This unexpected turn of events has sparked speculation and left many wondering about the implications for US-Russia relations moving forward. As we await further developments and reactions from world leaders, it is clear that this election result will have far-reaching consequences on the global stage.\""
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 24
}
]
},
{
"cell_type": "markdown",
"source": [
"###Generate news no. 2"
],
"metadata": {
"id": "4pziSlNXwiHe"
}
},
{
"cell_type": "code",
"source": [
"facts2 = ['fact 1', 'fact 2']\n",
"tone2 = 'formal'\n",
"length_words2 = 100\n",
"style2 = 'blogpost'"
],
"metadata": {
"id": "x5FlrlLltggw"
},
"execution_count": 25,
"outputs": []
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"id": "33n6sRel-EQK"
}
},
{
"cell_type": "code",
"source": [
"news2= assist_journalist(facts2, tone2, length_words2, style2)\n",
"print()\n",
"print(\"Response:\")\n",
"news2"
],
"metadata": {
"id": "jpF2IVHOwHtl",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 275
},
"outputId": "e7ca7943-ba55-4385-9049-0f60489261ec"
},
"execution_count": 26,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Prompt:\n",
"('You are an assistant for journalists.\\n'\n",
" 'Your task is to write articles, based on the FACTS that are given to you.\\n'\n",
" 'You should respect the instructions: the TONE, the LENGTH, and the STYLE\\n'\n",
" 'FACTS: fact 1, fact 2\\n'\n",
" 'TONE: formal\\n'\n",
" 'LENGTH: 100 words\\n'\n",
" 'STYLE: blogpost')\n",
"\n",
"Response:\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'Title: The Impact of Climate Change on Global Ecosystems\\n\\nClimate change continues to be a pressing issue affecting ecosystems worldwide. Factoring in rising temperatures and extreme weather events, habitats are being disrupted and species are facing extinction. Fact 1 illustrates the stark reality of coral reefs bleaching and dying due to ocean acidification. Meanwhile, Fact 2 highlights the decline in biodiversity in forests caused by deforestation and habitat loss. As concerned global citizens, it is crucial for us to acknowledge these facts and take action to mitigate the effects of climate change. Together, we can work towards a sustainable future for our planet and its precious ecosystems.'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 26
}
]
},
{
"cell_type": "markdown",
"source": [
"###Generate news no. 3"
],
"metadata": {
"id": "VoDBw9EGwzWc"
}
},
{
"cell_type": "code",
"source": [
"facts3 = ['fact 1', 'fact 2', 'fact 3']\n",
"tone3 = 'formal'\n",
"length_words3 = 100\n",
"style3 = 'blogpost'"
],
"metadata": {
"id": "DjQCXzebw3Kh"
},
"execution_count": 27,
"outputs": []
},
{
"cell_type": "code",
"source": [
"news3= assist_journalist(facts3, tone3, length_words3, style3)\n",
"print()\n",
"print(\"Response:\")\n",
"news3"
],
"metadata": {
"id": "XVAEMTU1xdFn",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 258
},
"outputId": "09de7e78-391d-4842-ea7a-c7fdb102ccaa"
},
"execution_count": 28,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Prompt:\n",
"('You are an assistant for journalists.\\n'\n",
" 'Your task is to write articles, based on the FACTS that are given to you.\\n'\n",
" 'You should respect the instructions: the TONE, the LENGTH, and the STYLE\\n'\n",
" 'FACTS: fact 1, fact 2, fact 3\\n'\n",
" 'TONE: formal\\n'\n",
" 'LENGTH: 100 words\\n'\n",
" 'STYLE: blogpost')\n",
"\n",
"Response:\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"\"In today's world of constant information and news, it's important to stay updated on the latest facts and developments. Here are three important facts to keep in mind:\\n\\nFact 1: According to recent studies, the global economy is expected to grow by 3.5% in the upcoming year.\\nFact 2: The unemployment rate in the United States has decreased to 4.4%, the lowest it has been in over a decade.\\nFact 3: Scientists have discovered a new species of fish deep in the ocean, marking a significant breakthrough in marine biology.\\n\\nIt's crucial to stay informed and aware of these facts as they shape our understanding of the world around us.\""
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 28
}
]
},
{
"cell_type": "markdown",
"source": [
"###Generate news no. 4"
],
"metadata": {
"id": "bJGO4l9Zx4fA"
}
},
{
"cell_type": "code",
"source": [
"facts4 = ['fact 1', 'fact 2', 'fact 3']\n",
"tone4 = 'formal'\n",
"length_words4 = 100\n",
"style4 = 'blogpost'"
],
"metadata": {
"id": "HmErFl8fx8OM"
},
"execution_count": 29,
"outputs": []
},
{
"cell_type": "code",
"source": [
"news4= assist_journalist(facts4, tone4, length_words4, style4)\n",
"print()\n",
"print(\"Response:\")\n",
"news4"
],
"metadata": {
"id": "ZJtYRxuQyJHJ",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 258
},
"outputId": "109c5c13-833c-453d-bf9e-0a2b281ad0ad"
},
"execution_count": 30,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Prompt:\n",
"('You are an assistant for journalists.\\n'\n",
" 'Your task is to write articles, based on the FACTS that are given to you.\\n'\n",
" 'You should respect the instructions: the TONE, the LENGTH, and the STYLE\\n'\n",
" 'FACTS: fact 1, fact 2, fact 3\\n'\n",
" 'TONE: formal\\n'\n",
" 'LENGTH: 100 words\\n'\n",
" 'STYLE: blogpost')\n",
"\n",
"Response:\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"\"In today's blog post, we're going to delve into the latest developments in the world of technology. Fact 1 reveals a groundbreaking new invention that has the potential to revolutionize the way we live our daily lives. Fact 2 sheds light on a major partnership between two industry giants that promises to shake up the market. Finally, fact 3 showcases a significant breakthrough in sustainable energy that could have far-reaching implications for the future of our planet. Stay tuned for more updates on these exciting developments in the tech world. Keep informed and stay ahead of the game.\""
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 30
}
]
},
{
"cell_type": "markdown",
"source": [
"###The news display"
],
"metadata": {
"id": "BD7R-fC-usl3"
}
},
{
"cell_type": "code",
"source": [
"for count in range(5):\n",
" output.clear()\n",
" pprint.pprint(news1)\n",
" time.sleep(5)\n",
" output.clear()\n",
" pprint.pprint(news2)\n",
" time.sleep(5)\n",
" output.clear()\n",
" pprint.pprint(news3)\n",
" time.sleep(5)\n",
" output.clear()\n",
" pprint.pprint(news4)\n",
" time.sleep(5)"
],
"metadata": {
"id": "4_fEyArPjWTi",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "40905cc0-d4ff-452e-f508-f16e5f9d7357"
},
"execution_count": 31,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"(\"In today's blog post, we're going to delve into the latest developments in \"\n",
" 'the world of technology. Fact 1 reveals a groundbreaking new invention that '\n",
" 'has the potential to revolutionize the way we live our daily lives. Fact 2 '\n",
" 'sheds light on a major partnership between two industry giants that promises '\n",
" 'to shake up the market. Finally, fact 3 showcases a significant breakthrough '\n",
" 'in sustainable energy that could have far-reaching implications for the '\n",
" 'future of our planet. Stay tuned for more updates on these exciting '\n",
" 'developments in the tech world. Keep informed and stay ahead of the game.')\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"#Exercises"
],
"metadata": {
"id": "5OxJTp9I9Cqc"
}
},
{
"cell_type": "markdown",
"source": [
"\n",
"\n",
"1. Provide 'facts' for news items 2, 3 and 4 so the chat reponses makes sense. Vary on style and tone as appropriate\n",
"2. State your observations what 'facts' that makes no-nonsense 'news'\n",
"3. Briefly describe the business processes that properly could support news generation as performed above. Also consider technical issues.\n",
"\n",
"\n",
"\n",
"\n"
],
"metadata": {
"id": "lAont_HU9GiN"
}
},
{
"cell_type": "code",
"source": [
"# prompt: Provide 'facts' for news items 2, 3 and 4 so the chat reponses makes sense. Vary on style and tone as appropriate\n",
"\n",
"# ###Generate news no. 2\n",
"facts2 = ['A new study reveals a link between regular consumption of dark chocolate and improved cognitive function.', 'Participants in the study showed enhanced memory and problem-solving abilities.']\n",
"tone2 = 'informative'\n",
"length_words2 = 150\n",
"style2 = 'scientific journal article'\n",
"news2= assist_journalist(facts2, tone2, length_words2, style2)\n",
"print()\n",
"print(\"Response:\")\n",
"news2\n",
"\n",
"# ###Generate news no. 3\n",
"facts3 = ['Local bakery wins national award for its innovative sourdough bread.', 'The bakery, known for its unique flavor combinations and commitment to traditional techniques, beat out hundreds of other competitors.']\n",
"tone3 = 'enthusiastic'\n",
"length_words3 = 120\n",
"style3 = 'local newspaper article'\n",
"news3= assist_journalist(facts3, tone3, length_words3, style3)\n",
"print()\n",
"print(\"Response:\")\n",
"news3\n",
"\n",
"# ###Generate news no. 4\n",
"facts4 = ['A team of scientists have discovered a new species of deep-sea creature.', 'The creature possesses unique bioluminescent properties and is unlike anything seen before.']\n",
"tone4 = 'formal'\n",
"length_words4 = 200\n",
"style4 = 'scientific journal article'\n",
"news4= assist_journalist(facts4, tone4, length_words4, style4)\n",
"print()\n",
"print(\"Response:\")\n",
"news4"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 752
},
"id": "fy-5-K5czTdx",
"outputId": "4a1eb7c2-ce3b-4aa1-b5c0-4eb227456456"
},
"execution_count": 32,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Prompt:\n",
"('You are an assistant for journalists.\\n'\n",
" 'Your task is to write articles, based on the FACTS that are given to you.\\n'\n",
" 'You should respect the instructions: the TONE, the LENGTH, and the STYLE\\n'\n",
" 'FACTS: A new study reveals a link between regular consumption of dark '\n",
" 'chocolate and improved cognitive function., Participants in the study showed '\n",
" 'enhanced memory and problem-solving abilities.\\n'\n",
" 'TONE: informative\\n'\n",
" 'LENGTH: 150 words\\n'\n",
" 'STYLE: scientific journal article')\n",
"\n",
"Response:\n",
"Prompt:\n",
"('You are an assistant for journalists.\\n'\n",
" 'Your task is to write articles, based on the FACTS that are given to you.\\n'\n",
" 'You should respect the instructions: the TONE, the LENGTH, and the STYLE\\n'\n",
" 'FACTS: Local bakery wins national award for its innovative sourdough bread., '\n",
" 'The bakery, known for its unique flavor combinations and commitment to '\n",
" 'traditional techniques, beat out hundreds of other competitors.\\n'\n",
" 'TONE: enthusiastic\\n'\n",
" 'LENGTH: 120 words\\n'\n",
" 'STYLE: local newspaper article')\n",
"\n",
"Response:\n",
"Prompt:\n",
"('You are an assistant for journalists.\\n'\n",
" 'Your task is to write articles, based on the FACTS that are given to you.\\n'\n",
" 'You should respect the instructions: the TONE, the LENGTH, and the STYLE\\n'\n",
" 'FACTS: A team of scientists have discovered a new species of deep-sea '\n",
" 'creature., The creature possesses unique bioluminescent properties and is '\n",
" 'unlike anything seen before.\\n'\n",
" 'TONE: formal\\n'\n",
" 'LENGTH: 200 words\\n'\n",
" 'STYLE: scientific journal article')\n",
"\n",
"Response:\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'In a groundbreaking discovery, a team of scientists has identified a new species of deep-sea creature with remarkable bioluminescent properties. This newly discovered organism has captivated researchers with its unparalleled characteristics that set it apart from any known species.\\n\\nThe unique bioluminescent properties of this deep-sea creature have astonished scientists, as they have never observed anything quite like it before. The organism emits a mesmerizing glow that illuminates its surroundings in the dark depths of the ocean, providing crucial insight into the adaptations of life in extreme environments.\\n\\nThis discovery sheds light on the incredible diversity of life that thrives in the deep-sea ecosystems, highlighting the importance of continued exploration and research in these remote regions. The findings from this study have profound implications for our understanding of the complexities of marine life and the interconnectedness of different species in the vast depths of the ocean.\\n\\nAs scientists continue to unravel the mysteries of this newly discovered deep-sea creature, they are eager to uncover more about its biology, behavior, and ecological significance. This remarkable discovery opens up a world of possibilities for further research and exploration into the uncharted realms of the deep sea.'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 32
}
]
},
{
"cell_type": "code",
"source": [
"# prompt: State your observations what 'facts' that makes no-nonsense ‘news’ og skriv det hele på dansk\n",
"\n",
"For at skabe troværdige nyheder med ChatGPT, er det afgørende at fakta er konkrete, verificerbare og relevante. \"Fakta\" bør være baseret på dokumenterede kilder og ikke spekulationer eller meninger. De skal være præcise og uden tvetydighed.\n",
"\n",
"For eksempel, i stedet for \"Putin er forvirret\" (som er subjektivt), ville en mere brugbar fakta være \"Putin annoncerede nye sanktioner mod EU\" (konkret og verificerbar). At bruge upræcise eller subjektive \"fakta\" fører til nyheder af lav kvalitet, der er mere fiktion end faktuel rapportering.\n",
"\n",
"Kort sagt, fakta skal være fundamentet for objektiv journalistik. Jo mere konkrete og verificerbare fakta, jo mere troværdig bliver nyheden.\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 122
},
"id": "eLvjIG8FzWrX",
"outputId": "49cb16ea-2a77-4405-b0c1-82ee62b8eb64"
},
"execution_count": 34,
"outputs": [
{
"output_type": "error",
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-34-9e5970f3e728>, line 3)",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-34-9e5970f3e728>\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m For at skabe troværdige nyheder med ChatGPT, er det afgørende at fakta er konkrete, verificerbare og relevante. \"Fakta\" bør være baseret på dokumenterede kilder og ikke spekulationer eller meninger. De skal være præcise og uden tvetydighed.\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# prompt: Briefly describe the business processes that properly could support news generation as performed above. Also consider technical issues. og skrive det hele på dansk\n",
"\n",
"## Forretningsprocesser og tekniske udfordringer ved nyhedsproduktion med AI\n",
"\n",
"Koden demonstrerer en simpel proces til nyhedsproduktion baseret på en stor sprogmodel (LLM). For at skalere og forbedre denne proces til et professionelt niveau, kræves der veldefinerede forretningsprocesser og løsning af flere tekniske udfordringer.\n",
"\n",
"**Forretningsprocesser:**\n",
"\n",
"1. **Indsamling af fakta:** En robust proces til at indsamle verificerede fakta fra pålidelige kilder er afgørende. Dette kan involvere:\n",
" * **Data scraping:** Automatisk indsamling af data fra nyhedskilder, sociale medier og andre online platforme. Der skal tages højde for juridiske og etiske aspekter af scraping.\n",
" * **API'er:** Anvendelse af nyhedsapplikations-programmeringsgrænseflader (API'er) fra kendte nyhedsudbydere.\n",
" * **Manuel indtastning:** For specialiserede eller unikke informationer kan manuel kontrol og indtastning være nødvendigt.\n",
" * **Fact-checking:** Et vigtigt trin er implementering af en proces til faktatjekning af de indsamlede informationer for at undgå spredning af misinformation.\n",
"\n",
"2. **Nyhedsudvikling:**\n",
" * **Emnedefinition:** Bestemmelse af relevante nyhedsemner baseret på aktuelle begivenheder og analyse af data.\n",
" * **Prompt engineering:** Formulering af effektive \"prompts\" til LLM'en for at generere specifikke og relevante nyheder med den ønskede tone og stil. Test af forskellige prompts for at optimere udgangen er afgørende.\n",
" * **Parameterstyring:** Definer parametre såsom tone, længde og stil for at tilpasse nyhedens karakteristikker til det tilsigtede publikum og medie.\n",
"\n",
"3. **Kvalitetskontrol:**\n",
" * **Manuel gennemgang:** En redaktør skal gennemgå genereret indhold for at sikre nøjagtighed, relevans og god sproglig kvalitet.\n",
" * **Automatiserede kvalitetskontrolsystemer:** Implementering af NLP-baserede værktøjer til automatisk at identificere potentielle fejl eller fordomme i teksterne.\n",
" * **Feedback loop:** En mekanisme til indsamling af brugerfeedback og optimering af processen ud fra denne feedback.\n",
"\n",
"4. **Publicering og distribution:**\n",
" * **Integration med CMS:** Integration med et content management system (CMS) til publicering af nyhederne.\n",
" * **Distributionsplatforme:** Automatisk distribution af nyheder til forskellige platforme såsom hjemmeside, sociale medier etc.\n",
"\n",
"**Tekniske udfordringer:**\n",
"\n",
"* **Datakilder:** Sikre pålidelige og varierede datakilder er kritisk.\n",
"* **Skalerbarhed:** Systemet skal være skalerbart for at håndtere et stort antal nyheder og høj trafik.\n",
"* **Bias og misinformation:** Sikre at modellen ikke genererer fordomme eller misinformation.\n",
"* **Kostnader:** Brug af API'er og beregningsressourcer kan være omkostningskrævende.\n",
"* **Sikkerhed:** beskyttelse af data og API nøgler.\n",
"* **Real-time performance:** For breaking news er real-time generering og publicering nødvendigt.\n",
"* **NLP-modeller:** Den valgte model og dens præstation afhænger af opgaven.\n",
"* **Monitorering og vedligehold:** kontinuerlig monitorering af system præstation og data kvalitetssikring.\n",
"\n",
"\n",
"Kort sagt, en succesfuld AI-drevet nyhedsproduktion kræver en kombination af en veldefineret forretningsproces, robust teknologi og en dedikeret kvalitetskontrolproces. De tekniske udfordringer skal adresseres fra starten for at opbygge et pålideligt og skalérbart system.\n"
],
"metadata": {
"id": "NVxiV4kPzfmN"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"id": "spsqF9R-zfXf"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment