vkryukov

vkryukov

Playing with DeepSeek for code generation

I’m playing with DeepSeek V3, a new open source 670B parameter model released by a Chinese LLM provider, that is said to be close in quality to the leading closed source models (Claude and gpt4o), and it’s pretty good (and ~10-15X cheaper than the competition when you use their API, with no restrictions).

One thing that it surprised me with was that when I asked it to fix the KV tutorial code (essentially, to implement “release buckets on exit”), instead of creating a map of refs as in the tutorial, it simply used the pid from the :DOWN message, arriving to the following solution:

  @impl true
  def handle_cast({:create, name}, names) do
    if Map.has_key?(names, name) do
      {:noreply, names}
    else
      {:ok, bucket} = KV.Bucket.start_link([])
      # Monitor the bucket process
      Process.monitor(bucket)
      {:noreply, Map.put(names, name, bucket)}
    end
  end

  @impl true
  def handle_info({:DOWN, _ref, :process, pid, _reason}, names) do
    # Remove the bucket from the registry when it exits
    names = Enum.into(Enum.reject(names, fn {_name, bucket_pid} -> bucket_pid == pid end), %{})
    {:noreply, names}
  end

Of course, nothing is ever rosy with LLM-produced code - its original suggestion didn’t have Enum.into, so it was silently replacing maps with lists when removing names (but DeepSeek was able to resolve the issue once I supplied it with a stack trace). And of course with a large number of processes, using a second map for refs will be more performant than linearly searching through the list. Notice also that most Elixir developers(?) would probably write

names = 
  names
  |> Enum.reject(...)
  |> Enum.into(%{})

to make the code more readable.

But I’m still impressed - I personally didn’t think of that solution when I was going through the docs for the first or second time.

Where Next?

Popular in Discussions Top

lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
Qqwy
Looking at the stacks that existing large companies have used, WhatsApp internally uses Mnesia to store the messages, while Discord uses ...
New
IVR
Hi all, I’ve seen a number of related threads in the past, but I’d still be very curious to hear an up-to-date opinion on this topic. I...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New
griffinbyatt
Sobelow Sobelow is a security-focused static analysis tool for the Phoenix framework. For security researchers, it is a useful tool for g...
New

Other popular topics Top

dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I'm a nov...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement