-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreproduce_issue.py
More file actions
76 lines (63 loc) · 2.82 KB
/
reproduce_issue.py
File metadata and controls
76 lines (63 loc) · 2.82 KB
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
import requests
import sys
API_URL = "http://localhost:8001/api/v1"
def reproduce():
# 1. Signup/Login
email = "test@example.com"
password = "password123"
print(f"Attempting to login with {email}...")
response = requests.post(f"{API_URL}/auth/login/access-token", data={"username": email, "password": password})
if response.status_code != 200:
print("Login failed, attempting signup...")
response = requests.post(f"{API_URL}/auth/signup", json={"email": email, "password": password, "full_name": "Test User"})
if response.status_code != 200:
print(f"Signup failed: {response.text}")
return
print("Signup successful, logging in...")
response = requests.post(f"{API_URL}/auth/login/access-token", data={"username": email, "password": password})
if response.status_code != 200:
print(f"Login failed after signup: {response.text}")
return
token = response.json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
print("Login successful.")
# 2. Create Conversation (or get existing)
print("Fetching conversations...")
response = requests.get(f"{API_URL}/chat/conversations", headers=headers)
if response.status_code != 200:
print(f"Failed to fetch conversations: {response.text}")
return
conversations = response.json()
conversation_id = None
if conversations:
conversation_id = conversations[0]["id"]
print(f"Using existing conversation {conversation_id}")
else:
print("No conversations found, will create one with first message.")
# 3. Send Message
print("Sending message...")
message_data = {"query": "Hello, this is a test message."}
if conversation_id:
message_data["conversation_id"] = conversation_id
response = requests.post(f"{API_URL}/chat/", json=message_data, headers=headers)
if response.status_code != 200:
print(f"Failed to send message: {response.text}")
return
response_data = response.json()
conversation_id = response_data["conversation_id"]
print(f"Message sent. Conversation ID: {conversation_id}")
print(f"Response: {response_data['answer']}")
# 4. Get Messages
print(f"Fetching messages for conversation {conversation_id}...")
response = requests.get(f"{API_URL}/chat/{conversation_id}/messages", headers=headers)
if response.status_code != 200:
print(f"Failed to fetch messages: {response.text}")
return
messages = response.json()
with open("reproduce_output.txt", "w") as f:
f.write(f"Messages ({len(messages)}):\n")
for msg in messages:
f.write(f"- [{msg['role']}] {msg['content']}\n")
print("Output written to reproduce_output.txt")
if __name__ == "__main__":
reproduce()