File size: 2,418 Bytes
e4fe207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import g4f
import time


def sentiment_func(message_list):
    message_list=[
        "Your lectures were so dull and uninspiring, I couldn't help but zone out", 
        "you have an extraordinary talent for leadership.",
        "The instructor's indifference made it difficult to remain engaged or motivated",
        "The lack of enthusiasm from the instructor made the class feel like a chore",
        "Salamat sa iyong inspirasyon at dedikasyon sa aming edukasyon.",
        "Sa bawat pagkakataon, lumalalim ang aming pag-unawa sa mga aralin.",
        "Thanks for being dedicated to our education.",
        "You show the societal importance of education.",
        "The instructor's disinterested demeanor was reflected in the overall class atmosphere"
    ]
    
    message_list = '[label]\n'.join(message_list)
    # print(message_list)
    prompt = f"""
    Please provide a single-word response per sentence.
    label the following sentences if it is positive,negative
    sentence list = {message_list}
    your output is should in comma separated
    example output : positive,negative,negative,positive
    """
            # Please provide a single-word response.
            
    print(prompt)
    while True:
        try:
            # streamed completion
            response = g4f.ChatCompletion.create(
                model="gpt-3.5-turbo",
                # provider=g4f.Provider.GeekGpt,
                provider=g4f.Provider.You,

                # model="gpt-4",
                # provider=g4f.Provider.Bing,
                
                messages=[{"role": "user", "content": prompt}],
                stream=True,
            )
            returned_output = ""
            for message in response:
                # print(message, flush=True, end='')
                returned_output += message
                # print(message)
            returned_output = returned_output.split(',')
            # Trim extra white spaces and convert to lowercase
            returned_output = [item.strip().lower() for item in returned_output]
            return returned_output
            # print(returned_output)
            break  # Exit the loop if the chat completes successfully

        except Exception as e:
            # Handle the error (e.g., log it or take appropriate action)
            # Sleep for a moment before retrying
            print("error....",e)
            time.sleep(0.4)