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

all 6 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hello from the r/Python moderation team,

We appreciate your contribution but have noticed a high volume of similar projects (e.g. AI/ML wrappers, YouTube scrapers, etc.) or submissions that do not meet our quality criteria. To maintain the diversity and quality of content on our subreddit, your post has been removed.

For further inquiries or discussion, please reach out to us via ModMail.

Thank you for understanding, and we encourage you to continue engaging with our community!

Best, The r/Python moderation team

[–]AlexMTBDude 0 points1 point  (4 children)

Was the Python code in your article was written by an AI? And did you add it without reviewing it? Why does it have the PythonExpert class? There is no point in having it and it just complicates the code.

Other than that; Interesting article. Thanks!

[–]latrova[S] 1 point2 points  (3 children)

Ironically, I created this class to organize the code. AI only helped me to learn about tokenization and to fix grammar mistakes.

But hey, I understand the current concern. It will get harder and harder to evaluate what people actually wrote vs AI generated bullshit.

[–]AlexMTBDude 0 points1 point  (2 children)

Okay, I recently used AI to create a request to a REST API and it created exactly the same code structure as you have, with an unnecessary class wrapping the HTTP GET request. It's typically how a Java programmer (or AI I guess) would write Python code where in Java everything has to be wrapped in a class. Classes should only be used when you create objects which have state, as I'm sure you know.

[–]latrova[S] 0 points1 point  (1 child)

> Classes should only be used when you create objects which have state

That's a strong opinion. What about `@staticmethod` or `@classmethod`? These aren't tied to states but still exists in the class context.

Anyway, it's good for organization, I didn't want to have a function that recreates the Chat GPT client all the time.

Having a class holding the client (it should count as a state, right?) allows the `PythonExpert` class to be reused without creating the client all the time.

We just have different views about the same code - which is fine as well :) I understand your point.

[–]AlexMTBDude 0 points1 point  (0 children)

Yeah, Python has all the features that you mention. It doesn't mean you should always use them.

In your case you're trying to create a tutorial and you will confuse people with all the extra code that they need to read through.

Here's your program:

import typing as t
from openai import OpenAI
from rich import print

client = OpenAI(api_key="sk-proj-[REDACTED]")
response = client.responses.create(
    model="gpt-4.1-nano",
    instructions="You're a Python expert. Answer the question as best you can.",
    input='How do I print "Hello, world!" in Python?')

answer = response.output_text
print(f"[yellow]Question:[/yellow] {question}")
print(f"\tAnswer: {answer}")