Skip to content

Commit

Permalink
Adds LlmConfig table
Browse files Browse the repository at this point in the history
  • Loading branch information
jpb18 committed Oct 16, 2024
1 parent a8f3148 commit 8b61f34
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 7 deletions.
7 changes: 7 additions & 0 deletions labs/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import LlmConfig

@admin.register(LlmConfig)
class LlmConfigAdmin(admin.ModelAdmin):
list_display = ('llm_model', 'config_key', 'config_value', 'config_type', 'created_at', 'updated_at')
search_fields = (['config_key', 'llm_model'])
50 changes: 50 additions & 0 deletions labs/fixtures/llm_configs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"model": "labs.llmconfig",
"pk": 1,
"fields": {
"llm_model": "llm_model",
"config_key": "api_key",
"config_value": "abcdef123456",
"config_type": "string",
"created_at": "2024-10-15T12:00:00Z",
"updated_at": "2024-10-15T12:00:00Z"
}
},
{
"model": "labs.llmconfig",
"pk": 2,
"fields": {
"llm_model": "llm_model",
"config_key": "response_format",
"config_value": "json",
"config_type": "string",
"created_at": "2024-10-15T12:00:00Z",
"updated_at": "2024-10-15T12:00:00Z"
}
},
{
"model": "labs.llmconfig",
"pk": 3,
"fields": {
"llm_model": "llm_model",
"config_key": "endpoint",
"config_value": "https://api.openai.com/v1/engines/davinci/completions",
"config_type": "url",
"created_at": "2024-10-15T12:00:00Z",
"updated_at": "2024-10-15T12:00:00Z"
}
},
{
"model": "labs.llmconfig",
"pk": 4,
"fields": {
"llm_model": "llm_model",
"config_key": "max_tokens",
"config_value": "4096",
"config_type": "integer",
"created_at": "2024-10-15T12:00:00Z",
"updated_at": "2024-10-15T12:00:00Z"
}
}
]
42 changes: 42 additions & 0 deletions labs/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 5.1.2 on 2024-10-16 15:57

import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="LlmConfig",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("llm_model", models.TextField(blank=True, null=True)),
("config_key", models.TextField(unique=True)),
("config_value", models.TextField(blank=True, null=True)),
("config_type", models.TextField(blank=True, null=True)),
("created_at", models.DateTimeField(default=django.utils.timezone.now)),
("updated_at", models.DateTimeField(auto_now=True)),
],
options={
"indexes": [
models.Index(
fields=["config_key", "llm_model"],
name="labs_llmcon_config__fda707_idx",
)
],
},
),
]
Empty file added labs/migrations/__init__.py
Empty file.
21 changes: 14 additions & 7 deletions labs/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from django.db import models
from django.utils import timezone

class LLMSettings(models.Model):
model_name = models.TextField() # Identifier for the LLM
api_key = models.TextField() # API key for the LLM
response_format = models.TextField() # Format of the response (e.g., JSON, text)
endpoint = models.URLField() # API endpoint URL for the LLM
extra_params = models.JSONField(blank=True, null=True) # Optional field for any extra parameters
class LlmConfig(models.Model):
llm_model = models.TextField(blank=True, null=True)
config_key = models.TextField(unique=True)
config_value = models.TextField(blank=True, null=True)
config_type = models.TextField(blank=True, null=True)
created_at = models.DateTimeField(default=timezone.now)
updated_at = models.DateTimeField(auto_now=True)

def __str__(self):
return self.model_name
return f"{self.config_key}: {self.config_value}"

class Meta:
indexes = [
models.Index(fields=['config_key', 'llm_model'])
]
1 change: 1 addition & 0 deletions labs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
# Application definition

INSTALLED_APPS = [
'labs',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand Down

0 comments on commit 8b61f34

Please sign in to comment.