File size: 1,019 Bytes
d7f32ed
 
74a7b28
d7f32ed
1cb9532
d7f32ed
 
29331bd
1cb9532
 
 
 
d7f32ed
 
0218c20
1cb9532
d7f32ed
eb96984
1cb9532
 
d7f32ed
03991d8
cc3751a
 
 
664b22f
cc3751a
 
 
 
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
from hugchat import hugchat
from hugchat.login import Login
import os

# Credentials
EMAIL = os.getenv("EMAIL")
PASSWD = os.getenv("PASSWD")

# Path to store cookies
cookie_path_dir = "./cookies/"  # Make sure this directory exists

# Log in and get cookies
sign = Login(EMAIL, PASSWD)
cookies = sign.login(cookie_dir_path=cookie_path_dir, save_cookies=True)

# Create ChatBot with cookies
chatbot = hugchat.ChatBot(cookies=cookies.get_dict())

# 🔁 Create a new conversation with a custom assistant ID
ASSISTANT_ID = "66017fca58d60bd7d5c5c26c"  # Replace with your actual assistant ID
chatbot.new_conversation(assistant=ASSISTANT_ID, switch_to=True)

# 🔁 Stream response character-by-character as it generates
print("Assistant:", end=" ", flush=True)
for token in chatbot.chat("Hello, how can I help you today?", stream=True):
    

# Optionally: web search example
# response = chatbot.chat("How many models stored in huggingface?", web_search=True)
# print("\n\nWeb Search Result:", response.wait_until_done())