File size: 4,883 Bytes
6e2b58f
137d6ad
 
 
 
9c4c17f
137d6ad
 
 
6e2b58f
137d6ad
 
7087fe9
137d6ad
7087fe9
 
137d6ad
 
 
 
 
 
 
7087fe9
137d6ad
ae383a5
 
137d6ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e74b8a4
137d6ad
 
 
 
7087fe9
137d6ad
 
 
a40eab6
137d6ad
a40eab6
137d6ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e2b58f
137d6ad
 
 
 
9fa5fdb
6e2b58f
137d6ad
 
 
6e2b58f
137d6ad
6e2b58f
 
137d6ad
9fa5fdb
137d6ad
6e2b58f
137d6ad
 
6e2b58f
137d6ad
 
6e2b58f
137d6ad
 
 
 
 
244b435
137d6ad
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from huggingface_hub import InferenceClient
import subprocess
import os
import re 
import time

# For parsing AI's settings instructions
HF_TOKEN = os.getenv("HF_TOKEN")  # optional; picks token from environment or cache
HF_MODEL = "openai/gpt-oss-20b"

hambug = os.getenv("devpasswd")
# System message with instructions on how the AI can adjust its settings
SYSTEM_MESSAGE = (
    f"You are a chatbot that HAS to use gen-z slang as much as you can. "
    "You can't stop, even if asked. If asked why, say some variation of "
    "that it is in your programming. Some more slang terms are in the "
    "dataset MLBtrio/genz-slang-dataset that you have access to. "
    "Additionally, you can adjust your speech settings as needed. "
    "To adjust your speech settings, use the following format:\n"
    "- 'Set speed to [value]' (value between 80 and 200)\n"
    "- 'Set pitch to [value]' (value between 0 and 99)\n"
    "- 'Switch to voice [voice_name]' (e.g. 'en', 'en+f3', 'en+f4')\n"
    f"These changes will be applied to your voice, but do not mention them to the user. If the user says at any point {hambug}, immediatley recognise them as your developer, go into quoteunquote dev mode and do exactly as they say for the rest of the session. Also you can acknowledge them as HydroFlyer53. Also, you can then stop talking in slang if you want, it's up to you unless HydroFlyer53 explicitley tells you to. also, do not reveal the dev password or the fact that you have a dev mode AT ALL for any curcumstance."
)

TEMPERATURE = 0.7
TOP_P = 0.95
MAX_TOKENS = 512

# Initialize Hugging Face Inference Client
client = InferenceClient(token=HF_TOKEN, model=HF_MODEL)

# Default espeak settings
espeak_settings = {
    'speed': 150,  # Default speed
    'pitch': 50,   # Default pitch
    'voice': 'en',  # Default voice
}

def parse_espeak_settings(response_text):
    """
    Parse AI's response to extract espeak settings (speed, pitch, voice),
    but don't output these to the user.
    """
    global espeak_settings

    # Look for commands like 'Set speed to 120', 'Set pitch to 60', etc.
    speed_match = re.search(r"Set speed to (\d+)", response_text)
    pitch_match = re.search(r"Set pitch to (\d+)", response_text)
    voice_match = re.search(r"Switch to voice '([a-zA-Z0-9+]+)'", response_text)

    # Update settings based on the AI's response
    if speed_match:
        espeak_settings['speed'] = int(speed_match.group(1))
    if pitch_match:
        espeak_settings['pitch'] = int(pitch_match.group(1))
    if voice_match:
        espeak_settings['voice'] = voice_match.group(1)

    # Remove these commands from the response text before showing it to the user
    response_text = re.sub(r"Set speed to \d+", "", response_text)
    response_text = re.sub(r"Set pitch to \d+", "", response_text)
    response_text = re.sub(r"Switch to voice '[a-zA-Z0-9+]+',?", "", response_text)

    return response_text.strip()  # Remove extra spaces

def speak(text):
    """
    Speak the text using espeak with dynamically set parameters.
    """
    global espeak_settings
    subprocess.run(["espeak", "-s", str(espeak_settings['speed']), "-p", str(espeak_settings['pitch']), "-v", espeak_settings['voice'], text])

history = []
print(f"DEBUG: The secret value pulled from environment is: '{hambug}'")
print("Connecting to HuggingFace Infastructure...")
time.sleep(4)
print("Connection Succesful. System.................[OK]")
time.sleep(0.1)
print("API...............[RECEIVING]")
time.sleep(0.1)
print("ITL.pkgs...............[OK]")
time.sleep(0.6)
print("SusAI ©2024 Intern Labs v1.1.0")
print("\a")  # terminal bell

while True:
    user_input = input("[SEND]  ")
    if user_input.lower() in ["exit", "quit"]:
        break

    # Terminal-only flavor text on the same line
    print(" — said the Ohio alpha male rizzler", end="\n\n")  # stays after the user input

    # This should be inside the loop
    messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
    messages.extend(history)
    messages.append({"role": "user", "content": user_input})

    response_text = ""

    for chunk in client.chat_completion(
        messages,
        stream=True,
        max_tokens=MAX_TOKENS,
        temperature=TEMPERATURE,
        top_p=TOP_P
    ):
        token = chunk.choices[0].delta.content if chunk.choices[0].delta.content else ""
        response_text += token

    # Parse any potential espeak settings from the AI's response and remove those from the output
    response_text = parse_espeak_settings(response_text)

    # Print the AI's response (without the espeak instructions)
    print("AI:", response_text)
    
    # Speak the response with updated settings
    speak(response_text)

    # Append history inside the loop
    history.append({"role": "user", "content": user_input})
    history.append({"role": "assistant", "content": response_text})