File size: 2,199 Bytes
a57c7fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import json

# url = "http://localhost:8000/chat"  # Change to your server address if different

# payload = {
#     "message": "Hello, how are you?",
#     "messages": [
#         {
#             "role": "system",
#             "content": [
#                 {
#                     "type": "text",
#                     "text": "You are a helpful assistant."
#                 }
#             ]
#         }
#     ],
#     "model": "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8"
# }

# headers = {
#     "Content-Type": "application/json"
# }

# response = requests.post(url, data=json.dumps(payload), headers=headers, stream=True)

# if response.status_code == 200:
#     print("Streaming response:\n")
#     try:
#         for line in response.iter_lines(decode_unicode=True):
#             if line:
#                 print(line)
#     except KeyboardInterrupt:
#         print("\nStopped streaming.")
# else:
#     print("Error:", response.status_code)
#     print(response.text)


url = "http://localhost:8000/generate-topics"
payload = {
    "searchQuery": "Introduction linear integrated circuits"
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, data=json.dumps(payload), headers=headers, stream=True)

if response.status_code == 200:
    print("Streaming response:\n")
    try:
        for line in response.iter_lines(decode_unicode=True):
            if line:
                if line.startswith("data: "):
                    # Parse the JSON data after "data: "
                    try:
                        json_data = json.loads(line[6:])  # Skip "data: " prefix
                        if "choices" in json_data and json_data["choices"]:
                            if "text" in json_data["choices"][0]:
                                print(json_data["choices"][0]["text"], end="", flush=True)
                    except json.JSONDecodeError:
                        # Handle special case for [DONE]
                        if line[6:] == "[DONE]":
                            break
    except KeyboardInterrupt:
        print("\nStopped streaming.")
else:
    print("Error:", response.status_code)
    print(response.text)