File size: 1,662 Bytes
d0f4923
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# import chainlit as cl

# @cl.on_message
# def main(message:str):
#     result = message.title()

#     cl.Message(content= f"sure here is your message: {result}").send()


# @cl.on_chat_start
# def chat():
#     content = "Hi welcome to teslabot what can I do for you?"
#     cl.Message(content=content).send()

import chainlit as cl
from textblob import TextBlob
from gpt4all import GPT4All


gpt = GPT4All(model_name='nous-hermes-13b.ggmlv3.q4_0.bin', model_path='models')


@cl.on_chat_start
async def start():
    # Send the first message without the elements
    content = "Hi, this is TeslaBot how can I help you?"

    await cl.Message(
        content=content,
    ).send()

    # elements = [
    #     cl.Image(path="images/avatar.jpeg", name="image1", display="inline"),
    #     cl.Text(content="Here is a side text document", name="text1", display="side"),
    #     cl.Text(content="Here is a page text document", name="text2", display="page"),
    #]

    # Send the second message with the elements
    # await cl.Message(
    #     content=content,
    #     #elements=elements,
    # ).send()


@cl.on_message
async def message(text:str):
    # logic
    if 'count' in text:
        file = None
        while file == None:
            file = await cl.AskFileMessage(
                content='please upload the file here',
                accept=['text/plain']).send()
            
        text = file[0].content.decode("utf-8")
        count = len(text)

        await cl.Message(content = f'The word count of your text is: {count} ').send()
    else:
        response = gpt.generate(text, temp=0.65)
        await cl.Message(f'{response}')