0

I am getting the response from a LLM called Moondream from Ollama. And there is nothing wrong with it because I tried to debug by print out its response, and it was fine. I believe that the problem lies in the database. I have two models in my database, one is "users" and the other is "personal_guide". The "users" works fine with authentication (log in, sign up) but the personal_guide just cannot. It always gets unexpected keyword argument.

Here is the error: image from traceback

Here is my models.py:

class users(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(100), unique=True, nullable=False)
    name = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    personal_guide = db.relationship('personal_guide')
    def __init__(self, email, name, password):
        self.email = email
        self.name = name
        self.password = password

class personal_guide(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    def __init__(self, content, user_id):
        self.content = content
        self.user_id = user_id

Here is my views.py (I use the Blueprint - auth and views instead of app):

@views.route('/', methods=["GET", "POST"])
@login_required
def homepage():
    if request.method == "POST":
        user_input = request.form.get('user_input') 
        response = str(moondream(user_input))
        print(response) #for debugging purpose
        print(current_user.id) #for debugging purpose
        try:
            user_info = personal_guide(content=response, user_id=current_user.id)
            db.session.add(user_info)
            db.session.commit()
            ai = personal_guide.query.filter_by(content=response).first()
            print(f"Retrieved guide content: {ai.content}, for user_id: {ai.user_id}") #for debugging purpose
            flash("Content saved", category='success')
        except Exception as e:
            print(f"Error: {e}")
            flash("Error saving content", category='failure')

        return render_template('homepage.html', response=ai.content)
    return render_template('homepage.html', current_user=current_user)

I check word for word, and try to print out response and user_id, all seem to work correctly. I cannot understand what is the problem.

And the result is that it never save the response to the model's content. Please help me! I would really appreciate that! Thanks a lot.

4
  • Please edit the question to include the complete error traceback (if necessary, remove the tryr/except so that the traceback is output). Commented Sep 25, 2024 at 6:31
  • Thank you for looking at my question! I've just upload the image of the error traceback. Could you take a look at it. Thanks a lot. Commented Sep 28, 2024 at 9:10
  • There seems to be a mismatch between the model definition and object in the route. How is it imported? What does print(personnel_guide) output (in the route function)? Commented Sep 30, 2024 at 18:42
  • here are what I import in the views.py to use the database: from website.ollama_test import moondream from .models import users, personal_guide from . import db And personal_guide takes the response of the AI, and insert it into content of that user_id. Commented Oct 1, 2024 at 7:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.