AI Models being able to generate code unlocks all sorts of use cases. The DeepSeek Coder ↗ models @hf/thebloke/deepseek-coder-6.7b-base-awq and @hf/thebloke/deepseek-coder-6.7b-instruct-awq are now available on Workers AI.
If you want to add these files to your environment, you can create a new file named .env
Generate code from a comment
A common use case is to complete the code for the user after they provide a descriptive comment.
Assist in debugging
We've all been there, bugs happen. Sometimes those stacktraces can be very intimidating, and a great use case of using Code Generation is to assist in explaining the problem.
The error in your code is that you are trying to use a variable name which is not defined anywhere in your function. The correct variable to use is first_name. So, you should change f"Hello, {name}!" to f"Hello, {first_name}!".
Here is the corrected code:
Now, when you call hello_world(), it will print "Hello, World" by default. If you call hello_world("John"), it will print "Hello, John".
Write tests!
Writing unit tests is a common best practice. With the enough context, it's possible to write unit tests.
Here is a simple unittest test case for the User class:
In this test case, we have two tests:
test_full_name tests the full_name method when the user has both a first name and a last name.
test_default_last_name tests the full_name method when the user only has a first name and the last name is set to "Mc" + first name.
If all these tests pass, it means that the full_name method is working as expected. If any of these tests fail, it
Fill-in-the-middle Code Completion
A common use case in Developer Tools is to autocomplete based on context. DeepSeek Coder provides the ability to submit existing code with a placeholder, so that the model can complete in context.
Warning: The tokens are prefixed with <| and suffixed with |> make sure to copy and paste them.
Experimental: Extract data into JSON
No need to threaten the model or bring grandma into the prompt. Get back JSON in the format you want.
Was this helpful?
What did you like?
What went wrong?
Thank you for helping improve Cloudflare's documentation!