Skip to content

talk

chat_with_file(path, prompt)

summary

Parameters:

Name Type Description Default
path str

description

required
prompt str

description

required

Returns:

Name Type Description
str str

description

Source code in ttf/talk.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def chat_with_file(path: str, prompt:str) -> str:
    """_summary_

    Args:
        path (str): _description_
        prompt (str): _description_

    Returns:
        str: _description_
    """

    if path.endswith('.pdf'):
        reader = PdfReader(path)
        text = "\n".join([page.extract_text() for page in reader.pages])

    elif path.endswith('.txt'):
        text = open(path, 'r').read()
    else:
        extension = path.split('.')[-1]
        raise ValueError(f'Files ending in "{extension}" are not yet supported')

    user_input = prompt + ":\n\n" + text
    chat_with(user_input)