Skip to content

Commit

Permalink
Minor import OCD
Browse files Browse the repository at this point in the history
  • Loading branch information
nicovank committed Feb 5, 2024
1 parent 40588ab commit 42979d8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/llm_utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import re
import json
import textwrap
from typing import Any

import tiktoken
from typing import Any, Dict, List, Optional


# OpenAI specific.
Expand Down Expand Up @@ -230,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 42979d8

Please sign in to comment.