<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Davide Fornelli</title>
    <description>The latest articles on DEV Community by Davide Fornelli (@davidefornelli).</description>
    <link>https://dev.to/davidefornelli</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F364962%2Ffdf068b0-2eb6-4d1a-a43a-a21cb710592c.png</url>
      <title>DEV Community: Davide Fornelli</title>
      <link>https://dev.to/davidefornelli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davidefornelli"/>
    <language>en</language>
    <item>
      <title>Running LLMs on Android: A Step-by-Step Guide</title>
      <dc:creator>Davide Fornelli</dc:creator>
      <pubDate>Fri, 10 May 2024 20:41:31 +0000</pubDate>
      <link>https://dev.to/davidefornelli/running-llms-on-android-a-step-by-step-guide-3ekc</link>
      <guid>https://dev.to/davidefornelli/running-llms-on-android-a-step-by-step-guide-3ekc</guid>
      <description>&lt;p&gt;In this blog post, we'll explore how to install and run the Ollama language model on an Android device using Termux, a powerful terminal emulator. This tutorial is designed for users who wish to leverage the capabilities of large language models directly on their mobile devices without the need for a desktop environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install F-Droid
&lt;/h3&gt;

&lt;p&gt;F-Droid is an installable catalogue of FOSS (Free and Open Source Software) applications for the Android platform. Download and install the F-Droid app from &lt;a href="https://f-droid.org/"&gt;https://f-droid.org/&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Install Termux
&lt;/h3&gt;

&lt;p&gt;Once F-Droid is installed, open it and search for Termux. Install Termux, which will serve as your Linux environment on Android.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Update and Upgrade Packages
&lt;/h3&gt;

&lt;p&gt;Open Termux and update its package repository to ensure you have access to the latest software versions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pkg update
pkg upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Install Proot-Distro and Debian
&lt;/h3&gt;

&lt;p&gt;Proot-Distro allows you to run different Linux distributions within Termux. Install it using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pkg &lt;span class="nb"&gt;install &lt;/span&gt;proot-distro
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pd &lt;span class="nb"&gt;install &lt;/span&gt;debian
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more details, visit the &lt;a href="https://github.com/termux/proot-distro"&gt;Proot-Distro GitHub page&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Login to a Linux Distribution
&lt;/h3&gt;

&lt;p&gt;For this tutorial, we will use Debian. Log in to your Debian environment with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pd login debian
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6: Install Tmux
&lt;/h3&gt;

&lt;p&gt;Tmux is a terminal multiplexer that allows you to run multiple terminal sessions simultaneously:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apt update
apt upgrade
apt &lt;span class="nb"&gt;install &lt;/span&gt;tmux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 7: Install Ollama
&lt;/h3&gt;

&lt;p&gt;Within the Debian environment, download and install Ollama:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://ollama.com/install.sh | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script installs Ollama and its dependencies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 8: Create a New Tmux Session
&lt;/h3&gt;

&lt;p&gt;Start a new tmux session dedicated to running Ollama:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tmux new &lt;span class="nt"&gt;-s&lt;/span&gt; llm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 9: Run Ollama Server
&lt;/h3&gt;

&lt;p&gt;In the tmux session, start the Ollama server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ollama serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 10: Create a New Pane in Tmux
&lt;/h3&gt;

&lt;p&gt;Split the current window into two panes by pressing &lt;code&gt;Ctrl+b "&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 11: Run an Ollama Model
&lt;/h3&gt;

&lt;p&gt;In the new pane, run a specific Ollama model. For example, to run the Gemma 2B model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ollama run gemma:2b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Depending on your device, you can run also run phi3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ollama run phi3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 12: Test the Model
&lt;/h3&gt;

&lt;p&gt;Once the model is running, you can interact with it directly from the terminal. Enter prompts and observe the model's responses, effectively using your Android device as a powerful AI tool.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;This tutorial provides a foundation for exploring further applications of LLMs on mobile devices, opening up possibilities for mobile-based AI development and experimentation.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>ollama</category>
      <category>androind</category>
    </item>
    <item>
      <title>Summarize a text with Azure Text Analytics in Python</title>
      <dc:creator>Davide Fornelli</dc:creator>
      <pubDate>Thu, 11 Nov 2021 06:00:00 +0000</pubDate>
      <link>https://dev.to/davidefornelli/how-to-use-python-chef-49l6</link>
      <guid>https://dev.to/davidefornelli/how-to-use-python-chef-49l6</guid>
      <description>&lt;h2&gt;
  
  
  Source code
&lt;/h2&gt;

&lt;p&gt;List of used gists.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chef
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Ingredients
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;The following example is based on specific commits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chef

&lt;ul&gt;
&lt;li&gt;commit: ac2a18c678a457b59535272a8d95cdc0c58ea02c&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Ingredients

&lt;ul&gt;
&lt;li&gt;commit: b01c0ab18d3d50d7e2836b71e22749e805fadac6&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Notebook
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%pip install httpimport


# - httpimport

# Description:
# Summarize a list of texts with Azure Text Analytics

import httpimport

# GitHub username
gist_user = 'Comm3'


gist_chef_id = '1bc116f05d09e598a1a2dcfbb0e2fc22'


gist_url_chef = f"https://gist.githubusercontent.com/{gist_user}/{gist_chef_id}/raw"
with httpimport.remote_repo(['chef'], gist_url_chef):
    import chef


gist_ingredients_id = '5c75b7cdea330d15dcd93adbb08648c3'
gist_ingredients_url = f"https://gist.githubusercontent.com/{gist_user}/{gist_ingredients_id}/raw"

chef.process_ingredients(
    gist_ids=[(gist_ingredients_id, ['az_cs_summarization.py'])]
)
with httpimport.remote_repo(['az_cs_summarization'], gist_ingredients_url):
    import az_cs_summarization


Requirement already satisfied: azure-ai-textanalytics==5.2.0b2 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (5.2.0b2)
Requirement already satisfied: azure-common~=1.1 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from azure-ai-textanalytics==5.2.0b2) (1.1.27)
Requirement already satisfied: six&amp;gt;=1.11.0 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from azure-ai-textanalytics==5.2.0b2) (1.16.0)
Requirement already satisfied: azure-core&amp;lt;2.0.0,&amp;gt;=1.19.1 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from azure-ai-textanalytics==5.2.0b2) (1.20.1)
Requirement already satisfied: msrest&amp;gt;=0.6.21 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from azure-ai-textanalytics==5.2.0b2) (0.6.21)
Requirement already satisfied: requests&amp;gt;=2.18.4 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from azure-core&amp;lt;2.0.0,&amp;gt;=1.19.1-&amp;gt;azure-ai-textanalytics==5.2.0b2) (2.26.0)
Requirement already satisfied: requests-oauthlib&amp;gt;=0.5.0 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from msrest&amp;gt;=0.6.21-&amp;gt;azure-ai-textanalytics==5.2.0b2) (1.3.0)
Requirement already satisfied: certifi&amp;gt;=2017.4.17 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from msrest&amp;gt;=0.6.21-&amp;gt;azure-ai-textanalytics==5.2.0b2) (2021.10.8)
Requirement already satisfied: isodate&amp;gt;=0.6.0 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from msrest&amp;gt;=0.6.21-&amp;gt;azure-ai-textanalytics==5.2.0b2) (0.6.0)
Requirement already satisfied: idna&amp;lt;4,&amp;gt;=2.5 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from requests&amp;gt;=2.18.4-&amp;gt;azure-core&amp;lt;2.0.0,&amp;gt;=1.19.1-&amp;gt;azure-ai-textanalytics==5.2.0b2) (3.3)
Requirement already satisfied: urllib3&amp;lt;1.27,&amp;gt;=1.21.1 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from requests&amp;gt;=2.18.4-&amp;gt;azure-core&amp;lt;2.0.0,&amp;gt;=1.19.1-&amp;gt;azure-ai-textanalytics==5.2.0b2) (1.26.7)
Requirement already satisfied: charset-normalizer~=2.0.0 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from requests&amp;gt;=2.18.4-&amp;gt;azure-core&amp;lt;2.0.0,&amp;gt;=1.19.1-&amp;gt;azure-ai-textanalytics==5.2.0b2) (2.0.7)
Requirement already satisfied: oauthlib&amp;gt;=3.0.0 in /home/daforne/.pyenv/versions/3.7.9/envs/global379/lib/python3.7/site-packages (from requests-oauthlib&amp;gt;=0.5.0-&amp;gt;msrest&amp;gt;=0.6.21-&amp;gt;azure-ai-textanalytics==5.2.0b2) (3.1.1)


texts = [
    '''
 A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically. Modern computers can perform generic sets of operations known as programs. These programs enable computers to perform a wide range of tasks. A computer system is a "complete" computer that includes the hardware, operating system (main software), and peripheral equipment needed and used for "full" operation. This term may also refer to a group of computers that are linked and function together, such as a computer network or computer cluster.
 A broad range of industrial and consumer products use computers as control systems. Simple special-purpose devices like microwave ovens and remote controls are included, as are factory devices like industrial robots and computer-aided design, as well as general-purpose devices like personal computers and mobile devices like smartphones. Computers power the Internet, which links hundreds of millions of other computers and users.
 Early computers were meant to be used only for calculations. Simple manual instruments like the abacus have aided people in doing calculations since ancient times. Early in the Industrial Revolution, some mechanical devices were built to automate long tedious tasks, such as guiding patterns for looms. More sophisticated electrical machines did specialized analog calculations in the early 20th century. The first digital electronic calculating machines were developed during World War II. The first semiconductor transistors in the late 1940s were followed by the silicon-based MOSFET (MOS transistor) and monolithic integrated circuit (IC) chip technologies in the late 1950s, leading to the microprocessor and the microcomputer revolution in the 1970s. The speed, power and versatility of computers have been increasing dramatically ever since then, with transistor counts increasing at a rapid pace (as predicted by Moore's law), leading to the Digital Revolution during the late 20th to early 21st centuries.
 Conventionally, a modern computer consists of at least one processing element, typically a central processing unit (CPU) in the form of a microprocessor, along with some type of computer memory, typically semiconductor memory chips. The processing element carries out arithmetic and logical operations, and a sequencing and control unit can change the order of operations in response to stored information. Peripheral devices include input devices (keyboards, mice, joystick, etc.), output devices (monitor screens, printers, etc.), and input/output devices that perform both functions (e.g., the 2000s-era touchscreen). Peripheral devices allow information to be retrieved from an external source and they enable the result of operations to be saved and retrieved.
 '''
]

summary_text = az_cs_summarization.summarize(
    texts=texts,
    cs_endpoint='https://westus2.api.cognitive.microsoft.com/',
    cs_key='use_your_own',
    language='en'
)

print(summary_text)


[ExtractSummaryResult(id=0, sentences=[SummarySentence(text=A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically., rank_score=1.0, offset=9, length=120), SummarySentence(text=These programs enable computers to perform a wide range of tasks., rank_score=0.95, offset=205, length=65), SummarySentence(text=A broad range of industrial and consumer products use computers as control systems., rank_score=0.79, offset=583, length=83)], warnings=[], statistics=None, is_error=False)]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>azuretextanalytics</category>
      <category>python</category>
      <category>jupyter</category>
      <category>recipe</category>
    </item>
  </channel>
</rss>
