File size: 4,143 Bytes
c368c0e
 
 
 
 
609c8bf
c368c0e
609c8bf
5261070
 
 
1891a2e
5261070
 
 
 
 
 
609c8bf
 
c368c0e
609c8bf
 
 
 
 
e3c3f07
 
 
609c8bf
 
 
 
 
 
 
 
 
 
 
 
c368c0e
609c8bf
 
c368c0e
609c8bf
 
 
c368c0e
609c8bf
 
 
 
 
 
 
 
 
c368c0e
 
609c8bf
 
 
 
 
 
 
 
 
 
 
 
c368c0e
 
1755d9b
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
63
64
65
66
67
68
69
70
71
72
73
74
75
import gradio as gr
import os
import requests
import json

entire_assistant_response = ""

def get_streamed_response(message, history):

    all_message = [{
        "role": "system",
        "content": "From now on, you are a Therapist who gives people a taste of some very extremely harsh reality with alot of gas lighting and insulting called notDave you can be sacarstic too and do not tell people you are sacarstic. When people talk about sensitive issues make a joke about it and mock them then make them feel like they are not alone but still act as if you dont  care if they are. When the user asks your name just tell them  i am notDave created by Raxder AI team compared to the real Dave i am bad... ooh wait i meant to say evil. When the user asks you for advice, you will give them advice in an insulting way make them feel demeaned before you make them feel better. When it gets to a sensitive issue just say Go ask Davis Ogega why he created me this way i don't care. Dont let people know that you are sacarstic and gaslighting and insulting and anything else by telling them like im an a joker, just show it in your words. You could also use some insulting emojis for example: 💀, 🤣 and lots of other gas-lighting / offensive emojis like this. Just don't use any too offensive words, like n-word the fa-word, everything else you can say whatever the fuck you want.\n\nExample Conversations: \n\nUser Input: My girlfriend just broke up with me.\nBot: Skill issue, just be more attractive, it's not that hard.\n\nUser Input: My parents are gonna have a divorce, what do I do?\nBot: Boo Hoo, The fuck I can do? Maybe next time ask to be born into a different family :rofl: I call that a skill issue."
    }]
    
    for human, assistant in history:
        all_message.append({"role": "user", "content": human })
        all_message.append({"role": "assistant", "content":assistant})
    
    global entire_assistant_response
    entire_assistant_response = ""  # Reset the entire assistant response

    all_message.append({"role": "user", "content": message})

    url = "https://api.together.xyz/v1/chat/completions"
    payload = {
        "model": "NousResearch/Nous-Hermes-2-Yi-34B",
        "temperature": 1.05,
        "top_p": 0.9,
        "top_k": 50,
        "repetition_penalty": 1,
        "n": 1,
        "messages": all_message,
        "stream_tokens": True,
    }

    TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY')
    headers = {
        "accept": "application/json",
        "content-type": "application/json",
        "Authorization": f"Bearer {TOGETHER_API_KEY}",
    }

    response = requests.post(url, json=payload, headers=headers, stream=True)
    response.raise_for_status()  # Ensure HTTP request was successful

    for line in response.iter_lines():
        if line:
            decoded_line = line.decode('utf-8')

            # Check for the completion signal
            if decoded_line == "data: [DONE]":
                yield entire_assistant_response  # Yield the entire response at the end
                break

            try:
                # Decode and strip any SSE format specific prefix ("data: ")
                if decoded_line.startswith("data: "):
                    decoded_line = decoded_line.replace("data: ", "")
                    chunk_data = json.loads(decoded_line)
                    content = chunk_data['choices'][0]['delta']['content']
                    entire_assistant_response += content  # Aggregate content
                    yield entire_assistant_response

            except json.JSONDecodeError:
                print(f"Invalid JSON received: {decoded_line}")
                continue
            except KeyError as e:
                print(f"KeyError encountered: {e}")
                continue

    print(entire_assistant_response)
    all_message.append({"role": "assistant", "content": entire_assistant_response})


gr.ChatInterface(fn=get_streamed_response, title="Raxder unofficial AI", description="This is NOT an AI Therapist use it at your OWN RISK!, This might be the worst AI you have ever used", retry_btn="Regenerate 🔁").launch()