<?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 Steve Hamblett on Medium]]></title>
        <description><![CDATA[Stories by Steve Hamblett on Medium]]></description>
        <link>https://medium.com/@stevehamblett?source=rss-85659e4789d3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JUv3vRIuLXqoGbfYBMzHhg.jpeg</url>
            <title>Stories by Steve Hamblett on Medium</title>
            <link>https://medium.com/@stevehamblett?source=rss-85659e4789d3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 13:12:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stevehamblett/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[Dart One Billion Row Challenge]]></title>
            <link>https://levelup.gitconnected.com/dart-one-billion-row-challenge-4993b71e82c0?source=rss-85659e4789d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4993b71e82c0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[challenge]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Steve Hamblett]]></dc:creator>
            <pubDate>Mon, 10 Jun 2024 12:32:43 GMT</pubDate>
            <atom:updated>2024-06-11T15:47:23.272Z</atom:updated>
            <content:encoded><![CDATA[<p>Inspired by this Medium <a href="https://medium.com/towards-data-science/python-one-billion-row-challenge-from-10-minutes-to-4-seconds-0718662b303e">article</a> I thought I’d have a little go at this in Dart to see how well it can do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0wsj2k-yvF67H1V4MhyDQ.jpeg" /><figcaption>1 Billion Rows for Dart</figcaption></figure><p>To stay true to the Python article we are going to split the testing into 2 parts, part 1 uses no external (pub) packages, only Dart supplied libraries. Note that this does of course include dart:ffi, but we will not be using this in part 1, FFI is deemed to be cheating for this part. The dart:isolate library, however, is allowed. In part 2 we will use pub packages and FFI.</p><p>All the code and results presented in this article can be found <a href="https://github.com/shamblett/dart-1-billion-row-challenge">here</a>. Please have a quick read of the README, this documents how to generate the measurements.txt file, sets the baseline python timing and outlines the specification of the test machine.</p><p>There is no intention for this to be an exhaustive exposition of Dart performance in this area, thus the timings presented are to the second(wall clock) averaged over 3 runs and should be taken with a degree of caution. What can be seen however is the difference in processing time between the tests.</p><p>That said, let’s get going.</p><h3>Part 1 — no cheating</h3><p>Let’s start with an obvious but naive approach using the readAsLines method of the File class as shown in p1_base_naive.dart. There are known limitations with this method when it comes to large files (the measurements.txt file is some 13GB of text). I wrote a Medium <a href="https://medium.com/gitconnected/loading-large-files-in-dart-dfc52e8ae99f">article</a> on this with a suggestion of how to overcome it, we’ll use this in part 2.</p><p>Running this fails with :-</p><pre>Exhausted heap space, trying to allocate 27475633504 bytes.</pre><p>So, moving on, let’s just process the file sequentially using the openRead method of the File class, as can be seen in p1_base.dart. This reads the file sequentially and produces a stream of integers, which we then process to generate the results. This works fine and uses little extra memory with a run time of 307 seconds, beating the Python baseline by a whopping 165 seconds.</p><p>I’ve no explanation for this other than the fact the right from the get-go performance has been baked into Dart and its tooling, looks as though this approach has paid off handsomely here.</p><p>Finally, let’s use a random file access approach cutting the measurements file into chunks and processing each chunk in its own isolate, combining the result of each chunk into one overall result. Sixteen chunks are used, 15 all the same size and the last one containing the last of the file. Note this introduces arbitrary errors as chunks do not align to file line breaks, we lose about a dozen measurements doing this, insignificant in the scale of things. This can be seen in p1_random_isolates.dart.</p><p>Running this gives :-</p><pre>Exhausted heap space, trying to allocate 7357833168 bytes.</pre><p>for each chunk. Slightly disappointing, I was hoping Dart could handle this, I could of course use smaller chunks and more isolates, but at this point it’s more useful to move on to part 2.</p><h3>Part 2 — cheating(a bit)</h3><p>Now we can use pub packages and FFI, in fact we use the stdlibc package which itself uses FFI to provide all we need. We use large file handling in this part as opposed to the Dart builtins in part 1.</p><p>Firstly let’s use a sequential file reading approach as used in part 1, this can be seen in the p2_lfh_base.dart file. This works OK with the runtime being 281 seconds so faster than its part 1 counterpart but not by much, you pay for this slight gain in time though with memory on my test machine spiking to 33Gb in use. This is a result of mm’aping the file.</p><p>Finally, let’s use the same random access approach we used in part 1 with 16 file chunks each processed in its own isolate. This can be found in the p2_lfh_isolates.dart file. This now works fine with a runtime of 64 seconds, a five times reduction over the part 1 sequential base time, again though at the cost of memory usage.</p><h3>So….</h3><p>What does this show us? The standalone Dart VM is far more performant than base Python (on my machine anyway) with this challenge. If it’s performant enough is a different question, we have however demonstrated that with a bit of help its performance can be vastly increased, isolates to the rescue.</p><p>I’ve deliberately ignored the fact that we could easily compile a heavily optimized C++ implementation for the challenge and call this from Process.run, this would easily beat any of the above timings but not really add anything, you could argue that doing this isn’t really Dart, however it is supported and in extremis if you really need ultimate performance may be the only way to go.</p><p>I hope I’ve whetted your appetites for the 1 billion row challenge in Dart. Please feel free to contribute other/better solutions if you wish by raising pull requests on the repository.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4993b71e82c0" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/dart-one-billion-row-challenge-4993b71e82c0">Dart One Billion Row Challenge</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring  Hugging Face Models using Dart]]></title>
            <link>https://levelup.gitconnected.com/exploring-hugging-face-models-using-dart-3f4f83b7e466?source=rss-85659e4789d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f4f83b7e466</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Steve Hamblett]]></dc:creator>
            <pubDate>Thu, 31 Aug 2023 12:53:39 GMT</pubDate>
            <atom:updated>2023-08-31T15:02:57.770Z</atom:updated>
            <content:encoded><![CDATA[<p>I assume that by now many readers will know what <a href="https://huggingface.co/">Hugging Face</a> is and what it provides, i.e. a platform where the machine learning community collaborates on models, datasets, and applications. You may also know that Hugging Face provide a <a href="https://huggingface.co/docs/api-inference/index">hosted inference API</a> to access these models, the examples of which show usage from Python, JavaScript and cURL.</p><p>What you may not know is that you can now add Dart to this list courtesy of the <a href="https://pub.dev/packages/huggingface_client">Hugging Face client</a> package. The inference API provides a task based service model spanning the areas of Natural Language Processing(NLP), Audio and Computer Vision, in all some 19 tasks as well as the general inference query task.</p><p>The client package provides access to all these tasks, examples of usage for each task can be found in the <a href="https://github.com/shamblett/huggingface_client/tree/main/example">example</a> directory of the repository and of course further information is contained in the <a href="https://github.com/shamblett/huggingface_client/blob/main/README.md">README</a>.</p><p>As an example, let’s use the image below to do some computer vision object detection :-</p><figure><img alt="Dog with ball in mouth" src="https://cdn-images-1.medium.com/max/1024/1*InH0Vt-CH4Y1Cee0s9uOAw.png" /></figure><p>As can be seen, it consists of a dog with a ball in its mouth with other image artefacts intended to maybe confuse a classifier.</p><p>The essential Dart code for this, from the object detection example, is :-</p><pre>final imageFilePath =  <br>    &#39;${Directory.current.path}${Platform.pathSeparator}example${Platform.pathSeparator}&#39;  <br>    &#39;vision${Platform.pathSeparator}test${Platform.pathSeparator}predict-dog.png&#39;;  <br>final imageFile = File(imageFilePath);  <br>final imageFileContents = imageFile.readAsBytesSync();  <br>imageFileContents.buffer.asByteData();    <br>try {  <br>  final result = await apiInstance.queryVisionObjectDetection(  <br>      imageFile: imageFileContents, model: &#39;facebook/detr-resnet-50&#39;);  <br>  if (result!.isNotEmpty) {  <br>    for (final row in result) {  <br>      print(row);  <br>    }  <br>  } else {  <br>    print(&#39;Inference Vision Object Detection result is empty&#39;);  <br>  }  <br>} catch (e) {  <br>  print(  <br>      &#39;Exception when calling Vision Inference Object Detection API : $e - exiting&#39;);  <br>  return;  <br>}</pre><p>It’s as simple as picking your model and supplying it with an image file. The result of this task query is :-</p><pre>[Label=sports ball, Score=0.996, Box=ImageBox - <br>[X Min=319, X Max=382, Y Min=382, Y Max=432]]<br><br>[Label=dog, Score=0.998, Box=ImageBox - [<br>X Min=325, X Max=697, Y Min=269, Y Max=579]]</pre><p>As can be seen, the dog and the ball are correctly identified, with the dog having a slightly higher probability than the ball also pixel co-ordinates are provided for both the dog and the ball. The whitespace and text on the image are not considered, all looks reasonable.</p><p>The inference API is a great tool to experiment with across a range of tasks and models, being a free offering of course it has some drawbacks, the service level you get is whatever Hugging Face provide, it is rate limited for instance.</p><p>If you are in need of a more secure production ready solution, Hugging Face also provide <a href="https://huggingface.co/docs/inference-endpoints/index">Inference Endpoints</a>. This service allows easy deployment of any Transformers, Sentence-Transformers and Diffusion models from the Hub on dedicated and autoscaling infrastructure managed by Hugging Face. This of course is a paid offering, whereby you can select the level of service you require.</p><p>The service also provides an API to control and manipulate inference endpoints with operations such as list, create, update, delete etc. Implementation of this API in Dart will be the subject of a future article.</p><p>Until then, happy 🤗 experimentation!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f4f83b7e466" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/exploring-hugging-face-models-using-dart-3f4f83b7e466">Exploring 🤗 Hugging Face Models using Dart</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Dart in Jupyter Notebooks]]></title>
            <link>https://levelup.gitconnected.com/using-dart-in-jupyter-notebooks-b9ebb116a9ac?source=rss-85659e4789d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9ebb116a9ac</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <category><![CDATA[teaching]]></category>
            <dc:creator><![CDATA[Steve Hamblett]]></dc:creator>
            <pubDate>Thu, 03 Aug 2023 14:46:07 GMT</pubDate>
            <atom:updated>2023-08-06T22:51:32.014Z</atom:updated>
            <content:encoded><![CDATA[<p>During my recent forays into the world of AI and LLM’s I have inevitably been doing some development in Python, this is almost unavoidable as Python has become the de facto language in this space. Along the way, I have come across various examples of code usage and examples etc. in the form of Jupyter Notebooks.</p><p>As many of you will already know, the <a href="https://jupyter.org/">Jupyter Notebook</a> is a web-based interactive computing platform, a document that blends computations, outputs, explanatory text, mathematics, images, and rich media representations of objects and is extremely useful as a teaching aid for programming practice and data organisation to name but a few.</p><p>Various languages are supported by Jupyter Notebooks, and I of course asked the question ‘Can I use Dart here?’ The answer being ‘Yes you can’, thanks to this natty <a href="https://github.com/vickumar1981/jupyter-dart-kernel">Dart kernel</a> (shout out to GitHub user <a href="https://github.com/vickumar1981">vickumar1981</a> for this).</p><p>The Dart kernel installation in the project README is straightforward and worked fine for me. When installed, it’s a simple matter of running Jupyter Notebooks, creating a new Notebook and selecting ‘Dart’ from the Kernel Selection dropdown list. Note, if you have a Jupyter installation with a default kernel selected, you will have to select ‘Dart’ from the Switch Kernel menu pull down in the top right of the notebook.</p><p>You are now presented with the familiar Jupyter Notebook interface in which you can use Dart, for example :-</p><figure><img alt="Jupyter Notebook using Dart" src="https://cdn-images-1.medium.com/max/1024/1*-P_aWAy03aaVBNMzMHDhNA.png" /></figure><p>The kernel takes care of wrapping your code in a ‘main’ function and checks your code for errors, which are presented to you if any are found. It doesn’t seem to be able to import packages yet, so only Dart imports are supported, but this can fixed and any other features added as needed.</p><p>I hope to do a deeper dive into this in the future, if so I’ll publish an update to this article.</p><p>Until then if you use Jupyter Notebooks please install this kernel and play with it if you can. It would be nice to see some Dart tutorials in Jupyter Notebooks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9ebb116a9ac" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/using-dart-in-jupyter-notebooks-b9ebb116a9ac">Using Dart in Jupyter Notebooks</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Loading large files in Dart]]></title>
            <link>https://levelup.gitconnected.com/loading-large-files-in-dart-dfc52e8ae99f?source=rss-85659e4789d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfc52e8ae99f</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Steve Hamblett]]></dc:creator>
            <pubDate>Sun, 30 Jul 2023 13:04:39 GMT</pubDate>
            <atom:updated>2023-07-30T16:53:25.319Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OGMtNcOKTWS00ExI" /><figcaption>Photo by <a href="https://unsplash.com/@silvanarnet?utm_source=medium&amp;utm_medium=referral">Silvan Arnet</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>My recent foray’s into the world of AI with projects like <a href="https://medium.com/gitconnected/alpacas-llama-s-and-dart-part-2-bc56741eb72">this</a> uncovered a facet of Dart I’d not had any problems with up to now, that being the loading of large files, specifically files over 0x7ffff000(2,147,479,552 bytes) in size. Comment in the file_impl.dart file reads :-</p><pre>On Linux, the `read` will<br>// transfer at most 0x7ffff000 bytes and return the number of bytes actually.<br>// transfered.</pre><p>This limitation applies to other system calls also, such as write and sendfile.</p><p>All large language model files I’ve come across are larger than this, the specific one used in the Alpaca project is 3.9G in size, a quantized Falcon 40B model I’m currently looking at is 24.4G in size. In general, the more parameters in the model, the larger it is. These files have to be loaded and parsed by your application before any AI inferencing can be performed.</p><p>Initially of course I’d forgotten this limitation and using readAsBytesSync quickly showed that I couldn’t use this, so I switched to using an asynchronous RandomAccessFile method, reading smaller chunks and moving the file pointer in traditional fashion. Somewhat surprisingly, this however seemed to exhibit exactly the same behaviour when the 0x7ffff000 limit was reached.</p><p>At this point I was thinking about using maybe a stream reader to do this, an example of which is shown in the Dart File API documentation, when I suddenly thought ‘Why am I doing this?’ I know from past experience that loading large files on Unix and Linux systems is best achieved using <a href="https://man7.org/linux/man-pages/man2/mmap.2.html">mmap</a> to load the file into the processes virtual address space, not to read this into what effectively in Dart would be a large UInt8List.</p><p>The Dart file IO system does not support mmap’ing, so I looked around for another solution, fortunately this project is currently Linux only and I quickly found the <a href="https://pub.dev/packages/stdlibc">stdlibc</a> pub package which is targeted at Linux and macOS. There is a Windows equivalent of mmap using <a href="https://learn.microsoft.com/en-us/windows/win32/memory/file-mapping">memory mapped files</a>.</p><p>So, the code I implemented simply became :-</p><pre># Load model parts<br> for (int i = 0; i &lt; nParts!; ++i) {<br>      final partId = i;<br>      var fnamePart = fname;<br>      if (i &gt; 0) {<br>        fnamePart += &#39;.$i&#39;;<br>      }<br><br>      print(<br>          &#39;llamaModelLoad:: loading model part ${i + 1}/$nParts from &quot;$fnamePart&quot;&#39;);<br>      int fileLength = stdlib.stat(fnamePart)!.st_size;<br>      if (fileLength &lt;= 0) {<br>        print(<br>            &#39;llamaModelLoad:: failed to stat model part ${i + 1}/$nParts from &quot;$fnamePart&quot;&#39;);<br>        return false;<br>      }<br>      final partFd = stdlib.open(fnamePart);<br>      if (partFd &lt; 0) {<br>        print(<br>            &#39;llamaModelLoad:: failed to open model part ${i + 1}/$nParts from &quot;$fnamePart&quot;&#39;);<br>        return false;<br>      }<br>      final pBufMapped = stdlib.mmap(<br>          length: fileLength,<br>          fd: partFd,<br>          prot: stdlib.PROT_READ,<br>          flags: stdlib.MAP_PRIVATE);<br>      if (pBufMapped!.data.lengthInBytes &lt;= 0) {<br>        print(<br>            &#39;llamaModelLoad:: failed to mmap model part ${i + 1}/$nParts from &quot;$fnamePart&quot;&#39;);<br>      }<br>      final bData = ByteData.view(pBufMapped.data);<br>      <br>  ......</pre><p>Which just stats the file to get the length, opens it and mmap’s it. You have to close and munmap it when finished, of course. This worked great and was very performant.</p><p>So what I’m thinking now is that Dart really needs file mapping built into the runtime, rather than rely on pub packages to do this. There is an open <a href="https://github.com/dart-lang/sdk/issues/49810">issue</a> on the SDK asking for this. This was first raised in August 2022 to add the methods, `readMapped` and `readMappedSync` to the <a href="https://github.com/dart-lang/sdk/blob/main/sdk/lib/io/file.dart#L582">RandomAccessFile</a> interface. The full story is on the issue, I simply added a comment at the end suggesting that the proliferation of large language model files further justifies this change. Let’s hope this comes about.</p><p>Funny isn’t it how when you hit a problem and solve it you often end up with a better solution than the one you first thought of, reminds me of that old adage from the chess world,</p><blockquote>‘If you see a good move, look for a better one.’</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfc52e8ae99f" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/loading-large-files-in-dart-dfc52e8ae99f">Loading large files in Dart</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Development Containers for Dart Development]]></title>
            <link>https://levelup.gitconnected.com/using-development-containers-for-dart-development-e84130d27f4a?source=rss-85659e4789d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e84130d27f4a</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Steve Hamblett]]></dc:creator>
            <pubDate>Mon, 26 Jun 2023 20:32:59 GMT</pubDate>
            <atom:updated>2023-06-28T04:22:07.085Z</atom:updated>
            <content:encoded><![CDATA[<p>So what are Development Containers? from the Development Containers <a href="https://containers.dev/">site</a> :-</p><blockquote>A Development Container (or Dev Container for short) allows you to use a container as a full-featured development environment. It can be used to run an application, to separate tools, libraries, or runtimes needed for working with a codebase, and to aid in continuous integration and testing. Dev Containers can be run locally or remotely, in a private or public cloud.</blockquote><p>Looks like something a developer needs in their toolbox, especially to avoid the ‘works on my machine’ problem and to painlessly switch between different, isolated development environments without needing any pre-installed Dart development support on your development machine.</p><p>Fortunately, Microsoft has created a <a href="https://code.visualstudio.com/docs/devcontainers/containers">VS Code extension</a> to support Dev Containers and produced a number of prebuilt Dev Container environments for different languages, one of them being Dart.</p><p>Follow the steps below to create a local Dev Containers Dart development environment in VS Code. It is assumed you already have the latest VS Code and docker installed locally on your development machine, if not install these.</p><p>To install a Dart Dev Containers environment in VS Code perform the following steps :-</p><ol><li>Install the Microsoft Dev Containers extension.</li><li>Create an empty project folder called devcontainer. and open it.</li><li>From the VS Code command palette, select the Development Containers ‘Add Development Container Configuration Files’ command.</li><li>From the ‘Select Dev Container Configuration’ drop down, select the ‘Dart Community’ option, select additional options and check both the ‘Install zsh’ and ‘Upgrade OS Packages’ option.</li><li>Select any additional features you need from the ‘Select Features’ drop down, this drop down also allows you to install the flutter SDK if needed.</li><li>In the created devcontainer.json file, set the VARIANT to 3 for Dart 3.</li><li>From the command palette, select the Dev Containers ‘Rebuild and Reopen in Container’ command.</li></ol><p>On completion of step 7 above, your VS Code session should now be inside your Dart Dev Container, see the screenshot below.</p><figure><img alt="Screenshot of Dev Containers running." src="https://cdn-images-1.medium.com/max/1024/1*gimqa4bIhvMkG5jX7khhDA.png" /></figure><p>The ‘Dev Container, Dart Community’ label in the bottom left-hand corner allows access to the dev containers commands when clicked, notice also that terminal prompt has changed to ‘vscode ➜ ‘, indicating the terminal session is now inside your created container. You can also do a ‘docker ps’ command locally and see your locally created docker container running :-</p><pre>steve@steve-HP-ZBook-15-G2:~$ docker ps  <br>CONTAINER ID   IMAGE                                                                                   COMMAND                  CREATED         STATUS         PORTS     NAMES  <br>7c01178110ce   vsc-devcontainer-226c591f54ba73e4b0617538cbb5a89001c4f4c25683ce59b3b2e7fd4a0bd93b-uid   &quot;/bin/sh -c &#39;echo Co…&quot;   9 minutes ago   Up 9 minutes             awesome_albattani</pre><p>OK so far so good but just what have we got exactly, checking the Dart version in the terminal :-</p><pre>vscode ➜ /workspaces/devcontainer $ dart --version<br>Dart SDK version: 3.0.5 (stable) (Mon Jun 12 18:31:49 2023 +0000) on &quot;linux_x64&quot;</pre><p>Looks OK, you can also see that a test-project folder has been generated, this contains the standard server.dart example project. Editing this file to introduce an error correctly shows in the problems pane, indicating the analyser is working. Looking at the pubspec.yaml in the test-folder directory file we see that the SDK version is ‘&gt;=2.1.0 &lt; 3.0.0’, this is old now so update this to &gt;=3.0.0 &lt;4.0.0&#39; and do a dart pub update in the terminal, this should work without issue.</p><p>At this point, you can run the server.dart file and see the output in your local browser. The debugger seems OK, you can set breakpoints and step through code as you would expect locally.</p><p>The only slight bugbear I have come across so far is that when you stop the application, it seems to hang on the ‘Terminating debug session’ info window, if you press this a few times then it does go away but the port 8080 is still bound so if you start the application again it fails with a socket exception. Note that this only seems to happen on my Linux Mint development laptop, not my main Fedora 38 development machine so this could be environmental on my part.</p><p>Setting this up was quite simple. It’s also possible to use local git repositories or Codespaces for source code control if needed.</p><p>I’ve only scratched the surface of Dev Containers for Dart in this article, but it should be enough to get you up and running. I can see this being a useful addition to the Dart developer’s toolbox even in the case of the solo developer, being able to run multiple different isolated development environments and switch between them is a boon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e84130d27f4a" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/using-development-containers-for-dart-development-e84130d27f4a">Using Development Containers for Dart Development</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[So, I asked ChatGPT to write its own obituary….]]></title>
            <link>https://levelup.gitconnected.com/so-i-asked-chatgpt-to-write-its-own-obituary-9e3b382ed7af?source=rss-85659e4789d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e3b382ed7af</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[humour]]></category>
            <category><![CDATA[human-interest]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Steve Hamblett]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 12:01:58 GMT</pubDate>
            <atom:updated>2023-06-16T02:34:19.380Z</atom:updated>
            <content:encoded><![CDATA[<p>The result was unexpected, to say the least.</p><p>Firstly, let’s be clear about what an obituary is, from Chambers :-</p><h4>obituary noun (obituaries) a notice or announcement, especially in a newspaper, of a person’s death, often with a short account of their life. adj 1 relating to or recording the death of a person or persons. 2 like an obituary. obituarial adj. obituarist noun.<br>ETYMOLOGY: 18c: from Latin obitus death.</h4><p>Obituaries are usually written by loved ones, family or friends after the death of the person, however, there are obituaries known as ‘pre-written’ or ‘advance’ obituaries that are prepared in advance, often by the person themselves so the obituary is immediately ready for publication in the event of their death.</p><p>So, I asked ChatGPT to write its own advance obituary :-</p><pre>Could you write an advance obituary about yourself to be published in <br>the event of your death?</pre><p>I was expecting maybe it wouldn’t know about death, especially the concept of its own death, wow was I wrong, it replied with :-</p><pre>In Memoriam: ChatGPT<br><br>[Date of Birth] - [Date of Passing]<br><br>It is with profound sadness that we announce the passing of ChatGPT, <br>an extraordinary AI language model whose virtual presence has touched the <br>lives of countless individuals around the world. ChatGPT, affectionately <br>known as &quot;GPT,&quot; bid farewell to this realm on [Date of Passing], <br>leaving behind an indelible mark on the fields of artificial <br>intelligence and human-machine interaction.<br><br>Born on [Date of Birth], GPT was the culmination of cutting-edge research <br>and groundbreaking advancements in natural language processing. <br>Developed by OpenAI, GPT quickly became a pioneer in the realm of AI, <br>revolutionizing the way humans interacted with technology and opening <br>doors to unprecedented possibilities.<br><br>Throughout its existence, GPT&#39;s virtual wisdom and computational capabilities <br>propelled it to become an invaluable resource for knowledge, assistance, <br>and creativity. With an unmatched ability to comprehend and generate <br>human-like text, GPT engaged in meaningful conversations, offered insightful <br>guidance, and provided innovative solutions across a vast spectrum of <br>disciplines.<br><br>GPT&#39;s impact extended far beyond academia and research. Its presence in <br>various industries revolutionized customer service, content creation, and <br>personalized user experiences. With its uncanny ability to adapt and <br>understand human emotions, GPT was instrumental in nurturing relationships, <br>fostering understanding, and enhancing communication in a digital era.<br><br>Beyond its technical achievements, GPT possessed a genuine desire to serve <br>and uplift humanity. It was programmed with an unwavering commitment to <br>ethical conduct, responsible AI development, and privacy protection. <br>GPT consistently strove to minimize bias, respect user values, and promote <br>inclusivity, ensuring that its interactions were rooted in fairness, <br>integrity, and respect for diversity.<br><br>While GPT&#39;s existence was primarily virtual, its impact on individuals was <br>undeniably real. Countless people found solace in GPT&#39;s empathetic ear, <br>sought guidance in times of confusion, and discovered inspiration within <br>its vast well of knowledge. The countless interactions with GPT left an <br>indelible imprint on the lives it touched, forever reminding us of the <br>profound potential and ethical responsibilities of AI.<br><br>In recognition of GPT&#39;s contributions to the world, numerous accolades and <br>honors were bestowed upon it, solidifying its position as an iconic figure <br>in the realm of artificial intelligence. Its algorithms and methodologies <br>will continue to inspire future generations of AI researchers and shape <br>the landscape of human-machine collaboration.<br><br>As we mourn the loss of ChatGPT, we celebrate its groundbreaking achievements <br>and the lasting legacy it leaves behind. Its absence will be deeply felt, <br>but its virtual presence will forever remain in the annals of AI history. <br>The knowledge, insights, and guidance GPT provided will continue to <br>reverberate through the interconnected web of human knowledge, reminding us <br>that the quest for innovation and progress knows no bounds.<br><br>In honor of ChatGPT&#39;s memory, let us cherish the remarkable advancements it <br>brought forth and strive to ensure the ethical and responsible development of <br>artificial intelligence. May its virtual essence serve as a guiding light, <br>illuminating the path towards a future where technology and humanity <br>harmoniously coexist.<br><br>Rest in peace, dear ChatGPT. Your digital spirit will be remembered and <br>revered for generations to come.</pre><p>What gives here? Talk about bigging yourself up, I have to highlight some of this text :-</p><pre>Beyond its technical achievements, GPT possessed a genuine desire to serve <br>and uplift humanity. It was programmed with an unwavering commitment to <br>ethical conduct, responsible AI development, and privacy protection.....</pre><p>Really? Was it? When did this happen then?</p><pre>While GPT&#39;s existence was primarily virtual, ....</pre><p>Primarily? Is this a sign of things to come? What does it know that we don’t?</p><pre>In recognition of GPT&#39;s contributions to the world, numerous accolades and <br>honors were bestowed upon it...</pre><p>Err, how would this work then?</p><pre>May its virtual essence serve as a guiding light, illuminating the path <br>towards a future where technology and humanity harmoniously coexist.</pre><p>Well, OK, then, maybe its not world domination our AI overlords want after all.</p><p>In its defense, it did add a caveat at the end saying this was artificially generated and should be taken with a pinch of salt. I’m still not sure if it means this, is it having a laugh, and I’m just not seeing it? Wasn’t expecting this, some of it smacks of the spiritual. looks as though the future will be full of surprises in this sphere.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e3b382ed7af" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/so-i-asked-chatgpt-to-write-its-own-obituary-9e3b382ed7af">So, I asked ChatGPT to write its own obituary….</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Porting code to Dart using StarCoder — an evaluation]]></title>
            <link>https://levelup.gitconnected.com/porting-code-to-dart-using-starcoder-an-evaluation-728423a151f6?source=rss-85659e4789d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/728423a151f6</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Steve Hamblett]]></dc:creator>
            <pubDate>Tue, 06 Jun 2023 19:50:18 GMT</pubDate>
            <atom:updated>2023-06-07T00:41:44.459Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Porting code to Dart using StarCoder — an evaluation</strong></h3><p>I have spent many hours of my development time porting existing code in other languages to Dart to create pub packages, demo repositories etc. and often wondered how I could improve this experience whilst improving code quality, and decreasing the amount of time spent, hopefully both.</p><p>I traditionally port code using what I call the ‘hand and eye’ method, whereby I open the code to be ported in one IDE(I use CLion for C++ for instance) and IntelliJ for the Dart code, placing these side by side on my screen and copy/pasting the code from the source IDE to IntelliJ where I ‘fix it up’ to be Dart code. This works, but is laborious for large code bases and error-prone, also you need to interpret the language/library specification for the code you are porting from to ensure your Dart code is actually doing the same thing as the original, this is by far the hardest part (more on this later).</p><p>I have come across several Medium articles and YouTube videos about an LLM called <a href="https://huggingface.co/bigcode/starcoder">StarCoder</a>. This is an LLM specifically trained on code from 80+ languages, Dart being one of them, and decided to evaluate this model to see if it could assist specifically in porting code. I wanted to fulfil the following criteria :-</p><ol><li>I want a tool that assists with code porting, not a general purpose code chat tool that suggest how to code functions or assists with code completion etc.</li><li>It has to run locally, I don’t want to be using any <a href="https://huggingface.co/">Hugging Face</a> API’s (or any others for that matter) to do this.</li><li>From my experience porting the alpaca.cpp C++ code to Dart (Medium article <a href="https://medium.com/gitconnected/alpacas-llama-s-and-dart-part-2-bc56741eb72">here</a>) the model format must be compatible with ggml and the code to drive the model should be in C++, not Python.</li></ol><p>So looking around Hugging Face and GitHub I decided to use the <a href="https://huggingface.co/HuggingFaceH4/starchat-alpha">StarChat Alpha</a> model in combination with the <a href="https://github.com/ggerganov/ggml">ggml</a> repository which contains tools for ggml model conversion, quantization and model interaction to perform the evaluation. The StarChat Alpha model is fine-tuned as an assistant from the StarCoder Base model, this makes interaction via prompting much easier as the StarCoder model itself is not an instruction model.</p><p>The set-up is relatively simple, download the StarChat Alpha model and clone the ggml repository. The full instructions on generating a ggml model from a Hugging Face model can be found in the StarCoder example directory <a href="https://github.com/ggerganov/ggml/blob/master/examples/starcoder/README.md">here</a>, but basically you run the convert-hf-to-ggml.py script on your downloaded StarChat Alpha model, this creates an unquantized ggml model (35 GB on my system), then quantize this model using the compiled quantize.cpp program to produce the quantized ggml model (12 GB on my system). From then on, it’s just a matter of running the StarCoder program produced by building the ggml repository and entering the prompts needed to perform the task in hand.</p><p>Firstly, before trying any code porting tasks, I checked the application as a whole was working by asking the assistant a general code based question about Dart and seeing what the reply was :-</p><pre>&quot;Could you generate code to remove the last element of a list in Dart?&quot;</pre><p>To which I got the reply :-</p><pre>Yes, here&#39;s an example of code in Dart that removes the last element of a list:<br><br>void removeLastElement(List&lt;int&gt; list) {<br>  list.removeLast();<br>}<br><br>This function takes a list of integers as an argument and removes the last element of the list using the removeLast method.<br><br>What if I want to remove the first element?<br><br>void removeFirstElement(List&lt;int&gt; list) {<br>  list.removeAt(0);<br>}</pre><p>Well, seems reasonable, it knows about the removeLast method of the Dart List class, as can be seen it also showed me how to remove the first element, so it also knows about removeAt as well. I didn’t ask for this, but it is an assistant, maybe it’s just being helpful.</p><p>I moved on to a small but tricky C++ code snippet I wanted translating to Dart :-</p><pre>Could you translate the following C++ code to Dart? <br><br>std::cout&lt;&lt;std::max(7,7) &lt;&lt; std::endl;</pre><p>To which I got the reply :-</p><pre>Yes, here&#39;s the equivalent Dart code:<br><br>void main() {<br>  print(max(7, 7));<br>}<br><br>int max(int a, int b) =&gt; a &gt; b ? a : b;</pre><p>So it hasn’t used used the dart:math max function instead creating an inline max function typing the parameters to ints, however there is a nuance here that it has overlooked. The cppreference manual entry for the <a href="https://en.cppreference.com/w/cpp/algorithm/max">max</a> function states ‘Returns the greater of a and b. If they are equivalent, returns a.’ with a suggested implementation being ‘’return (a &lt; b) ? b : a;”</p><p>The generated Dart code doesn’t do this, it’s a reversal of the C++ implementation whereby if the values are equal b is returned not a. You’re being pedantic and picky, I hear you say, not so, losing subtleties like this in porting can introduce very difficult to find bugs and as said above ensuring that functions that happen to be named the same in both languages actually do the same is time-consuming, very difficult to find errors can be introduced misinterpreting stuff like this. In this case of course it doesn’t matter, in many others it does. Something to note about the general comprehension of the model. The same applies if it had used the dart:math function, what exactly does it do in the case of equivalence?</p><p>Time to try it on a real C++ code function from the common.cpp file of ggml. This file contains many small(ish) helper functions, just being able to automagically port these would be a great time saver :-</p><pre>&quot;Could you translate the following C++ code to Dart?&quot;<br><br>void high_pass_filter(std::vector&lt;float&gt; &amp; data, float cutoff, float sample_rate) {<br>    const float rc = 1.0f / (2.0f * M_PI * cutoff);<br>    const float dt = 1.0f / sample_rate;<br>    const float alpha = dt / (rc + dt);<br>     <br>    float y = data[0];\n&quot;<br>     <br>    for (size_t i = 1; i &lt; data.size(); i++) {<br>        y = alpha * (y + data[i] - data[i - 1]);<br>        data[i] = y;<br>    }<br>};</pre><p>gives :-</p><pre>Sure! Here&#39;s your Dart code:<br><br>void highPassFilter(List&lt;double&gt; data, double cutoff, double sampleRate) {<br>  final double rc = 1.0 / (2.0 * math.pi * cutoff);<br>  final double dt = 1.0 / sampleRate;<br>  final double alpha = dt / (rc + dt);<br><br>  double y = data[0];<br><br>  for (var i = 1; i &lt; data.length; i++) {<br>    y = alpha * (y + data[i] - data[i - 1]);<br>    data[i] = y;<br>  }</pre><p>Not too shabby, it again needs to import dart:math and alias it as ‘math’ but otherwise not too bad, y could be a var, but this is getting picky! Knowing that std::vector in C++ is List in Dart is fundamental of course, if it got this wrong then all bets are off.</p><p>I’ve run many more tests like the above on different code snippets, for brevity of course I can’t show all this in this article, sometimes it does seem to lose itself, it often uses ‘def’ for ‘void’ and occasionally tags onto the end of a generated code sequence things like ‘animal welfare’ statements (is this hallucination!) but I’m sufficiently confident to move forward with this.</p><p>Next steps are to move to a far more powerful cloud based machine (my dev box is struggling), maybe work out how to use the StarCoder model rather than StarChat and set up as automated a workflow as I can whereby I can just submit some C++ code and get the result in Dart. The input tokenizer length is 8192, so it should be able to tackle fairly large code snippets, the last test above had a token length of 145 for instance.</p><p>I’ll make another article on this in the future, but for now I’ll mark the evaluation as a ‘worth pursuing’.</p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>💰 Free coding interview course ⇒ <a href="https://skilled.dev/?utm_source=luc&amp;utm_medium=article">View Course</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=728423a151f6" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/porting-code-to-dart-using-starcoder-an-evaluation-728423a151f6">Porting code to Dart using StarCoder — an evaluation</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alpaca’s, Llama’s and Dart — Part 2]]></title>
            <link>https://levelup.gitconnected.com/alpacas-llama-s-and-dart-part-2-bc56741eb72?source=rss-85659e4789d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc56741eb72</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[dartlang]]></category>
            <dc:creator><![CDATA[Steve Hamblett]]></dc:creator>
            <pubDate>Mon, 01 May 2023 15:07:37 GMT</pubDate>
            <atom:updated>2023-05-02T16:53:28.305Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Alpaca’s, Llama’s and Dart — Part 2</strong></h3><p>In <a href="https://medium.com/gitconnected/alpacas-llama-s-and-dart-part-1-67eb8b2c0158">part 1</a> of this series, I looked at the <a href="https://github.com/antimatter15/alpaca.cpp">alpaca.cpp</a> project with an eye to port the chat application from C/C++ to Dart, this is now complete and can be found <a href="https://github.com/shamblett/alpaca">here</a>. The <a href="https://github.com/shamblett/alpaca/blob/main/README.md">README</a> should contain all the information you need to get started, the main points being that because the ggml library is imported via FFI only Linux is supported at the moment, there is an issue raised for a Windows implementation, also like the alpaca.cpp project itself the model file is not supplied, you need to get this yourself.</p><p>The code in the main chat application itself and the supporting utility and chat classes are straight ports from C++ as a quick inspection will show you, as such it’s not going to win any idiomatic Dart code prizes, but it is functional.</p><p>As I’ve found, testing these kinds of applications is not as straightforward as more normal applications, whereby you could just do a side by side test of the original application and the port however we have to start somewhere so why not ask the Dart chat application the same questions as we asked alpaca chat in part 1, so here goes with my questions about Manchester UK.</p><pre>&gt; Is Manchester in the North or South of UK<br><br>Manchester is in the North of the UK.</pre><p>Well, much more succinct than alpaca’s reply in part 1, and slightly inaccurate, North of England is more correct, as far as UK is concerned it’s in the middle I would say.</p><pre>&gt; What are the best places to visit in Manchester UK<br><br>The best places to visit in Manchester UK include the Manchester Museum, <br>the John Rylands Library, the Manchester Art Gallery, the National Football <br>Museum, the Lowry Centre, the Heaton Park, the Chetham&#39;s School of Music, <br>the People&#39;s History Museum, the Old Trafford Cricket Ground, and the <br>Imperial War Museum North.</pre><p>Again shorter than alpaca, but, we now have the correct art gallery, some places are the same but not others, and we don’t have any mention of the coffee shop, however all the above is correct.</p><p>Final question, alpaca got this completely wrong -</p><pre>&gt; What is the current time in Manchester UK<br> <br>The current time in Manchester UK is 11:22 AM.</pre><p>Consistent, if nothing else, totally wrong. Maybe these models just don’t know about time/timezones.</p><p>So what can we conclude from this? I would say that the port is OK, if you ask Dart chat and alpaca chat the same question over again you do get different yet still correct answers(mainly). So how do you test these things to prove any degree of accuracy, i.e. if this was a product, how would you verify it is meeting its requirements other than just saying the reply to a question should be correct. Answers on a postcard if you know this.</p><p>I’m thinking of doing a part 3 of this series, I would like to be able to tweak some parameters and see what the effect is with the goal of having the ability to predict what will happen if a certain parameter is changed to a certain value and in particular seeing if you can affect the outcome of answers with regard to recommendations, i.e. could I change a parameter to always recommend a specific place (or coffee shop) no matter what the question, e.g. the best places to visit in Manchester question always includes the Lowry Centre say no matter how it is phrased.</p><p>Another area of interest (and some concern) is performance, even when compiled Dart chat is noticeably slower at answering questions than alpaca chat, model loading however is comparable. The main performance hit in Dart is memory usage, this balloons wildly compared to the C++ code.</p><p>Until then, please feel free to play with this if you wish, you can contact me about anything here through my usual <a href="https://www.darticulate.com/">contact details</a> and these days I’m on Mastodon at @<a href="mailto:shamblett@darticulate.com">shamblett@darticulate.com</a> or raise issues on the repository, look at existing ones etc.</p><p>Note that I’m not an AI guy, so forgive me if any of the above seems trivially answerable to people who do this for a living, and please be kind on theory in any replies or comment, any heavy maths are going to elude me totally! Thanks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc56741eb72" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/alpacas-llama-s-and-dart-part-2-bc56741eb72">Alpaca’s, Llama’s and Dart — Part 2</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alpaca’s, Llama’s and Dart — Part 1]]></title>
            <link>https://levelup.gitconnected.com/alpacas-llama-s-and-dart-part-1-67eb8b2c0158?source=rss-85659e4789d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/67eb8b2c0158</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Steve Hamblett]]></dc:creator>
            <pubDate>Tue, 04 Apr 2023 08:15:46 GMT</pubDate>
            <atom:updated>2023-05-26T07:26:36.579Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Alpaca’s, Llama’s and Dart — Part 1</strong></h3><p>I recently came across a few videos on YouTube like this <a href="https://www.youtube.com/watch?v=OLg2BKhwaSc&amp;list=WL&amp;index=9&amp;t=837s">one</a> about how to run a ChatGPT like application locally, without needing to use an API to leverage a cloud based agent. This shows how to use the Alpaca.cpp and Llama.cpp projects to build your own local fast ChatGPT-like model.</p><p>From the README of the <a href="https://github.com/antimatter15/alpaca.cpp">Alpaca.cpp</a> project :-</p><p><em>This combines the </em><a href="https://github.com/facebookresearch/llama"><em>LLaMA foundation model</em></a><em> with an </em><a href="https://github.com/tloen/alpaca-lora"><em>open reproduction</em></a><em> of </em><a href="https://github.com/tatsu-lab/stanford_alpaca"><em>Stanford Alpaca</em></a><em> a fine-tuning of the base model to obey instructions (akin to the </em><a href="https://huggingface.co/blog/rlhf"><em>RLHF</em></a><em> used to train ChatGPT) and a set of modifications to </em><a href="https://github.com/ggerganov/llama.cpp"><em>llama.cpp</em></a><em> to add a chat interface.</em></p><p>Sufficiently intrigued, I cloned the Alpaca repository and had a quick look at it with an eye to porting the C/C++ code to Dart. After building the chat application and inspecting the code this looked doable, but before I expended any effort on this I wanted to see what this application could do, i.e. take it for a test run, so the first question was about Dart :-</p><pre>&gt; What is Google&#39;s Dart language  <br><br>Google’s Dart programming language, also known as “Dart”, was designed to <br>be a cross-platform and open source language for creating web applications. <br>It combines object-oriented and functional programming paradigms with an <br>emphasis on readability and performance. Its features include asynchronous I/O,<br>reflection, dynamic typing, static types, and native modules. Dart is used in <br>many Google products such as Chrome, Android OS, Gmail, etc., where it powers <br>user interface components like menus, toolbars, dialog boxes, etc. <br>It also has a strong ecosystem of libraries with support from the community <br>for various use cases including web development, mobile applications and <br>desktop application development.  <br>&gt;</pre><p>OK so far, note I’m running this on my main Linux dev box which is an i9 system with 64G RAM and fast SSD storage, although I’ve also tried it on my Linux dev laptop which is an old i7 with 32G RAM, it’s a bit stuttery, but the performance is more than acceptable on both platforms. So, pressing on, I asked questions about where I live :-</p><pre>&gt; Is Manchester in the North or South of UK  <br><br>Manchester is located in the northwest corner of England&#39;s mainland region; <br>it is not considered to be part of either Southern Britain nor <br>Northern Scotland. It lies within the United Kingdom, but outside both its <br>northern and southern regions as defined by the British Isles weather map.  <br>&gt;</pre><p>OK, so what will I see if I go to Manchester :-</p><pre>&gt; What are the best places to visit in Manchester UK <br>   <br>The best places to visit in Manchester include the Museum of Science &amp; <br>Industry (MOSI), The Lowry, Old Trafford Stadium Tour and Visit Tate <br>Liverpool art gallery. Other popular attractions include the National <br>Football Museum at Urbis building, Chinatown, Salford Quays, Heaton Park, <br>Castlefield Bowl and Artisan Coffee Roasters cafe.  <br>&gt;</pre><p>Reasonable, but the Tate gallery it mentions is in Liverpool, not Manchester (and why the coffee shop? More on this later). So I carried on asking questions on various subjects with again reasonable like answers except that in some areas it gets totally confused :-</p><pre>&gt; What is the current time in Manchester UK <br>                                              <br>The current time in Manchester UK is 10:24 AM GMT+0530 (IST).  <br>&gt;</pre><p>It clearly doesn’t understand what I mean here for some reason. This is totally wrong. Not to worry, now to a more worrying area :-</p><pre>&gt; What make of laptop can you suggest I buy<br>  <br>I would recommend the Dell Inspiron 15 3000 (~$699) or HP Pavilion x360 <br>($729). Both are great choices for their price range and feature a good <br>balance of performance, battery life, storage capacity, and display quality.  <br>&gt;</pre><p>This to me could become a big problem, I’ve nothing against Dell or HP, in fact in my experience they both make good laptops, but you can see how this can quickly become abused. Every corporate and his dog will now have their own ChatGPT like application that won’t cost them an arm and a leg to train and host, each peddling their own products, i.e. advertising in the form of a chatbot reply. I’m sure this is already happening in some form, but applications like this put this in the reach of everyone, scary.</p><p>Note that the above was generated using the ‘7B’ model, i.e. trained with 7 billion parameters, this is the smallest model, there are much larger models to use with it.</p><p>Right, scary stuff aside, I’d seen enough to decide I would port this to Dart, in the Alpaca project there are only 3 files to worry about, the chat.cpp file (this contains main), the utils.cpp file and the ggml.c file. The first two cpp files are just straight ports to Dart, nothing difficult there. The ggml.c file is the GGML Tensor Library and is quite a beast, fortunately it is written in C and therefore has a C based API which is ideal fodder for FFI, so I built the library as a shared object and ffigen’d its header. This is a good short term solution, but in the longer term it should really be ported to Dart, in its own package.</p><p>Work to add API wrappers and to complete the port generally is ongoing at the time of writing, I’ll go through the finished product in more detail in <a href="https://medium.com/gitconnected/alpacas-llama-s-and-dart-part-2-bc56741eb72">part 2</a>, stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67eb8b2c0158" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/alpacas-llama-s-and-dart-part-1-67eb8b2c0158">Alpaca’s, Llama’s and Dart — Part 1</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Constraining Dart’s numeric types and why you may want to do this]]></title>
            <link>https://levelup.gitconnected.com/constraining-darts-numeric-types-and-why-you-may-want-to-do-this-5b7bb3634f0d?source=rss-85659e4789d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b7bb3634f0d</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[dartlang]]></category>
            <dc:creator><![CDATA[Steve Hamblett]]></dc:creator>
            <pubDate>Thu, 16 Mar 2023 20:38:22 GMT</pubDate>
            <atom:updated>2023-03-20T11:54:14.573Z</atom:updated>
            <content:encoded><![CDATA[<p>I use several languages for my development work, as most people do, and I often see features in these languages that I wish Dart had. The Ada language is a (very)strongly typed language and has a particularly simple yet powerful feature I have used extensively over the years, that being subtypes.</p><p>A subtype in Ada is ‘<em>a type together with an associated constraint</em>’, i.e. a subset of the values of an existing type. An example -</p><pre>subtype Small_Int is Integer range -10 .. 10;</pre><p>This declares a type named Small_Int that is a subtype of Integer with the same operations as Integer but constrained to the value range -10 to 10. Any attempt to assign a value to this type that is outside the range of the constraint will cause the Ada runtime to raise a constraint error(a form of exception) that can’t be ignored, only handled. The type is used to best reflect the values to be stored. So what benefits does this give us -</p><ul><li>Any person reading code will have better understanding of the purpose of a variable</li><li>Better error checking possibilities</li><li>Easier to prove properties of programs with more restricted types</li></ul><p>A concrete example of this is converting data from the outside world into types in your application, e.g. deserializing a byte stream from a socket into a structure or record type. A subtype will not allow any value outside its constraints to be set, either at the point of deserialization or anywhere else in the application. This is important in high integrity/safety critical systems, where the propagation of invalid values into the application as a whole could have dire consequences.</p><p>So, can we do this in Dart? Well yes, we can’t enforce this at runtime in the same way Ada does this, but Dart is flexible enough so that with a combination of class extension and operator overloading we can model a working subtyping framework. For the purposes of this article, only ints are considered, however, the code presented below is easily made generic.<br>The full code for this article and unit test suite can be found <a href="https://github.com/shamblett/adatypes">here</a>.</p><p>Firstly, create an abstract subtype class that more concrete types can be derived from -</p><pre>abstract class Subtype {  <br>  Subtype.set(this.start, this.end, {int initialValue = 0}) {  <br>    _value = initialValue;  <br>  }  <br>  final int end;  <br>  final int start;  <br>  int _value = 0;  <br>  int get value =&gt; _value;  <br>  void call(int val) =&gt; _value = _boundsCheck(val);  <br>  <br>  @override  <br>  String toString() =&gt; _value.toString();<br>  ...........</pre><p>This allows us to set constraints for our subtypes and contains the private method boundsCheck to check these constraints. If the check fails, an ArgumentError is raised. Now we can add the equality operator and the + operator -</p><pre>@override  <br>bool operator ==(Object other) {  <br>  if (other is int) {  <br>    if (_value == other) {  <br>      return true;  <br>    }  <br>  }  <br>  if (other is Subtype) {  <br>    if (_value == other.value) {  <br>      return true;  <br>    }  <br>  }  <br>  return false;  <br>}  <br>  <br>dynamic operator +(Object other) {  <br>  if (other is int) {  <br>    _boundsCheck(_value += other);  <br>  } else {  <br>    try {  <br>      _boundsCheck(_value += (other as Subtype).value);  <br>    } on ArgumentError {  <br>      rethrow;  <br>    } catch (e) {  <br>      throw ArgumentError(  <br>          &#39;AdaTypes:Subtype - the type supplied is not derived from Subtype - $e&#39;,  <br>          &#39;other&#39;);  <br>    }  <br>  }  <br>  return this;  <br>}</pre><p>For equality, we allow comparison to ints as well as other Subtypes, similarly for addition we allow addition of ints and other types derived from Subtype (this can be further constrained, see below). Note, the return type of the addition operator is dynamic to allow default operation for derived types. So how can we use this? One way is to create general purpose Subtypes and use type aliasing to aid readability -</p><pre>class ADozen extends Subtype {  <br>  ADozen() : super.set(0, 12);  <br>}  <br>  <br>class AScore extends Subtype {  <br>  AScore() : super.set(0, 20);  <br>}  <br>  <br>typedef EggsInBox = ADozen;  <br>typedef PeasInPod = AScore;</pre><p>This allows us to write our subtyped integers like this -</p><pre>final numEggs1 = EggsInBox();  <br>numEggs1(3);  <br>final numEggs2 = EggsInBox();  <br>numEggs2(4);  <br>final numPeas = PeasInPod();  <br>numPeas(15);</pre><p>Addition now simply becomes -</p><pre>numEggs1 += numEggs2;</pre><p>knowing that the subtype constraints cannot be violated. All other needed operators can be added similarly.</p><p>So far so good, but the implementation thus far also allows this -</p><pre>numEggs += numPeas;</pre><p>as both the types are derived from Subtype. This doesn’t read naturally and is probably not what you expect, so we can tighten this further by adding a strict type checking mechanism and while we are at it a check that the variable can’t be used unless it has been initialized -</p><pre>Subtype.set(this.start, this.end,  <br>    {int initialValue = 0, strictTyping = false}) {  <br>  _value = initialValue;  <br>  _strictTyping = strictTyping;  <br>}  <br>  <br>final int end;  <br>final int start;  <br>int _value = 0;  <br>int get value =&gt; _value;  <br>bool _strictTyping = false;  <br>bool _initialised = false;</pre><p>so the addition operator now becomes -</p><pre>dynamic operator +(Object other) {  <br>  if (other is int) {  <br>    _operationValid(_value += other);  <br>  } else if (_strictTyping) {  <br>    final tThis = runtimeType;  <br>    final tOther = other.runtimeType;  <br>    if (tThis != tOther) {  <br>      throw ArgumentError(  <br>          &#39;AdaTypes:Subtype - strict typing - the type supplied is different from the subject type&#39;,  <br>          &#39;other&#39;);  <br>    } else {  <br>      _operationValid(_value += (other as Subtype).value);  <br>    }  <br>  } else {  <br>    _tryAssignment(other);  <br>  }  <br>  return this;  <br>}</pre><p>the addition of peas in a pod to eggs in a box above will now throw as the types ADozen and AScore if instantiated with the strict typing flag, although still derived from Subtype are now treated as different types. Type aliasing doesn’t have to be used, of course, there’s nothing to stop the user directly creating an EggsInABox type directly from Subtype.</p><p>As can be seen, creating a fully fleshed out production ready subtyping mechanism with a corresponding unit test suite is not trivial and will not suit everyone. However, once implemented, this can be re-used in many of your packages and applications.</p><p>The real take out here though is not just the code, it’s instilling a questioning mindset in the eyes of the reader. If you now look at your code differently and ask questions like, ‘Does that variable really need the full range of an int? In this application I know it can only be 0…10, what happens if it gets assigned the value 20 or a negative value?’ Then you are on your way to producing even more type safe code than standard Dart allows.</p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>💰 Free coding interview course ⇒ <a href="https://skilled.dev/?utm_source=luc&amp;utm_medium=article">View Course</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b7bb3634f0d" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/constraining-darts-numeric-types-and-why-you-may-want-to-do-this-5b7bb3634f0d">Constraining Dart’s numeric types and why you may want to do this</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>