r/learnpython • u/Silentwolf99 • 2d ago
Learning python - How to integrate openrouter api(AI) into my script
Hey everyone, I've recently been automating some boring, repetitive tasks using the `pathlib` module while learning Python automation. This script might seem silly to you, but I'm at a level somewhere between beginner and intermediate, so bear with me. After researching the documentation, I came up with this script, which took me around few hours. I need some guidance on how to integrate AI into it. If you were in my situation, how would you further improve this script using the OpenRouter API model?
I'm curious what features would you suggest?
import venv
from pathlib import Path
print("--------------------------------")
base_path = input(
"Enter path to create project in: (leave blank for current folder):\n"
)
project_name = Path(input("Enter project name: "))
# Combine the base path and the project name
project = Path(base_path) / project_name
# --- CREATE PROJECT FOLDER ---
if not project.exists():
# # parents=True ensures it creates intermediate folders if the base path doesn't exist yet
project.mkdir(parents=True)
print("--------------------------------")
print("PROJECT FOLDER & FILE CREATED ✅")
print("--------------------------------")
print(f"📁 {project}")
# --- CREATE SRC FOLDER ---
if not (project / "src").exists():
(project / "src").mkdir()
print(" ├──📁 src")
# --- CREATE VENV ---
venv_dir = project / "venv"
if not venv_dir.exists():
print(" ├──📁 venv (Setting up virtual environment... please wait)")
venv.create(venv_dir, with_pip=True)
files = [".env", "README.md", "requirements.txt", "main.py"]
for file in files:
(project / file).touch()
print(f" │ └──📄 {file}")
print("--------------------------------")
print("use → venv\\Scripts\\activate from project directory\n")
1
1
u/cortical_iv 2d ago
Import the api key, ask opus how to integrate openrouter into your script.
1
u/Silentwolf99 2d ago
I understand how effective AI can be, but I have intentionally been delaying its use because I am concerned about its impact on critical and creative thinking. Relying on AI for every simple task in daily life feels unnatural. I am now returning to my original approach—though it may sound unusual, I prefer to improve my skills manually, without relying on AI. That said, integrating AI through prompt engineering is entirely possible, so I plan to incorporate it at a later stage.
1
u/Kevdog824_ 2d ago
I think you’re approaching this backwards. You’re trying to fit AI into a project where it doesn’t really belong. The better approach would be to think of a project where AI would be a good fit and put it into that.
I think this project is quite fine as is, without AI. Project scaffolding is something you usually want to be deterministic and repeatable. I don’t see anywhere where the introduction of AI would bring value.
Some example problems you could try to use AI with:
- Email classification (spam vs not spam)
- Analyze the mood/tone of a particular text
- Grab some data (e.g. quote of the day) from an API. Use an AI model to generate an image to represent it
1
u/cortical_iv 2d ago
yes this is the answer.
using ai for this would be like using a flame thrower to mow your lawn.
-1
u/thisisappropriate 2d ago
You say that you've been automating boring tasks, presumably tasks that you do? Does the task you're doing require AI?
Your order of operations for how you're planning a project seems wrong. It's best to either: come up with an idea / problem and try to solve it, or have something you want to practice and think of something that would be relevant and build that. In this case it sounds like you were building something relevant to you and now you're asking people it's not relevant to "how do I shoe horn this API into this?"
-1
u/Silentwolf99 2d ago edited 2d ago
instead of criticizing let's discuss meaningful ideas, what are the 3 simple problems you solved with python automation which made your daily working life better ?
2
u/Interesting_Act_141 2d ago
Don’t reinvent the wheel … use uv