Test Drive: Nemotron
Published on .
Today I’m test driving nvidia/llama-3_1-nemotron-70b-instruct, a Llama3.1 finetuned with “21, 362 prompt-responses built to make more models more aligned with human preference.” I’m going back to my Django car listings example, mainly to do a vibe check. The other goal of this test drive is to see how it plays with litellm. The process is:
- Get an API key
- Implement in litellm
Getting a key with free credits is just a few clicks from the model page, and the only trick with litellm is using the nvidia_nim/
namespace.
The output is a little better than I got with Qwen and plain Llama3.1 I’ve tried as it included some steps that were missed elsewhere, which is interesting because it isn’t specifically tuned for code. Here’s the code.
%env NVIDIA_NIM_API_KEY=nvapi-mykey
from litellm import completion
from textwrap import dedent
response = completion(
model="nvidia_nim/nvidia/llama-3.1-nemotron-70b-instruct",
messages=[
{
"role": "user",
"content": dedent("""\
Architect a django project with an app for car listings.
Include models for:
- Listings
Include views for:
- see all listings
- see a single listing
- add and modify a listing
Include a seeder for listings""")
}
],
)
print(response.choices[0].message.content)
Code language: Python (python)
Here’s the output
Below is a structured approach to architecting a Django project with an app for car listings as per your request. This will include:
- Project Setup
- App Setup (Car Listings)
- Models (Listings)
- Views for Listings
- URL Configuration
- Seeder for Listings
1. Project Setup
First, ensure you have Django installed. If not, you can install it using pip:
pip install django
Code language: Python (python)
Create a new Django project:
django-admin startproject car_listings_project
Code language: Python (python)
Navigate into your project directory:
cd car_listings_project
Code language: Python (python)
2. App Setup (Car Listings)
Create a new Django app for car listings:
python manage.py startapp car_listings
Code language: Python (python)
Add 'car_listings'
to the INSTALLED_APPS
in
your settings.py
to enable the app:
# settings.py (excerpt)
INSTALLED_APPS = [
...
'car_listings', # Add this line
...
]
Code language: Python (python)
3. Models (Listings)
Define the Listing
model in
car_listings/models.py
:
# car_listings/models.py
from django.db import models
class Listing(models.Model):
MAKE_CHOICES = [
('Toyota', 'Toyota'),
('Ford', 'Ford'),
('Honda', 'Honda'),
# Add more as needed
]
CONDITION_CHOICES = [
('New', 'New'),
('Used', 'Used'),
]
title = models.CharField(max_length=255)
make = models.CharField(max_length=20, choices=MAKE_CHOICES)
model = models.CharField(max_length=50)
year = models.IntegerField()
condition = models.CharField(max_length=10, choices=CONDITION_CHOICES)
price = models.DecimalField(max_digits=10, decimal_places=2)
description = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"{self.year} {self.make} {self.model}"
Code language: Python (python)
Run migrations to create the database tables:
python manage.py makemigrations
python manage.py migrate
Code language: Python (python)
4. Views for Listings
Create views for listings in car_listings/views.py
:
# car_listings/views.py
from django.shortcuts import render, redirect, get_object_or_404
from .models import Listing
from .forms import ListingForm # We'll define this next
def all_listings(request):
listings = Listing.objects.all()
return render(request, 'car_listings/all_listings.html', {'listings': listings})
def single_listing(request, pk):
listing = get_object_or_404(Listing, pk=pk)
return render(request, 'car_listings/single_listing.html', {'listing': listing})
def add_listing(request):
if request.method == 'POST':
form = ListingForm(request.POST)
if form.is_valid():
form.save()
return redirect('all_listings')
else:
form = ListingForm()
return render(request, 'car_listings/add_listing.html', {'form': form})
def modify_listing(request, pk):
listing = get_object_or_404(Listing, pk=pk)
if request.method == 'POST':
form = ListingForm(request.POST, instance=listing)
if form.is_valid():
form.save()
return redirect('all_listings')
else:
form = ListingForm(instance=listing)
return render(request, 'car_listings/add_listing.html', {'form': form})
Code language: Python (python)
5. Forms for Listings
Define a form for the Listing
model in
car_listings/forms.py
:
# car_listings/forms.py
from django import forms
from .models import Listing
class ListingForm(forms.ModelForm):
class Meta:
model = Listing
fields = ('title', 'make', 'model', 'year', 'condition', 'price', 'description')
Code language: Python (python)
6. URL Configuration
Update car_listings/urls.py
(create if it doesn’t exist)
and include it in the main project’s urls.py
:
car_listings/urls.py:
# car_listings/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('listings/', views.all_listings, name='all_listings'),
path('listings/<pk>/', views.single_listing, name='single_listing'),
path('listings/add/', views.add_listing, name='add_listing'),
path('listings/<pk>/modify/', views.modify_listing, name='modify_listing'),
]
Code language: Python (python)
car_listings_project/urls.py:
# car_listings_project/urls.py (excerpt)
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('car_listings.urls')), # Include car listings urls
]
Code language: Python (python)
7. Seeder for Listings (Using Django Shell)
To seed your database with some listings, use the Django shell:
python manage.py shell
Code language: Python (python)
Then, in the shell:
# Import the Listing model
from car_listings.models import Listing
# Create some listings
Listing.objects.create(title="Test Listing 1", make="Toyota", model="Camry", year=2020, condition="Used", price=25000.0, description="Test description")
Listing.objects.create(title="Test Listing 2", make="Ford", model="Mustang", year=2015, condition="New", price=35000.0, description="Another test")
# Quit the shell
quit()
Code language: Python (python)
8. Templates
Lastly, create the necessary templates in
car_listings/templates/car_listings/
:
all_listings.html
single_listing.html
add_listing.html
Example for all_listings.html
:
<!-- car_listings/templates/car_listings/all_listings.html -->
<h1>All Car Listings</h1>
<ul>
{% for listing in listings %}
<li>
<a href="{% url 'single_listing' listing.pk % }}">{{ listing }}</a>
</li>
{% endfor %}
</ul>
<p><a href="{% url 'add_listing' %}">Add New Listing</a></p>
Code language: Python (python)
Similarly, create templates for single_listing.html
and
add_listing.html
according to your needs, utilizing
Django’s template language to display and interact with your listings