mindsdb / mindsdb

Platform for building AI that can learn and answer questions over federated data.
https://mindsdb.com
Other
26.78k stars 4.88k forks source link

[Bug]: Model fails to predict with SQL query as input #9984

Open gaspardc-met opened 3 weeks ago

gaspardc-met commented 3 weeks ago

Short description of current behavior

Per the docs, model.predict can use as input a dataframe or a query:

However, I cannot reproduce this locally

model = project.get_model("my_model_5")
sql = "SELECT * FROM postgresml.powerplant LIMIT 5;"
dataframe = project.query(sql).fetch()
model.predict(data=dataframe) # works
model.predict(data=sql) # fails
{
    "name": "ValueError",
    "message": "Unknown input",
    "stack": "---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[93], line 1
----> 1 model.predict(data=sql)

File venv/lib/python3.11/site-packages/mindsdb_sdk/models.py:222, in Model.predict(self, data, params)
    219     return self.project.api.model_predict(self.project.name, self.name, data,
    220                                           params=params, version=self.version)
    221 else:
--> 222     raise ValueError('Unknown input')

ValueError: Unknown input"
}

Video or screenshots

image

Expected behavior

No response

How to reproduce the error

No response

Anything else?

No response

chandrevdw31 commented 2 weeks ago

@gaspardc-met please repost this in python sdk repo https://github.com/mindsdb/mindsdb_python_sdk

md-abid-hussain commented 1 week ago

@chandrevdw31 I think it is related to mindsdb-python-sdk

md-abid-hussain commented 1 week ago

@gaspardc-met @chandrevdw31 This is not a bug.

image

As you can see in the method signature above, it supports data input as either DataFrame, Query or dict. The problem here is you are trying to pass a string that is not supported and the error you are getting is Unknown input because the method is checking for input is either of DataFrame, Query or dict, else it's raising the error:

 else:
      raise ValueError('Unknown input')

see line 118 to 222 at model predict method

chandrevdw31 commented 1 week ago

@md-abid-hussain thank you, this was not supposed to be part of the list as it does not have a hacktoberfest label