Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed Trouble with text console.

+11 votes
asked Nov 19, 2025 by Sawyer (340 points)
closed Nov 27, 2025 by Sawyer
I created a code in python and for some reason when I run it in the interactive tab it works perfectly fine but when I try to run it in the text console it freezes up and then shows me a message that it has lost connection to the server. I’m not asking for any inputs it simply retrieves some data and this never happens in the text console. If anyone has any insight I would appreciate it.

Here’s my code:

import requests
import time

API_KEY = "[you can replace this with an API key by getting a free account at mistral if you want to test it]"
API_URL = "https://api.mistral.ai/v1/chat/completions"

history_1 = []
history_2 = []

def ask_1(prompt):
    global history_1
    history_1.append({"role": "user", "content": prompt})
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json",
    }
    data = {
        "model": "ministral-8b-2410",
        "messages": history_1,
        "temperature": 0.9,
        "max_tokens": 200,
    }
    
    response = requests.post(API_URL, headers=headers, json=data)
    response_1 = response.json()["choices"][0]["message"]["content"]
    history_1.append({"role": "assistant", "content": response_1})
    return response_1

def ask_2(prompt):
    global history_2
    history_2.append({"role": "user", "content": prompt})
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json",
    }
    data = {
        "model": "ministral-8b-2410",
        "messages": history_2,
        "temperature": 0.9,
        "max_tokens": 100,
    }
    
    response = requests.post(API_URL, headers=headers, json=data)
    response_2 = response.json()["choices"][0]["message"]["content"]
    history_2.append({"role": "assistant", "content": response_2})
    return response_2
    

response_2 = "Hi, who are you?"
count = 0

while count < 20:
    count += 1
    print(f"Chat # {count}")
    response_1 = ask_1(response_2)
    print("AI 1-", response_1)
    time.sleep(1)
    print("~~~")
    response_2 = ask_2(response_1)
    print("AI 2-", response_2)
    time.sleep(1)
    print(
        "---------------------------------------------------------------------------------"
    )
closed with the note: I’ve found out what I did wrong, the text console fully runs the entire code before showing the result, do to the runtime of my code I either was not giving it long enough or it timed out before it finished running.

1 Answer

0 votes
answered Nov 20, 2025 by Peter Minarik (101,420 points)
Can you share your code?
commented Nov 20, 2025 by Sawyer (340 points)
I updated it with my code along with some more information.
commented Nov 20, 2025 by Peter Minarik (101,420 points)
Thanks for posting it.

I couldn't detect any reading from the standard input either.

You could add some debug code to print when you start the request to the server, and print again something when you get the response, so you can verify that the program is not getting the response from the server.

Confirm that the same code still runs in "interactive" mode, but times out in "text" mode.

Then, update your code in this thread with this extra logging, and you should probably contact the admin (https://www.onlinegdb.com/contact), as this must have to do with how OnlineGDB works. That is, this is an environment issue, not a problem with the code.
commented Nov 20, 2025 by Sawyer (340 points)
I already tried debugging it but it just isn’t running the code. I will contact the admin though.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...