Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split out misc functions #74

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from env_loader import get_env
from utils.openai import initialize_openai, moderate_content, num_tokens_from_string
from utils.elevenlabs import get_voices_data, text_to_speech
from utils.misc import generate_unique_card_id, get_docs

# Load environment variables
OPENAI_API_KEY = get_env("OPENAI_API_KEY")
Expand All @@ -28,27 +29,6 @@
turn_counts = {} # A dictionary to track the turn count for each user
last_received_times = {} # A dictionary to track the last received time for each user

# Function to generate a unique cardId
def generate_unique_card_id():
return f"image_card_{int(datetime.datetime.now().timestamp())}_{uuid.uuid4().hex[:6]}"

def get_docs(doc_name: str) -> str:
try:
# Construct the file path based on the doc_name
file_path = f'docs/{doc_name}.md'

# Read the specified markdown file
with open(file_path, 'r') as file:
content = file.read()

# Split the content at the "---" header line and get the second part
doc_content = content.split("---", 2)[-1].strip()

return doc_content

except Exception as e:
print(f"Error reading {doc_name} content: {str(e)}")
return f'Sorry, I encountered an error retrieving the {doc_name} content.'

def process_event(request):
try:
Expand Down Expand Up @@ -77,6 +57,7 @@ def process_event(request):
print(f"Error processing event: {str(e)}")
return jsonify({'text': 'Sorry, I encountered an error while processing your message.'})


def handle_message(user_id, user_message):
try:
# Check the user input for any policy violations
Expand Down
24 changes: 24 additions & 0 deletions utils/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import datetime
import uuid

# Function to generate a unique cardId
def generate_unique_card_id():
return f"image_card_{int(datetime.datetime.now().timestamp())}_{uuid.uuid4().hex[:6]}"

def get_docs(doc_name: str) -> str:
try:
# Construct the file path based on the doc_name
file_path = f'docs/{doc_name}.md'

# Read the specified markdown file
with open(file_path, 'r') as file:
content = file.read()

# Split the content at the "---" header line and get the second part
doc_content = content.split("---", 2)[-1].strip()

return doc_content

except Exception as e:
print(f"Error reading {doc_name} content: {str(e)}")
return f'Sorry, I encountered an error retrieving the {doc_name} content.'