Skip to content

Commit

Permalink
Merge branch 'solution'
Browse files Browse the repository at this point in the history
  • Loading branch information
apradoada committed Dec 6, 2024
2 parents 1b93f8d + ed49f1b commit 033c541
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
Part 1 - Setup

Clone the Pet Name Generator Repo
Create your venv
Install your requirements.txt
Create two databases in psql called pet_name_gen_dev and pet_name_gen_test
Create your .env file and add pet_name_gen_dev and pet_name_gen_test as the SQLALCHEMY_DATABASE_URI and the SQLALCHEMY_TEST_DATABASE_URI respectively.
Run your flask db init, flask db migrate and flask db upgrade
If you want, check your database to make sure it has the pet relation
1. Clone the Pet Name Generator Repo
2. Create your venv
3. Install your requirements.txt
4. Create two databases in psql called pet_name_gen_dev and pet_name_gen_test
5. Create your .env file and add pet_name_gen_dev and pet_name_gen_test as the SQLALCHEMY_DATABASE_URI and the SQLALCHEMY_TEST_DATABASE_URI respectively.
6. Run your flask db init, flask db migrate and flask db upgrade
7. If you want, check your database to make sure it has the pet relation

Part 2 - Install OpenAI

Install the OpenAI python library using pip
Run the command pip freeze > requirements.txt to add OpenAI to the requirements file
Add your OpenAI (or Llama) Secret key to your .env file
Import OpenAI into your pet_routes.py file
Create an OpenAI client in your pet_routes.py file
If you are using llama, route the OpenAI client to the llama api using these instructions.
1. Install the OpenAI python library using pip
2. Run the command pip freeze > requirements.txt to add OpenAI to the requirements file
3. Add your Gemini Secret key to your .env file
4. Import genai into your pet_routes.py file
5. Create an Gemini client in your pet_routes.py file

Part 3 - Write Your Pet Name POST Route

Now that everything is set up and OpenAI has been installed, write a helper function that will take the correct parameters to generate a suggestion for a pet’s name given its species, color and personality. Work with your group to write a prompt to feed into either OpenAI or Llama that will generate a name for your pet with the parameters given. Feel free to test out a few prompts and make sure to use print statements to analyze the response you get from each.
Once you’ve got a working prompt and feel satisfied with your understanding of the response, write the add_pet function to add a pet to the database. Your request body should only include the pet’s species (type), personality and color. The name should be generated using AI and then added to the Pet object which then gets sent to the database. Remember that you may have to tweak the string you receive in order to effectively add it to the Pet object. When you are finished, write a GET method that will return a list of the Pet objects.
1. Now that everything is set up and OpenAI has been installed, write a helper function that will take the correct parameters to generate a suggestion for a pet’s name given its species, color and personality.
2. Work with your group to write a prompt to feed into either OpenAI or Llama that will generate a name for your pet with the parameters given. Feel free to test out a few prompts and make sure to use print statements to analyze the response you get from each.
3. Once you’ve got a working prompt and feel satisfied with your understanding of the response, write the add_pet function to add a pet to the database. Your request body should only include the pet’s species (type), personality and color. The name should be generated using AI and then added to the Pet object which then gets sent to the database. Remember that you may have to tweak the string you receive in order to effectively add it to the Pet object. When you are finished, write a GET method that will return a list of the Pet objects.

Part 4 - (Optional) Write a PATCH Route

Expand Down
2 changes: 1 addition & 1 deletion app/models/pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Pet(db.Model):
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
name: Mapped[Optional[str]]
name: Mapped[str]
animal_type: Mapped[str]
personality: Mapped[str]
color: Mapped[str]
Expand Down
3 changes: 2 additions & 1 deletion app/routes/pet_routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Blueprint, jsonify, request, abort, make_response
from flask import Blueprint, request, abort, make_response
from ..db import db
from ..models.pet import Pet

Expand All @@ -17,6 +17,7 @@ def create_pet():
except KeyError as e:
abort(make_response({"message": f"missing required value: {e}"}, 400))


@bp.get("")
def get_pets():
pet_query = db.select(Pet)
Expand Down
36 changes: 36 additions & 0 deletions migrations/versions/b69c72688ecc_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""empty message
Revision ID: b69c72688ecc
Revises: d066cb56e11a
Create Date: 2024-12-06 09:53:41.147503
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'b69c72688ecc'
down_revision = 'd066cb56e11a'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('pet', schema=None) as batch_op:
batch_op.alter_column('name',
existing_type=sa.VARCHAR(),
nullable=False)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('pet', schema=None) as batch_op:
batch_op.alter_column('name',
existing_type=sa.VARCHAR(),
nullable=True)

# ### end Alembic commands ###

0 comments on commit 033c541

Please sign in to comment.