MCPcopy Create free account
hub / github.com/AsyncFuncAI/deepwiki-open / test_streaming_endpoint

Function test_streaming_endpoint

tests/api/test_api.py:5–58  ·  view source on GitHub ↗

Test the streaming endpoint with a given repository URL and query. Args: repo_url (str): The GitHub repository URL query (str): The query to send file_path (str, optional): Path to a file in the repository

(repo_url, query, file_path=None)

Source from the content-addressed store, hash-verified

3import sys
4
5def test_streaming_endpoint(repo_url, query, file_path=None):
6 """
7 Test the streaming endpoint with a given repository URL and query.
8
9 Args:
10 repo_url (str): The GitHub repository URL
11 query (str): The query to send
12 file_path (str, optional): Path to a file in the repository
13 """
14 # Define the API endpoint
15 url = "http://localhost:8000/chat/completions/stream"
16
17 # Define the request payload
18 payload = {
19 "repo_url": repo_url,
20 "messages": [
21 {
22 "role": "user",
23 "content": query
24 }
25 ],
26 "filePath": file_path
27 }
28
29 print(f"Testing streaming endpoint with:")
30 print(f" Repository: {repo_url}")
31 print(f" Query: {query}")
32 if file_path:
33 print(f" File Path: {file_path}")
34 print("\nResponse:")
35
36 try:
37 # Make the request with streaming enabled
38 response = requests.post(url, json=payload, stream=True)
39
40 # Check if the request was successful
41 if response.status_code != 200:
42 print(f"Error: {response.status_code}")
43 try:
44 error_data = json.loads(response.content)
45 print(f"Error details: {error_data.get('detail', 'Unknown error')}")
46 except:
47 print(f"Error content: {response.content}")
48 return
49
50 # Process the streaming response
51 for chunk in response.iter_content(chunk_size=None):
52 if chunk:
53 print(chunk.decode('utf-8'), end='', flush=True)
54
55 print("\n\nStreaming completed successfully.")
56
57 except Exception as e:
58 print(f"Error: {str(e)}")
59
60if __name__ == "__main__":
61 # Get command line arguments

Callers 1

test_api.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected