Spaces:
Running
Running
Update docstrings and remove unused imports
Browse files
src/slidedeckai/core.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
Core functionality of
|
| 3 |
"""
|
| 4 |
import logging
|
| 5 |
import os
|
|
|
|
| 1 |
"""
|
| 2 |
+
Core functionality of SlideDeck AI.
|
| 3 |
"""
|
| 4 |
import logging
|
| 5 |
import os
|
src/slidedeckai/helpers/chat_helper.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
| 1 |
"""
|
| 2 |
-
Chat helper classes
|
| 3 |
"""
|
| 4 |
-
import streamlit as st
|
| 5 |
|
| 6 |
|
| 7 |
class ChatMessage:
|
| 8 |
"""Base class for chat messages."""
|
| 9 |
-
|
| 10 |
def __init__(self, content: str, role: str):
|
| 11 |
self.content = content
|
| 12 |
self.role = role
|
|
@@ -34,11 +33,14 @@ class ChatMessageHistory:
|
|
| 34 |
self.messages = []
|
| 35 |
|
| 36 |
def add_user_message(self, content: str):
|
|
|
|
| 37 |
self.messages.append(HumanMessage(content))
|
| 38 |
|
| 39 |
def add_ai_message(self, content: str):
|
|
|
|
| 40 |
self.messages.append(AIMessage(content))
|
| 41 |
|
|
|
|
| 42 |
class ChatPromptTemplate:
|
| 43 |
"""Template for chat prompts."""
|
| 44 |
|
|
|
|
| 1 |
"""
|
| 2 |
+
Chat helper: message classes and history.
|
| 3 |
"""
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
class ChatMessage:
|
| 7 |
"""Base class for chat messages."""
|
| 8 |
+
|
| 9 |
def __init__(self, content: str, role: str):
|
| 10 |
self.content = content
|
| 11 |
self.role = role
|
|
|
|
| 33 |
self.messages = []
|
| 34 |
|
| 35 |
def add_user_message(self, content: str):
|
| 36 |
+
"""Append user message to the history."""
|
| 37 |
self.messages.append(HumanMessage(content))
|
| 38 |
|
| 39 |
def add_ai_message(self, content: str):
|
| 40 |
+
"""Append AI-generated response to the history."""
|
| 41 |
self.messages.append(AIMessage(content))
|
| 42 |
|
| 43 |
+
|
| 44 |
class ChatPromptTemplate:
|
| 45 |
"""Template for chat prompts."""
|
| 46 |
|
src/slidedeckai/helpers/llm_helper.py
CHANGED
|
@@ -3,7 +3,6 @@ Helper functions to access LLMs using LiteLLM.
|
|
| 3 |
"""
|
| 4 |
import logging
|
| 5 |
import re
|
| 6 |
-
import sys
|
| 7 |
import urllib3
|
| 8 |
from typing import Tuple, Union, Iterator, Optional
|
| 9 |
|
|
|
|
| 3 |
"""
|
| 4 |
import logging
|
| 5 |
import re
|
|
|
|
| 6 |
import urllib3
|
| 7 |
from typing import Tuple, Union, Iterator, Optional
|
| 8 |
|
src/slidedeckai/helpers/text_helper.py
CHANGED
|
@@ -8,10 +8,12 @@ def is_valid_prompt(prompt: str) -> bool:
|
|
| 8 |
"""
|
| 9 |
Verify whether user input satisfies the concerned constraints.
|
| 10 |
|
| 11 |
-
:
|
| 12 |
-
|
| 13 |
-
"""
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
if len(prompt) < 7 or ' ' not in prompt:
|
| 16 |
return False
|
| 17 |
|
|
@@ -24,10 +26,12 @@ def get_clean_json(json_str: str) -> str:
|
|
| 24 |
trailing ``` and any text beyond that.
|
| 25 |
CAUTION: May not be always accurate.
|
| 26 |
|
| 27 |
-
:
|
| 28 |
-
|
| 29 |
-
"""
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
response_cleaned = json_str
|
| 32 |
|
| 33 |
if json_str.startswith('```json'):
|
|
@@ -55,10 +59,12 @@ def fix_malformed_json(json_str: str) -> str:
|
|
| 55 |
"""
|
| 56 |
Try and fix the syntax error(s) in a JSON string.
|
| 57 |
|
| 58 |
-
:
|
| 59 |
-
|
| 60 |
-
"""
|
| 61 |
|
|
|
|
|
|
|
|
|
|
| 62 |
return jr.repair_json(json_str, skip_json_loads=True)
|
| 63 |
|
| 64 |
|
|
|
|
| 8 |
"""
|
| 9 |
Verify whether user input satisfies the concerned constraints.
|
| 10 |
|
| 11 |
+
Args:
|
| 12 |
+
prompt: The user input text.
|
|
|
|
| 13 |
|
| 14 |
+
Returns:
|
| 15 |
+
True if all criteria are satisfied; False otherwise.
|
| 16 |
+
"""
|
| 17 |
if len(prompt) < 7 or ' ' not in prompt:
|
| 18 |
return False
|
| 19 |
|
|
|
|
| 26 |
trailing ``` and any text beyond that.
|
| 27 |
CAUTION: May not be always accurate.
|
| 28 |
|
| 29 |
+
Args:
|
| 30 |
+
json_str: The input string in JSON format.
|
|
|
|
| 31 |
|
| 32 |
+
Returns:
|
| 33 |
+
The "cleaned" JSON string.
|
| 34 |
+
"""
|
| 35 |
response_cleaned = json_str
|
| 36 |
|
| 37 |
if json_str.startswith('```json'):
|
|
|
|
| 59 |
"""
|
| 60 |
Try and fix the syntax error(s) in a JSON string.
|
| 61 |
|
| 62 |
+
Args:
|
| 63 |
+
json_str: The input JSON string.
|
|
|
|
| 64 |
|
| 65 |
+
Returns:
|
| 66 |
+
The fixed JSOn string.
|
| 67 |
+
"""
|
| 68 |
return jr.repair_json(json_str, skip_json_loads=True)
|
| 69 |
|
| 70 |
|