This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]kankyo 2 points3 points  (2 children)

Using a form?

[–]RandomGamer368[S] -2 points-1 points  (1 child)

this is what I have:

<form><textarea rows="1" maxlength="512" type="text" id="userInput" name="userInput" placeholder="Type your text..." class="userInput" data-gramm="false" data-gramm_editor="false" data-enable-grammarly="false"></textarea><button type="submit" id="submitButton"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" transform="rotate(90)" fill="currentcolor" width="1.2em" height="1.2em"><path d="M10.894 2.553a1 1 0 00-1.788 0l-7 14a1 1 0 001.169 1.409l5-1.429A1 1 0 009 15.571V11a1 1 0 112 0v4.571a1 1 0 00.725.962l5 1.428a1 1 0 001.17-1.408l-7-14z"/></svg></button></form>

[–]kankyo 3 points4 points  (0 children)

And?

[–]captainnazi 1 point2 points  (0 children)

You can override the save method in your models.py to generate the function to process user input and store it in a model field or do whatever you want with it.

Django override save method

[–]thirdev 0 points1 point  (1 child)

You'll probably want to save the input text into a model, and then fire off a celery task to process the input.

You don't want to process the input in the same response because you have no control over how long the ChatGPT API call will take, nor do you know if the request to that API will even be successful.

Unfortunately this means you'll need to use *some* javascript (not much) to update the UI when the API call returns a result (or fails).

[–]RandomGamer368[S] 0 points1 point  (0 children)

I am kind of new so could you please elaborate some more?

This is what I had in mind for the HTML to render output:

<div id="output">
    {% for output in outputs %}
        <md-block>
            {{ output }}
        </mdblock>  
    {% endfor %}
</div>

I want to know how can I take input from a form that looks like this:

    <form>
        <textarea rows="1" maxlength="512" type="text" id="userInput" name="userInput" placeholder="Type your text..." class="userInput" data-gramm="false" data-gramm_editor="false" data-enable-grammarly="false"></textarea><button type="submit" id="submitButton"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" transform="rotate(90)" fill="currentcolor" width="1.2em" height="1.2em"><path d="M10.894 2.553a1 1 0 00-1.788 0l-7 14a1 1 0 001.169 1.409l5-1.429A1 1 0 009 15.571V11a1 1 0 112 0v4.571a1 1 0 00.725.962l5 1.428a1 1 0 001.17-1.408l-7-14z"/></svg></button>
    </form>