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

ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
RudManusachi
What configs will make sense to put to runtime.exs? – A bit of how I configure apps: I have generic configs in config/config.exs, dev...
New
AstonJ
Can you believe the first professionally published Elixir book was published just 8 years ago? Since then I think we’ve seen more books f...
New

Other popular topics Top

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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
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

We're in Beta

About us Mission Statement