Skip to content
Fondazione ITS INCOM

Examples · Programming

Code with Qwen3-Coder

The model made for programming. Have it write a log analyser, explain it and find a bug in it, then get your own code reviewed.

Intermediate · 40 min

The model

Qwen3-Coder 30B (qwen3-coder-30b) is the model for programming: it writes, explains and fixes code in Python, Bash, JavaScript, SQL and more, and it can call tools. It is fast: on the school's machines it writes more than 100 tokens a second.

It can be wrong, like every model. Run and test what it writes before you trust it.

1. Write a script, in the chat

Open the chat, choose Qwen3-Coder 30B and ask:

Write a Python script that reads a Linux /var/log/auth.log file and prints, for each IP address, how many failed SSH logins it made, from the most to the least. Use only the standard library.

Then, in the same conversation:

2. Find the bug

Paste this function and ask: "Why does it never find port 22 open? Fix it."

import socket


def open_ports(host, first, last):
    found = []
    for port in range(first, last):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(0.5)
        if s.connect_ex((host, port)) == 0:
            found.append(port)
        s.close()
    return found


print(open_ports("127.0.0.1", 1, 22))

Try to find it yourself first: the answer is at the end of the page.

3. Review your code, from Python

You need your API key, from Your first API call in Python.

import os
import sys

from openai import OpenAI

client = OpenAI(
    base_url="https://api.ai.itsincom.org/v1",
    api_key=os.environ["API_KEY"],
)

code = open(sys.argv[1]).read()

review = client.chat.completions.create(
    model="qwen3-coder-30b",
    temperature=0,
    messages=[
        {"role": "system", "content": "You are a senior developer and a security reviewer. Be concise."},
        {"role": "user", "content": "Review this code. List the bugs and the security problems, "
                                    "the most serious first, then show the fixed code.\n\n" + code},
    ],
)

print(review.choices[0].message.content)

Save it as review.py and run python review.py my_script.py.

4. Exercise

Good to know

The bug in section 2: range(first, last) stops before last, so range(1, 22) ends at 21 and port 22 is never tried. Use range(first, last + 1).

All examples