File size: 973 Bytes
d7f32ed
 
e68e9cf
 
49158eb
e68e9cf
 
 
 
 
 
 
 
 
 
 
29331bd
e68e9cf
 
 
0288607
e68e9cf
 
808ec17
e68e9cf
 
 
1cb9532
03991d8
cc3751a
808ec17
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
from hugchat import hugchat
from hugchat.login import Login
import fastapi
from fastapi import FastAPI, Query
app = FastAPI()
# Your HuggingFace credentials
EMAIL = "[email protected]"
PASSWORD = "Allahisgreatest17"
@app.post("/ask")
def main(prompt: str = Query(..., description="The prompt for the AI")):
    # Login and save cookies (optional cookie path omitted for simplicity)
    sign = Login(EMAIL, PASSWORD)
    cookies = sign.login(save_cookies=True)

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

    # Start a new conversation with your assistant ID
    ASSISTANT_ID = "682e0c1f5f0c3d952a27498e"  # Replace with your assistant ID
    chatbot.new_conversation(assistant=ASSISTANT_ID, switch_to=True)

    # Send message and get the full response (no streaming)
    response = chatbot.chat(f"{prompt}", stream=False)

    # Print full response
    print("Assistant:", response)
    return response