Skip to content

Commit

Permalink
Merge pull request #29 from software-students-fall2023/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
zeepxnflrp authored Nov 9, 2023
2 parents 9e2a237 + 5bf8e0f commit 107e727
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 39 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include src/pyrizz/data *
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,45 @@ In this function, you can retreive any random pickup line from a specific catego
```
from pyrizz import pyrizz
print(pyrizz.get_random_categoryy_line('romantic'))
print(pyrizz.get_random_categoryy_line('clever'))
print(pyrizz.get_random_categoryy_line('geeky'))
print(pyrizz.get_random_categoryy_line('dev'))
print(pyrizz.get_random_category_line('romantic'))
print(pyrizz.get_random_category_line('clever'))
print(pyrizz.get_random_category_line('geeky'))
print(pyrizz.get_random_category_line('dev'))
```

### get_ai_line(keyword)
### get_ai_line(keyword, your_openai_key)

In this function, you can retreive a generated pickup line using openai based on any keyword that you suggest. In this example, it would output a Shakespearean pickup line:
In this function, you can retreive a generated pickup line using openai gpt-3.5 model based on any keyword that you suggest. In this example, it would output a Shakespearean pickup line:

```
from pyrizz import pyrizz
import openai
print(pyrizz.get_ai_line('shakespeare'))
openai.api_key = "..."
print(pyrizz.get_ai_line("Shakespeare", openai))
```

### rate_line(pickup_line)
### rate_line(pickup_line, your_openai_key)

In this function, you can rate your very own pickup line out of 10 using openai. Simply type your pickup line and a rating will output:
In this function, you can rate your very own pickup line out of 10 using openai gpt-3.5 model. Simply type your pickup line and a rating will output:

```
from pyrizz import pyrizz
import openai
print(pyrizz.rate_line('Are you from Tennesse? Cause you're the only 10 I see.'))
openai.api_key = "..."
print(pyrizz.rate_line('Are you from Tennesse? Cause you're the only 10 I see.', openai))
```

Note: Please make sure you are using `openai==0.28.1`.
### create_line(template_number, words)

In this function, if you're new to pickup lines, you can create your very own pickup using some of our templates!
- **template_number** - You need to input a template number (0-39). You can find out the templates by calling the list_templates() function: `print(pyrizz.list_templates())`. This way you can see how the templates look like, how many words you need to include and which one you like!
- **template_number** - You need to input a template number (0-39). You can find out the templates by calling the list_templates() function: `templates = pyrizz.list_templates()`. This way you can see how the templates look like, how many words you need to include and which one you like! You can print these templates like this:
```
for idx, template in enumerate(templates, 1):
print(f"Template {idx}: {template}")
```
- **words** - You need to input a list of all the words, for example if you need to input 2 words: `words = ["word1", "word2"]`

This function returns your line with some lovely ASCII art as well! Enjoy!
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "pyrizz"
description = "A package where users can receive pick up lines, rate pickup lines and add pickup lines"
version = "0.0.91"
version = "1.0.5"
authors = [
{ name="Aditya Pandhare", email="[email protected]" },
{ name="Anzhelika Nastashchuk", email="[email protected]" },
Expand Down Expand Up @@ -33,3 +33,6 @@ dev = ["pytest"]

[project.scripts]
pyrizz = "pyrizz.__main__:main"

[tool.setuptools.package-data]
"pyrizz" = ["data/*"]
6 changes: 4 additions & 2 deletions src/pyrizz/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pyrizz as pyrizz
import pyrizz.pyrizz as pyrizz
import openai

"""Main function for PyRizz."""
Expand Down Expand Up @@ -77,7 +77,9 @@ def main():

elif user_input == "6":
print("Here are the available templates:")
pyrizz.list_templates()
templates = pyrizz.list_templates()
for idx, template in enumerate(templates, 1):
print(f"Template {idx}: {template}")

elif user_input == "7":
print("Please enter your API key.")
Expand Down
39 changes: 20 additions & 19 deletions src/pyrizz/pyrizz.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import random
import pathlib
import json
from pyrizz.pickuplines import pickuplines
from pyrizz.templates import templates

Expand Down Expand Up @@ -66,8 +65,13 @@ def load_ascii_art(filename):
with open(filename, 'r', encoding='utf-8') as file:
content = file.read()
ascii_art_pieces = content.split('[End]')
ascii_art_pieces = [piece.strip()[len('[Start]'):].strip() for piece in ascii_art_pieces if piece.strip()]
return ascii_art_pieces
cleaned_ascii_art_pieces = []
for piece in ascii_art_pieces:
if '[Start]' in piece:
start_index = piece.find('[Start]') + len('[Start]')
art_piece = piece[start_index:]
cleaned_ascii_art_pieces.append(art_piece)
return cleaned_ascii_art_pieces

def create_line(template_number, words):
if not (0 <= template_number < len(templates)):
Expand All @@ -92,12 +96,16 @@ def create_line(template_number, words):
return None, "Your line doesn't pass our checks. Sorry!"

def get_user_input_for_line():
print("Choose a template number (0-{}):".format(len(templates)))
template_number = int(input("> ")) - 1
print("Choose a template number (0-{}):".format(len(templates) - 1))
try:
template_number = int(input("> "))
except ValueError:
print("Invalid input. Please enter an integer value.")
return None, None

if template_number not in range(len(templates)):
print("Invalid template number. Please choose a number between 0 and {}.".format(len(templates) - 1))
return None, None
return None, None

template_to_show = templates[template_number]
placeholders_count = template_to_show.count("{}")
Expand All @@ -106,28 +114,21 @@ def get_user_input_for_line():
print(template_to_show.format(*(['______'] * placeholders_count)))

print(f"Enter {placeholders_count} word(s) separated by commas to fill into the template:")
words = input("> ").split(',')
words = [word.strip() for word in words]
words_input = input("> ")
words = [word.strip() for word in words_input.split(',')]

if len(words) != placeholders_count:
print(f"Incorrect number of words. You need to provide exactly {placeholders_count} word(s).")
return None, None

return template_number, words

def is_line_valid(user_line):
if len(user_line) > 140:
print("Your pick-up line is too long.")
return False

#if is_offensive(user_line):
#return False

return True

#def is_offensive(text):
# if profanity.contains_profanity(text):
# return True
# else:
# return False

def list_templates():
for idx, template in enumerate(templates, 1):
print(f"Template {idx}: {template}")
return templates
6 changes: 0 additions & 6 deletions tests/test_pyrizz.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ def test_is_line_valid_length(self):
long_line = "x" * 141
assert not pyrizz.is_line_valid(long_line), "Expected the line to be flagged as too long."

@patch("builtins.input", side_effect=["1", "word1, word2"])
def test_get_user_input_for_line(self, mock_input):
template_number, words = pyrizz.get_user_input_for_line()
assert template_number == 0
assert words == ["word1", "word2"]

def test_create_line_invalid_template_number(self):
_, message = pyrizz.create_line(999, ["word1", "word2"])
assert message == "Template number out of range. Please choose between 0 and {}.".format(len(pyrizz.templates) - 1)
Expand Down

0 comments on commit 107e727

Please sign in to comment.