<?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: Luis</title>
    <description>The latest articles on DEV Community by Luis (@luisfun).</description>
    <link>https://dev.to/luisfun</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%2F1409621%2Ffee8ecf5-567c-4ae6-8268-f3f91cd99714.png</url>
      <title>DEV Community: Luis</title>
      <link>https://dev.to/luisfun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/luisfun"/>
    <language>en</language>
    <item>
      <title>Plugin for Cloudflare AI API</title>
      <dc:creator>Luis</dc:creator>
      <pubDate>Tue, 16 Apr 2024 20:18:32 +0000</pubDate>
      <link>https://dev.to/luisfun/plugin-for-cloudflare-ai-api-4e5f</link>
      <guid>https://dev.to/luisfun/plugin-for-cloudflare-ai-api-4e5f</guid>
      <description>&lt;p&gt;I created a module for &lt;a href="https://github.com/LuisFun/cloudflare-ai-plugin"&gt;&lt;code&gt;@luisfun/cloudflare-ai-plugin&lt;/code&gt;&lt;/a&gt;, and this is its introduction.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;This plugin enables you to write REST API or AI Gateway in the same way as binding AI (env.AI.run) when using Cloudflare's Workers AI.&lt;br&gt;
Also, it supports Typescript.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Use
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Install&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i @luisfun/cloudflare-ai-plugin
npm i &lt;span class="nt"&gt;-D&lt;/span&gt; @cloudflare/ai &lt;span class="c"&gt;# When using TypeScript&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Coding&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Ai&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@luisfun/cloudflare-ai-plugin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// const ai = env.AI&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ai&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Ai&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AI_API_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AI_API_TOKEN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://developers.cloudflare.com/ai-gateway/providers/workersai/"&gt;How to get API URL and TOKEN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are also some extensions available.&lt;br&gt;
Here, I will include the cache control of the Gateway.&lt;br&gt;
If you are interested in other extensions, please check the repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cf-skip-cache&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cf-cache-ttl&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Repository
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/LuisFun/cloudflare-ai-plugin"&gt;https://github.com/LuisFun/cloudflare-ai-plugin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>plugin</category>
      <category>cloudflare</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Discord Bot with Cloudflare AI</title>
      <dc:creator>Luis</dc:creator>
      <pubDate>Sat, 13 Apr 2024 12:27:14 +0000</pubDate>
      <link>https://dev.to/luisfun/discord-bot-with-cloudflare-ai-e69</link>
      <guid>https://dev.to/luisfun/discord-bot-with-cloudflare-ai-e69</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/devteam/join-us-for-the-cloudflare-ai-challenge-3000-in-prizes-5f99"&gt;Cloudflare AI Challenge&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;Discord Bot for asking questions to AI or generating images&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;Discord Bot: &lt;a href="https://discord.com/oauth2/authorize?client_id=1227951760539258880&amp;amp;permissions=0&amp;amp;scope=bot"&gt;https://discord.com/oauth2/authorize?client_id=1227951760539258880&amp;amp;permissions=0&amp;amp;scope=bot&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj6o024ck6y06xhwun866.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj6o024ck6y06xhwun866.png" alt="Image Demo" width="590" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My Code
&lt;/h2&gt;

&lt;p&gt;Repository: &lt;a href="https://github.com/LuisFun/discord-bot-cloudflare-ai-challenge"&gt;https://github.com/LuisFun/discord-bot-cloudflare-ai-challenge&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Journey
&lt;/h2&gt;

&lt;p&gt;I realized that most of the projects that have been submitted so far were in the form of websites, as we are in the latter half of the challenge period.&lt;br&gt;
Therefore, as a different approach, I tried creating a simple application using a discord bot.&lt;/p&gt;

&lt;p&gt;The main thing I worked on during the challenge period was creating and publishing a plugin package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stacks&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cloudflare

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.cloudflare.com/workers/"&gt;Workers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.cloudflare.com/workers-ai/"&gt;Workers AI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.cloudflare.com/ai-gateway/"&gt;AI Gateway&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;a href="https://discord.com/developers/docs/tutorials/hosting-on-cloudflare-workers"&gt;Discord Bot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://discord-hono.luis.fun/"&gt;&lt;code&gt;discord-hono&lt;/code&gt;&lt;/a&gt; (I made it)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/LuisFun/cloudflare-ai-plugin"&gt;&lt;code&gt;@luisfun/cloudflare-ai-plugin&lt;/code&gt;&lt;/a&gt; (I made it)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;@luisfun/cloudflare-ai-plugin&lt;/code&gt; can do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI Gateway - You can code the AI Gateway in the same way as the workers AI.&lt;/li&gt;
&lt;li&gt;MD Translator - You can translate while maintaining the structure of Markdown to some extent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using the module and plugin that I created, the server code for the Bot was 80 lines, and the command registration code for the Bot was 50 lines. In this way, I was able to create a Bot with such a small amount of code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multiple Models and/or Triple Task Types&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;All Text Generation models&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;All Text to Image models&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@cf/meta/m2m100-1.2b&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the language set in the discord is not English, the default behavior is to process as follows&lt;br&gt;
&lt;code&gt;Translate prompt&lt;/code&gt; -&amp;gt; &lt;code&gt;Generate text or image&lt;/code&gt; (-&amp;gt; &lt;code&gt;Translate text&lt;/code&gt;)&lt;br&gt;
In the second translation, I made sure not to break the markdown format.&lt;/p&gt;

</description>
      <category>cloudflarechallenge</category>
      <category>devchallenge</category>
      <category>ai</category>
    </item>
    <item>
      <title>Image Generator with Cloudflare</title>
      <dc:creator>Luis</dc:creator>
      <pubDate>Thu, 11 Apr 2024 08:34:19 +0000</pubDate>
      <link>https://dev.to/luisfun/image-generator-with-cloudflare-4kaf</link>
      <guid>https://dev.to/luisfun/image-generator-with-cloudflare-4kaf</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/devteam/join-us-for-the-cloudflare-ai-challenge-3000-in-prizes-5f99"&gt;Cloudflare AI Challenge&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;Simple App for Text to Image.&lt;br&gt;
In addition, image modification using img2img or inpainting models.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;Web Site: &lt;a href="https://ai-paint.luis.fun"&gt;https://ai-paint.luis.fun&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7qsfa46pttzxzowwc37h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7qsfa46pttzxzowwc37h.png" alt="Demo" width="800" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My Code
&lt;/h2&gt;

&lt;p&gt;Repository: &lt;a href="https://github.com/LuisFun/ai-paint"&gt;https://github.com/LuisFun/ai-paint&lt;/a&gt;&lt;br&gt;
License: AGPL-3.0&lt;/p&gt;

&lt;h2&gt;
  
  
  Journey
&lt;/h2&gt;

&lt;p&gt;I had been developing an app that could generate images on a website even before the challenge started. This time, I applied because it roughly matched the entry requirements of the challenge.&lt;/p&gt;

&lt;p&gt;During the challenge period, I worked on the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Utilized Workers AI through the AI Gateway&lt;/li&gt;
&lt;li&gt;Enabled the enlargement of uploaded image&lt;/li&gt;
&lt;li&gt;Implemented the inpainting mode&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Stacks&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cloudflare

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.cloudflare.com/pages/"&gt;Pages / Functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.cloudflare.com/workers-ai/"&gt;Workers AI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.cloudflare.com/ai-gateway/"&gt;AI Gateway&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.cloudflare.com/turnstile/"&gt;Turnstile&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kit.svelte.dev/"&gt;Svelte kit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.skeleton.dev/"&gt;Skeleton&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/LuisFun/cloudflare-ai-plugin"&gt;&lt;code&gt;@luisfun/cloudflare-ai-plugin&lt;/code&gt;&lt;/a&gt; (I made it)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The two things I focused on when creating the frontend were eliminating unnecessary UI and making the UI more understandable.&lt;/p&gt;

&lt;p&gt;What I kept in mind when creating the backend was to protect the AI-related API from bot attacks.&lt;br&gt;
I achieved this using the AI Gateway and Turnstile.&lt;/p&gt;

&lt;p&gt;AI Gateway can utilize Real-time logs, Caching, and Rate-limiting.&lt;br&gt;
Turnstile determines whether it's a human or a bot, and blocks appropriately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multiple Models and/or Triple Task Types&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;@cf/lykon/dreamshaper-8-lcm&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@cf/runwayml/stable-diffusion-v1-5-img2img&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@cf/runwayml/stable-diffusion-v1-5-inpainting&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@cf/meta/m2m100-1.2b&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the language of the Prompt is specified as something other than EN, the Prompt is first translated into English using m2m100-1.2b, and then the translated Prompt is input in image generation.&lt;br&gt;
(You can select this if the default language of your browser is not EN.)&lt;/p&gt;

&lt;p&gt;The img2img model automatically switches when an image is uploaded.&lt;/p&gt;

&lt;p&gt;The inpainting model automatically switches when a mask is added.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P.S.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The project's code includes code to display Adsense.&lt;br&gt;
Originally, considering long-term operation, it was added as one means to recover operating costs.&lt;br&gt;
However, considering the submission requirements, the ads are hidden during the challenge period (throughout April).&lt;/p&gt;




&lt;p&gt;(Apr 13) I have installed the &lt;a href="https://github.com/LuisFun/cloudflare-ai-plugin"&gt;&lt;code&gt;@luisfun/cloudflare-ai-plugin&lt;/code&gt;&lt;/a&gt; that was created in &lt;a href="https://dev.to/luisfun/discord-bot-with-cloudflare-ai-e69"&gt;this project&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>cloudflarechallenge</category>
      <category>devchallenge</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
