Skip to content

Commit

Permalink
conform all files to PEP8 standards
Browse files Browse the repository at this point in the history
  • Loading branch information
Noblesix960 committed Jul 24, 2024
1 parent ee968da commit a23d56a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
8 changes: 5 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from prank_line_crafter.story_generator import generate_complete_story
from prank_line_crafter.sender import send_story
import os


def get_names_from_file(filename):
"""Read names from the specified file."""
Expand All @@ -12,19 +12,21 @@ def get_names_from_file(filename):
print(f"The file {filename} does not exist.")
return []


def main():
names_file = 'names.txt'
names = get_names_from_file(names_file)

for i, name in enumerate(names, start=1):
print(f"{i}: Processing {name}... ", end="")

# Generate a funny story for the current name
story = generate_complete_story(name)

# Send the story to the server
result = send_story(name, story)
print(result)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion prank_line_crafter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
URL = os.getenv("URL")

if not LLAMA_API_TOKEN or not URL:
raise ValueError("Missing required environment variables: LLAMA_API_TOKEN or URL")
raise ValueError("Missing: LLAMA_API_TOKEN or URL")
1 change: 1 addition & 0 deletions prank_line_crafter/sender.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
from .config import URL


def send_story(name, story):
"""Send the generated story to the server."""
data = {
Expand Down
4 changes: 3 additions & 1 deletion prank_line_crafter/story_generator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from llamaapi import LlamaAPI
from .config import LLAMA_API_TOKEN


def generate_complete_story(name):
"""Generate a funny story about the given name using LlamaAPI."""
llama = LlamaAPI(LLAMA_API_TOKEN)
api_request_json = {
"messages": [
{"role": "user", "content": f"Generate a funny story about a person named {name}."}
{"role": "user",
"content": f"Generate a funny story about a person named {name}"}
],
"max_tokens": 500,
"stream": False
Expand Down
8 changes: 4 additions & 4 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import unittest
from unittest.mock import patch, MagicMock
from prank_line_crafter.story_generator import generate_complete_story
from main import get_names_from_file, main
from main import get_names_from_file
import os
import io
import sys


class TestMain(unittest.TestCase):

Expand Down Expand Up @@ -40,5 +39,6 @@ def test_get_names_from_file(self):
# Assert that the names list matches the expected list
self.assertEqual(names, ['Alice', 'Bob', 'Charlie'])


if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit a23d56a

Please sign in to comment.