From d44ad1f490ef390d7bfd7af9939aa062baf810b6 Mon Sep 17 00:00:00 2001 From: kitt Date: Wed, 29 Nov 2023 12:04:26 -0500 Subject: [PATCH] add machine id --- .../migrations/0004_thread_runner_machine_id.py | 17 +++++++++++++++++ assistant/models.py | 1 + assistant/orchestrator.py | 3 +++ assistant/templates/assistant/view_thread.html | 2 +- assistant/views.py | 5 ++++- 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 assistant/migrations/0004_thread_runner_machine_id.py diff --git a/assistant/migrations/0004_thread_runner_machine_id.py b/assistant/migrations/0004_thread_runner_machine_id.py new file mode 100644 index 00000000..cf85e47d --- /dev/null +++ b/assistant/migrations/0004_thread_runner_machine_id.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.7 on 2023-11-29 17:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('assistant', '0003_thread_status_alter_thread_openai_file_id'), + ] + + operations = [ + migrations.AddField( + model_name='thread', + name='runner_machine_id', + field=models.CharField(blank=True, max_length=20), + ), + ] diff --git a/assistant/models.py b/assistant/models.py index 63142c53..b2c33ed5 100644 --- a/assistant/models.py +++ b/assistant/models.py @@ -14,3 +14,4 @@ class Status(models.TextChoices): created_date = models.DateTimeField(auto_now_add=True) initial_message = models.TextField(default='') status = models.CharField(blank=True, choices=Status.choices, max_length=25) + runner_machine_id = models.CharField(blank=True, max_length=20) diff --git a/assistant/orchestrator.py b/assistant/orchestrator.py index 811b6a3c..072f5c4d 100644 --- a/assistant/orchestrator.py +++ b/assistant/orchestrator.py @@ -1,3 +1,4 @@ +import json import os import requests @@ -45,3 +46,5 @@ def schedule_machine(thread: Thread): if response.status_code != 200: print(response.text) response.raise_for_status() + data = json.loads(response.text) + return data.id diff --git a/assistant/templates/assistant/view_thread.html b/assistant/templates/assistant/view_thread.html index 69f28c24..dd70318a 100644 --- a/assistant/templates/assistant/view_thread.html +++ b/assistant/templates/assistant/view_thread.html @@ -13,7 +13,7 @@

Thread ID: {{ thread.openai_thread_id }}

File ID: {% if thread.status == thread.Status.PENDING %} - Waiting for thread data... + Waiting for thread data... (Runner ID: {{ thread.runner_machine_id }}) {% else %} {{ thread.openai_file_id }} {% endif %}

diff --git a/assistant/views.py b/assistant/views.py index 72a56be6..3e8357f3 100644 --- a/assistant/views.py +++ b/assistant/views.py @@ -54,7 +54,10 @@ def create_thread(request): initial_message=form.cleaned_data['initial_message']) thread.save() - orchestrator.schedule_machine(thread) + machine_id = orchestrator.schedule_machine(thread) + + thread.runner_machine_id = machine_id + thread.save() return redirect("assistant:view_thread", thread.id)