<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yousseftarhri on Medium]]></title>
        <description><![CDATA[Stories by Yousseftarhri on Medium]]></description>
        <link>https://medium.com/@yousseftarhri15?source=rss-dbf2761fd624------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CMmD-fWwDBHYRelA3upfEA.jpeg</url>
            <title>Stories by Yousseftarhri on Medium</title>
            <link>https://medium.com/@yousseftarhri15?source=rss-dbf2761fd624------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 21:16:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yousseftarhri15/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AI Agents for Travel: Creating a Smart Itinerary Planner with CrewAI]]></title>
            <link>https://medium.com/@yousseftarhri15/ai-agents-for-travel-creating-a-smart-itinerary-planner-with-crewai-30111071e767?source=rss-dbf2761fd624------2</link>
            <guid isPermaLink="false">https://medium.com/p/30111071e767</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[crew-ai]]></category>
            <dc:creator><![CDATA[Yousseftarhri]]></dc:creator>
            <pubDate>Fri, 18 Apr 2025 13:42:15 GMT</pubDate>
            <atom:updated>2025-12-25T13:20:42.538Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone! Today, we’re going to build a smart itinerary planner using CrewAI. The user will simply enter the city they’re traveling to and their hobbies, and a team of AI agents will collaborate to generate a personalized 7-day itinerary for that destination.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IHTI82U2ESbaWPitRsHZyQ.png" /></figure><p>But first, let’s break down some key concepts.</p><p>👉 <strong>What is an AI agent?</strong><br> AI agents are intelligent software systems that can operate autonomously to perform specific tasks. More importantly, they can also collaborate with other agents to make decisions on behalf of the user.</p><p>👉 <strong>What is CrewAI?</strong><br> CrewAI is an open-source Python framework that allows you to orchestrate multiple AI agents, enabling them to work together toward a common goal.</p><p>Now, let’s hit the ground running!<br> We’ll start by setting up our environment and installing the required dependencies.<br> <strong>Note:</strong> CrewAI requires Python version <strong>&gt;= 3.10 and &lt; 3.13</strong>.We will use uv since crewAI use uv as its dependency management</p><h4>On macOS/Linux follow this instruction:</h4><pre>curl -LsSf https://astral.sh/uv/install.sh | sh #or wget -qO- https://astral.sh/uv/install.sh | sh<br>uv tool install crewai<br>uv tool list #to verify that crewai is installed</pre><h4>On Windows:</h4><ul><li>Use irm to download the script and iex to execute it:</li></ul><pre>powershell -ExecutionPolicy ByPass -c &quot;irm https://astral.sh/uv/install.ps1 | iex&quot;</pre><ul><li>If you run into any issues, refer to <a href="https://docs.astral.sh/uv/getting-started/installation/">UV’s installation guide</a> for more information.</li></ul><h3>Creating a crewai Project.</h3><p>Let’s create a new crewai project using CLI, the following command will create a complete project structure with all necessary files.</p><pre>crewai create crew travel_agent<br>cd travel_agent</pre><p>Before we continue, I’ll share <a href="https://github.com/yousseftarhri/Itinerary_Planner_CrewAI/tree/main">the full code</a> with you in case you want to clone <a href="https://github.com/yousseftarhri/Itinerary_Planner_CrewAI/tree/main">the repository</a> and make your own edits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*tqNlKYHTallW-ElX8gVm4w.png" /></figure><p>First of all, open the crew.py file and load your OpenAI API key from a .env file to keep your credentials safe and out of your code.</p><pre>import os<br>from dotenv import load_dotenv<br><br>load_dotenv()<br><br>openai_key = os.getenv(&quot;OPENAI_API_KEY&quot;)</pre><p>The first step is to define our agents. Agents are specialized team members, each with a specific role and responsibilities. They are assigned tasks — individual assignments with clear objectives to achieve.</p><p><strong>Let’s start by defining the agents.</strong> Open the agents.yaml file and begin by creating your first agent. If you see any pre-existing AI agents there, feel free to delete them and create your own from scratch.</p><p>Our first agent will be the <em>tourism guide</em>, responsible for suggesting the best places to visit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gXf3wsLhern4cATjgccNRA.png" /></figure><p><strong>As you can see in the image, there are three main parameters:</strong></p><ul><li><strong>role</strong>: Defines what the agent does and their domain of expertise.</li><li><strong>goal</strong>: Describes the specific objective the agent needs to achieve. It should be clear and emphasize quality standards to help the agent understand what a &#39;good&#39; result looks like.</li><li><strong>backstory</strong>: Adds depth to the agent, influencing how they approach problems and collaborate with other agents.</li></ul><p><strong>Note:</strong> Any value in <strong>brackets</strong> (e.g. {city}) is a dynamic parameter that will be fetched from the user&#39;s input.&quot;</p><p>let’s move to define our task,In CrewAI, a <strong>task</strong> is like a clear instruction or mission you give to an AI agent. It tells the agent:</p><ul><li><strong>What to do</strong> (description),</li><li><strong>What the output should look like </strong>(expected_output),</li><li><strong>Who should do it</strong> (which agent).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vG7x2y19v50zoOAzgxGGuA.png" /></figure><p>Here, we’re defining a <strong>“tourism task”</strong> that will be handled by a specific agent called tourism_guide.</p><ul><li>description: Explains what the task is about — finding interesting places in a given city.</li><li>expected_output: Clearly states the format of the output — a bullet list of 10 spots, each with a short description and reason.</li><li>agent: Assigns the task to an agent (like a smart virtual tour guide).</li></ul><p>Now we need to load our agents and tasks in crew.py</p><p>The crew.py file acts as the <strong>brain</strong> of your CrewAI app. It connects everything together by:</p><ul><li><strong>Loading your agents and tasks</strong> from the YAML configuration files.</li><li>Using the @agent and @task decorators to define reusable components.</li><li>Defining the <strong>workflow</strong> of your app using the @crew decorator, which builds the team and sets the process flow (e.g., sequential or hierarchical).</li><li>Optionally, combining outputs or saving results to a file like report.md</li></ul><p>Each agent is loaded from a config file like this:</p><pre>@agent<br>def tourism_guide(self) -&gt; Agent:<br>    return Agent(<br>        config=self.agents_config[&#39;tourism_guide&#39;],<br>        verbose=True<br>    )</pre><p>This means: <em>“Create an agent called </em><em>tourism_guide using the instructions defined in the file </em><em>agents.yaml.&quot;</em></p><p>after loading the agent, we need to load the the task,</p><pre>@task<br>def tourism_task(self) -&gt; Task:<br>    return Task(<br>        config=self.tasks_config[&#39;tourism_task&#39;]<br>    )</pre><p>This task asks the <strong>Tourism Guide Agent</strong> to list the top 10 places to visit in a given city.</p><p>We also have other agents and tasks. You can see the full code in this <a href="https://github.com/yousseftarhri/Itinerary_Planner_CrewAI">repository</a>, but right now, I will share with you the second agent, which will generate fun activities to do in a specific city.</p><pre>@agent<br>def activities_guide(self) -&gt; Agent:<br>    return Agent(<br>        config=self.agents_config[&#39;activities_guide&#39;],<br>        verbose=True<br>    )<br><br>@task<br>def activities_task(self) -&gt; Task:<br>    return Task(<br>        config=self.tasks_config[&#39;activities_task&#39;],<br>        context=[],<br>    )</pre><ul><li><strong>Agent</strong>: Suggests fun activities to do in a city (e.g., hiking, shows, etc.).</li><li><strong>Task</strong>: Independent, doesn’t require previous inputs — hence context=[].</li></ul><p>context=[] This means: <strong>“This task doesn’t need any input from previous tasks.” </strong>It will run <strong>independently</strong> using only its own config, <strong>without depending</strong> on another agent’s output.</p><h4>Travel Planner Agent + Task (Combines Everything)</h4><pre>@agent<br>def travel_planner(self) -&gt; Agent:<br>    return Agent(<br>        config=self.agents_config[&#39;travel_planner&#39;],<br>        verbose=True,<br>    )<br><br>@task<br>def travel_planner_task(self) -&gt; Task:<br>    return Task(<br>        config=self.tasks_config[&#39;travel_planner_task&#39;],<br>        context=[<br>            self.tourism_task(),<br>            self.activities_task(),<br>            self.food_recommender_task()<br>        ],<br>        output_file=&quot;report.md&quot;<br>    )</pre><ul><li><strong>Agent</strong>: Final AI who creates a full travel plan.</li><li><strong>Task</strong>: Combines results from the other 3 tasks via context=[...]. Generates a travel plan and <strong>writes it to a </strong><strong>report.md file</strong>.</li></ul><h4>Final Step: Create the Crew</h4><pre>@crew<br>def crew(self) -&gt; Crew:<br>    return Crew(<br>        agents=self.agents,<br>        tasks=self.tasks,<br>        process=Process.sequential,<br>        verbose=True,<br>    )</pre><ul><li><strong>agents</strong>: list of all the defined agents</li><li><strong>tasks</strong>: list of all the defined tasks</li><li><strong>process</strong>: the way tasks are executed (here it’s sequential)</li><li><strong>verbose</strong>: prints more logs while running</li></ul><h4>How it works — Step-by-Step</h4><ol><li>🧑 <strong>Agent 1 (Tourism Guide)</strong>: finds top places in a city</li><li>🧑 <strong>Agent 2 (Activities Guide)</strong>: finds fun things to do</li><li>🧑 <strong>Agent 3 (Food Recommender)</strong>: finds where/what to eat</li><li>🧑‍💼 <strong>Agent 4 (Travel Planner)</strong>: combines all of that into a daily plan</li></ol><p><strong>main.py</strong> is the final script that ties everything together and kicks off the full Travel AI planning process using user input.</p><pre>def run():<br>    &quot;&quot;&quot;<br>    Run the crew.<br>    &quot;&quot;&quot;<br>    city = input(&quot;&quot;&quot;where will you be traveling?: &quot;&quot;&quot;)<br>    hobbies = input(&quot;Hobbies: &quot;)<br>    inputs = {<br>        &#39;city&#39;: city,<br>        &#39;hobbies&#39;: hobbies,<br>    }<br><br>    try:<br>        TravelAi().crew().kickoff(inputs=inputs)<br>    except Exception as e:<br>        raise Exception(f&quot;An error occurred while running the crew: {e}&quot;)</pre><p>This collects two pieces of info from the user:</p><ul><li><strong>City</strong> → Where the user wants to travel.</li><li><strong>Hobbies</strong> → What the user likes to do (used by the activities_guide agent).</li></ul><p>This dictionary will be passed to your agents so they can personalize their responses.</p><p>If you run this file with crewai run, the app will ask for input, then automatically generate a complete travel guide.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30111071e767" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Odoo on Azure Cloud in Just a Few Minutes]]></title>
            <link>https://medium.com/@yousseftarhri15/deploy-odoo-on-azure-cloud-in-just-a-few-minutes-cb9a9fde89a8?source=rss-dbf2761fd624------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb9a9fde89a8</guid>
            <category><![CDATA[odoo]]></category>
            <category><![CDATA[odoo-development]]></category>
            <category><![CDATA[install-odoo]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[odoo-erp]]></category>
            <dc:creator><![CDATA[Yousseftarhri]]></dc:creator>
            <pubDate>Fri, 17 Jan 2025 20:32:21 GMT</pubDate>
            <atom:updated>2025-03-22T04:04:57.507Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone, We will install Odoo17 in this tutorial, which will cover installing Odoo in an Ubuntu virtual machine hosted on Azure Cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*kgcPwcupJswds6MNflxNng.jpeg" /><figcaption>odoo logo</figcaption></figure><h3>Step 1: Install odoo.</h3><p>First of all you need to access into your vm using ssh key.</p><pre>ssh -i key.pem username@address_ip</pre><p>I will share with you a <a href="https://github.com/yousseftarhri/install-odoo">script</a> that you can execute to install all you need for odoo, or take the actions listed below.</p><ol><li><strong>Install PostgreSql</strong></li></ol><p>execute the following command to install postgresql</p><pre>sudo apt install postgresql -y</pre><p>2. <strong>Odoo Repository</strong></p><p>In this tutorial, we gonna install odoo community, execute the following command.</p><pre> wget -q -O - https://nightly.odoo.com/odoo.key | sudo gpg --dearmor -o /usr/share/keyrings/odoo-archive-keyring.gpg<br> echo &#39;deb [signed-by=/usr/share/keyrings/odoo-archive-keyring.gpg] https://nightly.odoo.com/17.0/nightly/deb/ ./&#39; | sudo tee /etc/apt/sources.list.d/odoo.list<br> sudo apt-get update &amp;&amp; sudo apt-get install odoo</pre><p><strong>3. Start and Enable Odoo Service</strong></p><pre>sudo systemctl enable odoo<br>sudo systemctl start odoo</pre><h3>Step 2: Create inboud port rule</h3><p>You need to go to <a href="https://portal.azure.com/">microsoft azure portal</a>, we need to let our server to listen and receive inbound traffic from 8096 port, this is the default xmlrpc port, you can modify it as you wish.</p><p>first of all choose your VM, then click on <strong>Network settings</strong> as depicted in the screen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*h7245LGHfYlawmQfNOPOvg.png" /></figure><p>Next, select “Create Port Rule” on the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*gUNV7XVNeksah5H_RPHMmw.png" /></figure><p>then fill the form with the destination port 8069</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*QmbT_8DiB8YgrPh02xi6zA.png" /></figure><p>we are done, go to any web browser, copy this link your_address_ip:8069. then you will see the page below to create a new database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*G6MuSO4XXdY9-iNhxra4KA.png" /></figure><p>Congratulations you are done, see you soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb9a9fde89a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an AI WhatsApp Chatbot with Gemini LLM and deploy it on Heroku]]></title>
            <link>https://blog.cubed.run/building-an-intelligent-whatsapp-chatbot-with-gemini-llm-a-step-by-step-guide-to-deployment-on-e66d95035314?source=rss-dbf2761fd624------2</link>
            <guid isPermaLink="false">https://medium.com/p/e66d95035314</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Yousseftarhri]]></dc:creator>
            <pubDate>Tue, 23 Apr 2024 20:26:09 GMT</pubDate>
            <atom:updated>2024-05-13T10:07:00.739Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone. Today, we will delve deeply into the process of building an AI chatbot with Cute Edge LLMs. The Gemini API will be utilized in our use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SvufqXuK3H27ndyvmbD9XA.jpeg" /></figure><p>Let’s get started by following those steps together to successfully build our AI chatbot.</p><ol><li>Retrieve Gemini API</li><li>Retrieve Whatsapp API</li><li>Set up flask code and deploy it in Heroku</li><li>Set up webhook</li></ol><h3>1. Retrieving Gemini API.</h3><p>We need this API, so we can make a post HTTP request to Gemini LLM.</p><p>Go to <a href="https://ai.google.dev/">AI Google </a>then click on Get API, you will notice a new page, at the left of the page click on Get API Key, after that make sure to copy and past the keys in somewhere safe.</p><p>That’s all, by the way the keys are free until now, with 60 QPM (queries per minute), but you need to consider that Input and output data shared with Google.</p><h3>2. Retrieving Whatsapp API</h3><p>Firstly, go to <a href="https://developers.facebook.com/">Facebook developer</a> then create an app their, by clicking on “<strong>Create APP</strong>”. In our app we need to create a chatbot on Whatsapp, so make sure to click on “<strong>other</strong>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p6UuPzVkczP24TfRA-m2Zw.png" /></figure><p>After that choose the app type, which is “<strong>Business</strong>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OfO7kLSTMSnaYC3MlC7bUg.png" /></figure><p>Then write your app name plus your mail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYABY_mszSB1YNV3tSB_LA.png" /></figure><p>and then scroll down, you will see an icon for Whatsapp, click on it to successfully come to this page below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p_pwt4DMuZjaKeWeY8tpgg.png" /></figure><p>choose your meta account business and click “<strong>continue</strong>”. You’ll get on the page that appears on the screen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dLDpxVnszA1wd33i1EBIiQ.png" /></figure><p>click on “<strong>start using API</strong>”, and finally you will have the access to retrieve your API keys plus a test number, for now we are going to use only the number whatsapp which will be the AI ‘Sender’, plus your phone number which will be the ‘Receiver’.</p><p>Copy the temporary access token and put it somewhere safe, we will use it later , let’s jump to the next step.</p><p>You will see <strong>Step 2: Send messages with the API, </strong>click on “<strong>Send Message” </strong>button to test that you can receive a message from the test phone number, since in that chat where you will communicate with the AI.</p><h3>3. Set up Flask code and deploy it in Heroku.</h3><p>I put the code for this article in this <a href="https://github.com/yousseftarhri/whatsapp_bot_gemini/tree/main">github repository</a>. After cloning it to your own environment, make a new file named <em>.env</em> and add the API Keys listed below.</p><pre>VERIFY_TOKEN= create a random token or string <br>GEMINI_API_KEY= GEMINI API kEY<br>WHAT_TOKEN= the temporary access token from meta<br>PHONE_NUMBER= your_phone_number</pre><p><strong>Install dependencies:</strong></p><pre>pip install -r requirements.txt</pre><p>The code below explains how the bot will operate. First, it will use the GET method, which is used by the Meta server to ping our URL Callback in order to confirm webhook connectivity. Next, it will use the POST request method, which will be called whenever a user sends a message to our WhatsApp chatbot (i.e., a POST request), Then the function <em>ai_response </em>will cause the GEMINI LLM to generate a response.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb1ce10fd424a09fb4fe90594468c95f/href">https://medium.com/media/eb1ce10fd424a09fb4fe90594468c95f/href</a></iframe><p>Then go to heroku and create a new app, it will not take too long, just log in or create a new a account if you don’t have one, then you will see create new app at the top right of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bz8VmJxCTUURf0_JTqzm8A.png" /></figure><p>Then go to <strong>Deploy </strong>section and choose your github repository (The code that you cloned before push it in a new repository), and since we are not pushing .env file to the repository, we need to create our own config file in Heroku, so click on Settings, then you will notice config vars as shown in the screen shot bellow. Copy all your API keys in that section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dRCL1gwn64tFuA6MmyWfnQ.png" /></figure><p>Note you will need the domain name, you can access it in the <strong>Settings </strong>section, then scroll down you will see the domain name.</p><p>After finishing the deployment, you need to setup webhook.</p><h3>3. Set up webhook</h3><p>Let’s explain what is webhook used for, webhook typically used to connect two applications, in our case user message and LLM, when an event occur, which mean when someone send a message in whatsapp, this data will be sent to the webhook URL, then we gonna take this data and pass it to the LLM, the LLM gonna return the response based of the user input, and finally we gonna send the AI response back to the user.</p><p>After you created your app, you will be directed to this page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VjsbA1aGPhFfnp1DYW9Pzg.png" /></figure><p>Then click on setup for Webhooks, then choose Whatsapp Business Account, since here we are creating Whatsapp Bot, then click on Subscribe to this object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cQ9v-fv-D7bntdGFPbNPlQ.png" /></figure><p>After that we need to enter both Callback URL and Verify Token. Copy and past the domain name that you get from Heroku, and the verify token that you generated before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bjkaX9NhgOHKgliyruZvmg.png" /></figure><p><strong>Callback </strong>technically is a ping http or https request between one sever and another the pings occurs when an event happen, for example in our case whatsapp going to ping our URL Callback with the data when someone send a message in whatsapp chat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8162UTPUPuPzjFxjXs5mlA.png" /></figure><p>Finally subscribe to messages object, here as you can see in the screenshot, each row or field map to a given event. For example <strong>messages field</strong> will be trrigered when a user send a message in our chatbot.</p><p><strong>Congratulations</strong>, open WhatsApp Chat, try sending a message, and the AI will reply. In order to ensure that we can access this LLM in WhatsApp chat, the AI is not currently remembering previous conversations. However, you can tweak the code to add more features, such as storing chat history to help the AI recall previous conversations, and you can work on prompt engineering to improve the accuracy of your chatbot.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e66d95035314" width="1" height="1" alt=""><hr><p><a href="https://blog.cubed.run/building-an-intelligent-whatsapp-chatbot-with-gemini-llm-a-step-by-step-guide-to-deployment-on-e66d95035314">Building an AI WhatsApp Chatbot with Gemini LLM and deploy it on Heroku</a> was originally published in <a href="https://blog.cubed.run/">Cubed</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an LLM-Powered Chatbot : Creating a Telegram Chatbot Using OpenAI API]]></title>
            <link>https://medium.com/@yousseftarhri15/revolutionizing-chatbots-using-chatgpt-to-build-a-smarter-telegram-bot-39cd25ace917?source=rss-dbf2761fd624------2</link>
            <guid isPermaLink="false">https://medium.com/p/39cd25ace917</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[telegram-messenger]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[chatgpt-chatbot]]></category>
            <category><![CDATA[telegram-bot]]></category>
            <dc:creator><![CDATA[Yousseftarhri]]></dc:creator>
            <pubDate>Thu, 13 Apr 2023 23:16:06 GMT</pubDate>
            <atom:updated>2023-10-08T11:29:09.867Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone, Today we gonna create a telegram bot using OpenAI API, so instead of using chatGPT website, the goal is to integrate the chatGPT model into Telegram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KgfLFcAPuVlvSBBHJA0sDA.jpeg" /></figure><p>ChatGPT is an AI program designed for understand and generate human-like text, chatGPT was created by openAI a research company that was founded in 2015 by a group of high-profile tech executives, including Elon Musk and Sam Altman, among others. OpenAI API offer several models for NLP similar to chaGPT, these models can be accessed through OpenAI’s API, you can learn more about openAI API <a href="https://openai.com/blog/openai-api">here</a>.</p><p>The main goal of this bot is that the bot can act as Spoken English Teacher and Improver, but instead of using it in chatGPT, we gonna use it in telegram, but <strong>why</strong>? because I want my bot to join the channel and everyone can speak with the bot, so other members may learn from other mistakes.</p><h4>OpenAI API :</h4><p>As I said before, OpenAI API offer many models, in our project we will using the model <strong>gpt-3.5-turbo</strong>.</p><blockquote>gpt-3.5-turbo : Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003. Will be updated with our latest model iteration. with max 4,096 tokens and training data up to Sep 2021.</blockquote><p><strong>What is tokens : </strong>The input text should not exceed a maximum of 4096 tokens, as the model breaks the text down into tokens, each of which is basically one word.</p><p>let’s dive into the code, it’s really simple to call openAI api, first you should know that we can call the API through HTTP request from any given programming language, in our project we gonna use <strong>python3</strong>.</p><p>Follow this steps to interact with openAI API.</p><h4>1. Install OpenAI library</h4><pre>pip install openai</pre><h4>2. Authentication</h4><p>OpenAI uses API keys for authentication, to get your API key so you can call API, get your key from <a href="https://platform.openai.com/account/api-keys">here</a>, copy the key and set it as the OPENAI_API_KEY in your newly created .env file. Do not share it with anyone and keep it safe.</p><h4>3. Make a request</h4><p>Let’s try to generate text using the ChatGPT model. To begin, establish the <strong>instructions</strong> that your chatbot should be capable of generating in the context of our use case, the instruction is :</p><p>“<em>I want you to act as a spoken English teacher and improver. I will speak to you in English and you will reply to me in English to practice my spoken English. I want you to keep your reply neat, limiting the reply to 100 words. I want you to strictly correct my grammar mistakes, typos, and factual errors. I want you to ask me a question in your reply. Now let’s start practicing, you could ask me a question first. Remember, I want you to strictly correct my grammar mistakes, typos, and factual errors.</em>”</p><p>In the code you will find a variable called <strong>question</strong>, which is the user input, then you will find a dictionary named <strong>messages</strong>. This dictionary contains the <strong>instruction,</strong> <strong>question</strong>, and we will later add the <strong>answer</strong> once the model has generated it. We will then provide this dictionary to the model so that it can generate <strong>new answer</strong>. We will store all questions and answers in this dictionary, in order to help the model remember previous conversations with the user.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/001dbeb17ccd440d5ac8170e752004a4/href">https://medium.com/media/001dbeb17ccd440d5ac8170e752004a4/href</a></iframe><p>I’ll go over a few parameters with you, and you can learn more about additional parameters <a href="https://platform.openai.com/playground">here</a>.</p><p><strong>model : </strong>the name of the model you wanna use, in our case we gonna use <em>gpt-3.5-turbo</em></p><p><strong>message</strong> : the user’s input.</p><p><strong>max_tokens</strong> : the maximum tokens of inputs and outputs that any given API can generate, tokens can be words or just chunk of characters.</p><p><strong>temperature</strong> : the parameter temperature describe what sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.</p><p>That’s all, yeah it’s really simple. Right now we gonna move to the telegram API. we gonna combine openAI API with telegram API, so you can interact with AI bot in your telegram channel.</p><h4>Telegram API :</h4><p>Now let’s integrate the chatbot into telegram, you should first install python-telegram-bot library.</p><pre>pip install python-telegram-bot</pre><p>To start working with telegram API, you need first to retrieve the API key from the <strong>BotFather</strong>, Let me explain how to do that.</p><p>Go to your telegram app, and search in the search bar for BotFather.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*MdIqZgACs_BHOxzc9nvSUg.jpeg" /><figcaption>BotFather</figcaption></figure><p>Write the <strong>/newbot </strong>command and follow the instructions, after giving the name and the username of the bot, the BotFather will send you the token to access the HTTP API.</p><p>Here is the code of the bot, you can clone the code from the <a href="https://github.com/yousseftarhri/telegram-chatGPT/tree/main">github</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64fab9d843657467c5ac706330146b27/href">https://medium.com/media/64fab9d843657467c5ac706330146b27/href</a></iframe><p>Install the required Python libraries</p><pre>pip install -r requirements.txt</pre><p>Create .env file, then add OPENAI_API_KEY and Telegram_TOEKN to that file, and start the bot by running <em>python main.py</em></p><p>Once the bot is running, you can start a conversation with it by sending a message to the bot on Telegram. The bot will reply with an introductory message and ask you to start the conversation by asking a question. From there, you can continue the conversation by asking more questions and receiving replies from the bot.</p><h3>Conclusion :</h3><p>In conclusion, integrating chatGPT with other apps can generate a lot of ideas, and if we want our model to handle a certain task, we should fine-tune the model.</p><p>Fine-tuning <strong>trains a pretrained model on a new dataset without training from scratch. </strong>In the next article I will explain how you can fine-tune a model.</p><p><em>Stay tuned.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39cd25ace917" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to run any linux program at startup]]></title>
            <link>https://medium.com/@yousseftarhri15/how-to-run-any-linux-program-at-startup-9f8669f51705?source=rss-dbf2761fd624------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f8669f51705</guid>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[telegram-bot]]></category>
            <dc:creator><![CDATA[Yousseftarhri]]></dc:creator>
            <pubDate>Wed, 14 Dec 2022 23:28:50 GMT</pubDate>
            <atom:updated>2022-12-14T23:28:50.921Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone, In a previous <a href="https://medium.com/@yousseftarhri15/every-time-you-turn-on-your-computer-a-telegram-bot-will-alert-you-18cb6e80bd01">post</a>, I explained how to build a Telegram bot that will capture a photo from your camera’s computer and send it to your Telegram account. In order to run the script automatically every time the computer boots, we must now automate the process. To truly understand the project, please go to the first <a href="https://medium.com/@yousseftarhri15/every-time-you-turn-on-your-computer-a-telegram-bot-will-alert-you-18cb6e80bd01">article</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HGHv0WHzPXMP1oAwou_3bQ.jpeg" /></figure><p>Any program lunch at startup are controlled by systemd, the systemd is the first process to run at startup, is always have process id PID 1, programs that are run in the background called daemons or services. In this post, we’ll build an application that launches after computer startup.</p><p><strong>The steps are listed below.</strong></p><h3>Create the service program (script).</h3><p>The goal is to capture a photo from the computer and send it to my Telegram account. In the last <a href="https://medium.com/@yousseftarhri15/every-time-you-turn-on-your-computer-a-telegram-bot-will-alert-you-18cb6e80bd01">article</a>, I created two scripts, one that captures the picture and the other that sends it to the telegram account. So I wrote two scripts in Python and Bash. Running those two scripts at boot is the next step.</p><p><strong>Follow those steps to run any file at start up of your computer</strong></p><ol><li>Create your file.</li></ol><pre>nano screen.sh</pre><p>2. Edit your file.</p><p>The script below take picture with your webcam and save in a directory.</p><pre>#!/bin/bash<br>[[ -f saved_value ]] || echo 0 &gt; saved_value<br>n=$(&lt; saved_value)<br>echo $(( n + 1 )) &gt; saved_value<br>name_img=&quot;web-cam$n.jpg&quot;<br><br>echo `fswebcam -r 640x480 --jpeg 85 -D 1 $name_img`<br><br><br>echo `mv $name_img /home/youssef/Documents/pic`</pre><h3>Creating the unit service file</h3><p>Each program that is started with <strong>systemd</strong> has a unit service file, this file holds some attributes that <strong>systemd</strong> holds to lunch the program at startup.</p><p>Let’s create the unit file called <strong>simpletest.servcie</strong></p><pre>sudo nano /etc/systemd/system/simpletest.service</pre><p>Copy and past the following code to your file.</p><pre>[Unit]<br>Description=How-To Geek Service Example<br><br>Wants=network.target<br>After=syslog.target network-online.target<br><br>[Service]<br>Type=simple<br>ExecStart=/usr/local/bin/screen.sh #The path to your file that you wanna to execute<br>Restart=on-failure<br>RestartSec=10<br>KillMode=process<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>Let’s check the syntax of our unit service with <strong>systemctl</strong>.</p><p>This command gives us the status of our service.</p><pre>systemctl status simpletest.service</pre><p>When you add new file unit, you must tell <strong>systemd</strong> to reload the definition of unit files</p><pre>sudo systemctl daemon-reload</pre><p>Start your service now by copying and pasting the following instructions into your terminal.</p><pre>sudo systemctl enable simpletest.service<br>sudo systemctl start simpletest.service</pre><p>We done with the script that take picture from the camera’s computer, you can test that by restart your computer.</p><p>Let’s go on to the Python script that will send the image to your Telegram account so that you can see who opened your computer every time it boots up.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0576180c290bce6805ee5e7b3b8dc47a/href">https://medium.com/media/0576180c290bce6805ee5e7b3b8dc47a/href</a></iframe><p>Also we want to run this script at boot of the computer, so we will just repeat the command lines that create a service with <strong>systemd</strong>.</p><p>Finally, restart your computer, then check your telegram account, so you will receive a message with an image attached.</p><h3>Conclusion</h3><p>In conclusion, this post explains how to utilize <strong>systemd</strong>, which launches a program whenever the computer boots up. We also learn how to make a simple Telegram bot. This article’s goal is to make you aware of the numerous uses for <strong>systemd</strong> and <strong>telegram API</strong> that go beyond simply securing your computer by running a bot to take a photo from your camera’s computer when you boots up your computer and send it to you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f8669f51705" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Every time you turn on your computer, a Telegram bot will alert you.]]></title>
            <link>https://medium.com/@yousseftarhri15/every-time-you-turn-on-your-computer-a-telegram-bot-will-alert-you-18cb6e80bd01?source=rss-dbf2761fd624------2</link>
            <guid isPermaLink="false">https://medium.com/p/18cb6e80bd01</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[telegram-bot]]></category>
            <category><![CDATA[telegram-messenger]]></category>
            <dc:creator><![CDATA[Yousseftarhri]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 19:58:26 GMT</pubDate>
            <atom:updated>2022-12-12T00:21:51.682Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone, Today, we’ll create a Telegram bot that, every time your computer starts up, the telegram bot will send a private message to you and attach an image that your computer’s camera will take. This bot will only function for Linux users because <strong>systemd</strong> is required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-FZmSMqNKrSi-VJ7Squew.jpeg" /></figure><p><strong>Systemd</strong> is a standard process for controlling what programs run when a linux system boots up.</p><p>In this project we will create two scripts, <strong><em>bash script</em></strong> and <strong><em>python script.</em></strong></p><p><strong>Bash script</strong> : Every time you load your opereting system, the script will run a command line to take a photo immediately from your computer’s camera.</p><p><strong>Python script</strong> : The code use telegram API, so that the bot can send a file “Image” from the location where the bash script saves the image to your Telegram account.</p><h4>Bash script :</h4><p>the script below can take a picture from the camera of your computer, and save it in spacific folder. I use in this project fswebcam, <strong>fswebcam</strong> is a small and simple webcam app for linux. Read more about <strong>fswebcam</strong> <a href="https://manpages.ubuntu.com/manpages/bionic/man1/fswebcam.1.html">Here</a></p><p>If you don’t know how you can write a simple bash script, follow this instructions</p><ol><li>create a file.</li></ol><pre>touch name_file.sh</pre><p>2. Modifying the premission of the file, and add the execution premission to the file.</p><pre>chmod u+x name_file.sh</pre><p>3. run the script.</p><pre>./name_file.sh</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/082651ed0c5bddfb335d0ec30bdadd8e/href">https://medium.com/media/082651ed0c5bddfb335d0ec30bdadd8e/href</a></iframe><p>Here is the script that capture image from your camera and save in a folder, and every time you execute this script, you will save a new picture with different name, because as you can see, I encrement the variable <strong>n</strong> every time I run the script.</p><p><strong>Note</strong> : Before you run the script, you need to download fswebcam</p><p>See below for quick step to install fswebcam package on Ubuntu</p><pre>sudo apt-get update<br>sudo apt-get install fswebcam</pre><h3>Python script.</h3><p>The code below is simple, every time you run the code, you will recieve a message in your telegram account attached with image.</p><p>but before we get into the code, you need <strong>api_id</strong> and <strong>api_hash</strong>. Log in to your telegram account <a href="https://my.telegram.org/">https://my.telegram.org</a>, go to <a href="https://my.telegram.org/apps">“API development tools”</a> and fill out the form, you will get basic addresses as well as the <strong>api_id</strong> and <strong>api_hash</strong> parameters required for user authorization.</p><p>Here is a simple bot, so whenever you execute this code, you will recieve a message in your telegram account attached with a picture.</p><p>First, install telethon library.</p><p>Telethon is a Python library in order to make a simple Telegram bot. Here is <a href="https://docs.telethon.dev/en/stable/">Telethon’s Documentation</a>.</p><pre>pip install telethon</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0576180c290bce6805ee5e7b3b8dc47a/href">https://medium.com/media/0576180c290bce6805ee5e7b3b8dc47a/href</a></iframe><p><strong>Note</strong> : When you run this code for the first time, in the output they will ask you to enter your phone number, then you will receive a code in your telegram, use it to be verified.</p><p>Therefore, I advise running this simple code first to see if your code functions as intended, this is needed for first time authorization.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdaf7ac5f925b1b7b7ebb3590142e041/href">https://medium.com/media/fdaf7ac5f925b1b7b7ebb3590142e041/href</a></iframe><h3>Final step : Now we need to lunch our two script at boot.</h3><p>I will make Part two of this article, so I can explain you well how you can run your scripts or any program every time you open your computer.</p><h3><strong>Conclusion</strong></h3><p>In this article, We learn how to make a telegram bot using the telegram API and how to develop a bash script to capture a picture from your computer’s camera, in the next article I will explain to you, how to launch any code when your computer boots.</p><p><strong><em>stay tuned.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18cb6e80bd01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making a discord bot with python, and deploy it in heroku.]]></title>
            <link>https://medium.com/@yousseftarhri15/create-discord-bot-with-python-and-deploy-it-in-heroku-dbdb590266e0?source=rss-dbf2761fd624------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbdb590266e0</guid>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[discord-bot]]></category>
            <category><![CDATA[deployment]]></category>
            <dc:creator><![CDATA[Yousseftarhri]]></dc:creator>
            <pubDate>Mon, 09 May 2022 11:42:54 GMT</pubDate>
            <atom:updated>2023-12-21T10:07:06.840Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone. Today we will discover how to create a simple discord bot using python, I will give you the github <a href="https://github.com/yousseftarhri/Bot_discord">link</a> of the code, and we will deploy it in heroku, so that our bot can run 24/24.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*osI2_rmd0R9CTS2fCKgnEQ.png" /></figure><p>First of all, you have to go to discord developer portal, create your first application from <a href="https://discord.com/developers/applications">https://discord.com/developers/applications</a> .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3K5iUsWYLVVg8mw4lZWt_A.png" /></figure><p>Enter the name of the app and click create.</p><p>Then you will land to general overview, on the left hand sidebar click Bot, and click add bot. You will be able to change the username and the icon image of your bot, under that there is a token section, with the Rest Token button. Bot tokens are you used to authorize the API requests, make sure to not share your token with anyone. Click Rest Token, and copy your token to a safe place, for example, we gonna use ‘.env’ file in our example, you can always store any sensitive information in this file.</p><p>Now let’s add some scopes and permissions to request during installation. Click on Auth2, then URL Generator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a2seKhwwLWc5CHr_SDel6g.png" /></figure><p>We will add two scopes, <strong>applications.commands </strong>that lets your app create commands in guilds its installed, and <strong>bot </strong>to enable your bot user, after you add bot, you can add different permissions to the bot, now we will add just <strong>send messages</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agW-sBFgp8EwhK4OAWW5iw.png" /></figure><p>Once you add scopes, you should see URL in the bottom of the page, copy this link and past it in your browser so you can install your bot in your discord server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qB3TcDJhD8OCmtRA93u9bQ.png" /></figure><p>Copy the link and past it into your browser, you’ll be guided through the installation flow, where you should make sure you’re installing the app on a server where you can develop and test your bot.</p><p>After installing your app, you can head over to your sever and see that it has joined. Now let’s see how we can make our bot work 24/24. In this article, I will not explain how the code works, I will publish another post to explain the part of the python code. All the code used in this example can be found in the <a href="https://github.com/yousseftarhri/Bot_discord">repository github</a>.</p><p><a href="https://github.com/yousseftarhri/Bot_discord">GitHub - yousseftarhri/Bot_discord: Here is the code of the discord bot</a></p><h3>Deploy part :</h3><p>After we done with the code part, we need our bot to work 24/24. So we need a free host, Heroku is a free host where you can add your code.</p><p>First, in our python code directory, we need to create two file, Procfile and requirements.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*UCEFjyncx0K5AriLfG8_mQ.png" /></figure><p><strong>main.py</strong> : The code here of our bot.</p><p><strong>Procfile</strong> : A text file in the root directory of your application, to explicitly declare what command should be executed to start your app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f27b67b9026e5c8a5867e0cb18925d7/href">https://medium.com/media/8f27b67b9026e5c8a5867e0cb18925d7/href</a></iframe><p><strong>requirements.txt</strong> : Here we declare all the libraries that are important to run our code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfd0290293bf07803e48eba63b83d3a5/href">https://medium.com/media/cfd0290293bf07803e48eba63b83d3a5/href</a></iframe><p><strong>Install heroku cli :</strong></p><p>Heroku command line interface, it will help us to manage and create Heroku apps form the terminal. <a href="https://devcenter.heroku.com/articles/heroku-cli#install-the-heroku-cli">Here</a> is the instructions to in install Heroku cli.</p><p>Let’s create our first Heroku app. Go to the directory where your code is located, and login to your heroku account then create the app.</p><pre>heroku login <br>heroku create</pre><p>If you go to your heroku account, you can check that a new app was added.</p><p>Install git if you don’t have it, from <a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git">here</a>.</p><p>If your app was successfully created, follow this instruction to push your work.</p><pre>git init<br>git add .<br>git commit -m “first app”<br>heroku git:remote -a name_of_your_app<br>git push heroku master</pre><p>One more thing has to be done. Log in to your heroku account, then click on your app, go to Resources, click on the edit tab, activate it, and then click confirm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dj6Y4awfH_O5GJYJtAiClg.jpeg" /></figure><p>Well done, Your Python code is now running, and you can use Discord to see if the bot is online.</p><p><strong>Thank you for your reading.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbdb590266e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>