Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
How to use the input through get request as a variable in fastapi

I am using fast API to do predictions. I am taking the if and the inputs through the get request and returning the response. But I want to change the endpoint dynamically from the input id given by the user and I was unable to do it. I am getting name task_id is not defined

from pydantic import BaseModel
class SoluteSolvent(BaseModel):
    solvent: str
    solute: str
    task_id: int

api_names = ['/predict','/predict_json']

@app.get(api_names[task_id])
def predict(task_id: int,solute: str, solvent: str):
    if task_id == 0:
        results = predictions(solute, solvent)
        response["interaction_map"] = (results[1].detach().numpy()).tolist()
        response["predictions"] = results[0].item()
        return {'result': response}
    elif task_id == 1:
        return "this is second one"
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!