Skip to content

Commit

Permalink
Support for Python 3.8; backing off on chat support since we now have…
Browse files Browse the repository at this point in the history
… litellm.
  • Loading branch information
emeryberger committed Feb 5, 2024
1 parent 78349c8 commit 16aed97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [
]
description = "Utilities for our LLM projects (CWhy, ChatDBG, ...)."
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
Expand Down
2 changes: 1 addition & 1 deletion src/llm_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .utils import *
from .chat import *
# from .chat import *
12 changes: 6 additions & 6 deletions src/llm_utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import json
import textwrap
from typing import Any
from typing import Any, Dict, List, Tuple

import tiktoken

Expand Down Expand Up @@ -134,7 +134,7 @@ def word_wrap_except_code_blocks(text: str, width: int = 80) -> str:
return "\n\n".join(["\n".join(b) for b in blocks])


def read_lines(file_path: str, start_line: int, end_line: int) -> tuple[list[str], int]:
def read_lines(file_path: str, start_line: int, end_line: int) -> Tuple[List[str], int]:
"""
Read lines from a file.
Expand Down Expand Up @@ -172,12 +172,12 @@ def truncate(s: str, l: int) -> str:
return (lines[start_line - 1 : end_line], start_line)


def number_group_of_lines(group: list[str], first: int, strip: bool = True) -> str:
def number_group_of_lines(group: List[str], first: int, strip: bool = True) -> str:
"""
Add line numbers for each line in the input list.
Args:
group (list[str]): The lines to number.
group (List[str]): The lines to number.
first (int): The number for the first line.
strip (bool): Whether to strip leading and trailing blank lines.
Expand Down Expand Up @@ -231,13 +231,13 @@ def contains_valid_json(my_string: str) -> Any:
return None


def extract_code_blocks(text: str) -> list[str]:
def extract_code_blocks(text: str) -> List[str]:
pattern = r"```(python)?(.*?)```"
blocks = re.findall(pattern, text, re.DOTALL)
return [block[1].strip() for block in blocks]


def parse_chatlog(log: str) -> list[dict[str, str]]:
def parse_chatlog(log: str) -> List[Dict[str, str]]:
entries = log.split("\n\n") # split entries by empty lines
result = []
for entry in entries:
Expand Down

0 comments on commit 16aed97

Please sign in to comment.