atrmkj commited on
Commit
52f4b0f
·
1 Parent(s): 666d907

initial push

Browse files
README.md CHANGED
@@ -1,13 +1,115 @@
1
- ---
2
- title: MedTranscript QA Agent
3
- emoji: 📚
4
- colorFrom: blue
5
- colorTo: green
6
- sdk: gradio
7
- sdk_version: 5.27.0
8
- app_file: app.py
9
- pinned: false
10
- short_description: A medical Q&A system that intelligently routes queries betwe
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Healthcare Tool-Using AI Agent
2
+
3
+ A medical Q&A system that intelligently routes queries between document retrieval and web search to provide accurate healthcare information.
4
+
5
+ ## Overview
6
+
7
+ This agent leverages two main tools:
8
+ 1. **Document Retrieval**: Uses vector similarity search over medical transcripts
9
+ 2. **Web Search**: Queries the public web for general healthcare information
10
+
11
+ The agent makes intelligent decisions about which tool to use based on the query type. Clinical questions about procedures and diagnoses are typically routed to the document database, while general medical information and recovery timelines are routed to web search.
12
+
13
+ ## Features
14
+
15
+ - **Smart Routing**: Uses Claude 3.7 Sonnet to decide between document search and web search
16
+ - **Vector Similarity Search**: Efficient document retrieval using FAISS and sentence embeddings
17
+ - **Web Search Integration**: DuckDuckGo search for up-to-date medical information
18
+ - **Gradio UI**: User-friendly interface for interacting with the agent
19
+ - **Debug Mode**: Detailed information about tool selection and search results
20
+
21
+ ## Installation
22
+
23
+ 1. Clone the repository:
24
+ ```bash
25
+ git clone https://github.com/yourusername/healthcare-tool-agent.git
26
+ cd healthcare-tool-agent
27
+ ```
28
+
29
+ 2. Create a virtual environment and install dependencies:
30
+ ```bash
31
+ python -m venv venv
32
+ source venv/bin/activate # On Windows: venv\Scripts\activate
33
+ pip install -r requirements.txt
34
+ ```
35
+
36
+ 3. Create a `.env` file with your API key:
37
+ ```
38
+ ANTHROPIC_API_KEY=your_api_key_here
39
+ ```
40
+
41
+ 4. Place your medical transcript data in `data/mtsamples_surgery.csv`
42
+
43
+ ## Usage
44
+
45
+ Run the application:
46
+ ```bash
47
+ python app.py
48
+ ```
49
+
50
+ This will start the Gradio interface, accessible at http://127.0.0.1:7860 in your browser.
51
+
52
+ ## File Structure
53
+
54
+ - **agent.py**: Main agent logic for routing queries and combining results
55
+ - **tools/retriever_tool.py**: Vector similarity search for document retrieval
56
+ - **tools/search_tool.py**: Web search functionality using DuckDuckGo
57
+ - **app.py**: Gradio UI for the agent
58
+ - **data/mtsamples_surgery.csv**: Medical transcription samples dataset
59
+
60
+ ## Technical Details
61
+
62
+ ### Document Retrieval
63
+
64
+ The document retrieval system uses:
65
+ - **SentenceTransformers**: For creating embeddings of both documents and queries
66
+ - **FAISS**: For efficient similarity search
67
+ - **Vector Similarity**: Cosine similarity with a threshold of 0.2-0.6 (adjustable)
68
+
69
+ ### Web Search
70
+
71
+ The web search component uses:
72
+ - **DuckDuckGo Search API**: For querying the public web
73
+ - **Result Formatting**: Structured presentation of search results with source links
74
+
75
+ ### LLM Tool Selection
76
+
77
+ The agent uses Claude 3.7 Sonnet to:
78
+ - Determine if a query needs document retrieval, web search, or both
79
+ - Route queries appropriately based on content type
80
+ - Format results into a coherent response
81
+
82
+ ## How It Works
83
+
84
+ 1. User submits a question through the Gradio interface
85
+ 2. Claude analyzes the query to determine the appropriate tool(s)
86
+ 3. Query is sent to selected tool(s) (document retrieval, web search, or both)
87
+ 4. Results are formatted and returned to the user
88
+ 5. If debug mode is enabled, additional information about the process is displayed
89
+
90
+ ## Requirements
91
+
92
+ - Python 3.8+
93
+ - Anthropic Claude API access
94
+ - FAISS
95
+ - SentenceTransformers
96
+ - DuckDuckGo Search
97
+ - Gradio
98
+ - Pandas
99
+ - NumPy
100
+
101
+ ## Future Improvements
102
+
103
+ - TBD next: Provide a better summary for the retrieved results
104
+ - Implement a hybrid search approach that blends results from both tools
105
+ - Improve document chunking for more precise retrieval
106
+ - Implement a feedback mechanism to improve tool selection over time
107
+
108
+ ## License
109
+
110
+ This project is licensed under the MIT License - see the LICENSE file for details.
111
+
112
+ ## Acknowledgments
113
+
114
+ - Medical transcription samples from [MTSamples](https://www.mtsamples.com/)
115
+ - Built with Claude 3.7 Sonnet by Anthropic
__pycache__/agent.cpython-312.pyc ADDED
Binary file (4.73 kB). View file
 
agent.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import anthropic
2
+ import os
3
+ from dotenv import load_dotenv
4
+ from tools.search_tool import search_duckduckgo
5
+ from tools.retriever_tool import Retriever
6
+
7
+ load_dotenv()
8
+
9
+ import logging
10
+
11
+ logging.basicConfig(
12
+ level=logging.DEBUG,
13
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
14
+ handlers=[logging.FileHandler("debug.log"), logging.StreamHandler()]
15
+ )
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+ client = anthropic.Anthropic(
20
+ api_key=os.getenv("ANTHROPIC_API_KEY"),
21
+ )
22
+ # print("Anthropic API key:", os.getenv("ANTHROPIC_API_KEY"))
23
+
24
+ retriever = Retriever(
25
+ top_k=3,
26
+ similarity_threshold=0.2,
27
+ batch_size=8
28
+ )
29
+
30
+ def call_llm(prompt, model="claude-3-7-sonnet-20250219"):
31
+ response = client.messages.create(
32
+ model=model,
33
+ max_tokens=500,
34
+ temperature=0,
35
+ system="""You are an expert clinical AI assistant. You must strictly reply in ONLY one of the following formats: TOOL: [Document], TOOL: [Search], or TOOL: [Both].
36
+
37
+ For questions about general medical information like recovery times, procedure durations, or standard practices, prefer TOOL: [Search].
38
+ For questions about specific medical cases or rare conditions found in the document database, use TOOL: [Document].
39
+ For questions that would benefit from both sources, use TOOL: [Both].
40
+
41
+ Never explain, never say anything else.""",
42
+ messages=[
43
+ {"role": "user", "content": f"""Question: "{prompt}"
44
+
45
+ Decide the best tool for answering it. Reply exactly with TOOL: [Document], TOOL: [Search], or TOOL: [Both]. No other text."""}
46
+ ]
47
+ )
48
+ return response.content[0].text
49
+
50
+ def agent_respond(question):
51
+ logger.debug(f"Received question: {question}")
52
+
53
+ tool_decision = call_llm(
54
+ f"""Decide which tool(s) are needed to answer this question: "{question}".
55
+ Available tools:
56
+ - Document RAG (for clinical facts)
57
+ - Search (for public info)
58
+
59
+ Reply in format:
60
+ TOOL: [Document/Search/Both/All]
61
+ """
62
+ )
63
+
64
+ logger.debug(f"Tool decision raw response: '{tool_decision}'")
65
+
66
+ use_document = "document" in tool_decision.lower()
67
+ use_search = "search" in tool_decision.lower()
68
+
69
+ logger.debug(f"Parsed decision - Use Document: {use_document}, Use Search: {use_search}")
70
+
71
+ results = []
72
+
73
+ if use_document:
74
+ logger.debug("Retrieving from documents...")
75
+ try:
76
+ doc_info = retriever.query(question)
77
+ logger.debug(f"Document retrieval returned {len(doc_info)} characters")
78
+ results.append(f"Document info:\n{doc_info}")
79
+ except Exception as e:
80
+ logger.error(f"Document retrieval error: {e}")
81
+ results.append(f"Document retrieval error: {str(e)}")
82
+
83
+ if use_search:
84
+ logger.debug("Searching web...")
85
+ try:
86
+ search_info = search_duckduckgo(question)
87
+ logger.debug(f"Search returned {len(search_info)} characters")
88
+ results.append(f"Search info:\n{search_info}")
89
+ except Exception as e:
90
+ logger.error(f"Search error: {e}")
91
+ results.append(f"Search error: {str(e)}")
92
+
93
+ if results:
94
+ return "\n\n".join(results)
95
+ else:
96
+ logger.warning("No results from either tool")
97
+ return "Could not determine the right tool to use or both tools failed."
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from agent import agent_respond
3
+
4
+ def agent_interface(user_question, debug_mode=True):
5
+ return agent_respond(user_question)
6
+
7
+ custom_css = """
8
+ .gradio-container {
9
+ max-width: 1400px !important;
10
+ margin-left: auto;
11
+ margin-right: auto;
12
+ }
13
+ .output-box {
14
+ min-height: 500px !important;
15
+ font-size: 16px !important;
16
+ }
17
+ .input-box {
18
+ min-height: 150px !important;
19
+ font-size: 16px !important;
20
+ }
21
+ """
22
+
23
+ with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
24
+ gr.Markdown("# Healthcare Tool-Using AI Agent")
25
+ gr.Markdown("An agent that uses document retrieval, live web search, and calculation to answer clinical healthcare questions.")
26
+
27
+ with gr.Row():
28
+ with gr.Column(scale=1):
29
+ user_question = gr.Textbox(
30
+ lines=4,
31
+ placeholder="Ask a healthcare question...",
32
+ elem_classes="input-box",
33
+ label="Question"
34
+ )
35
+ debug_mode = gr.Checkbox(label="Debug Mode", value=True)
36
+ submit_btn = gr.Button("Submit")
37
+ clear_btn = gr.Button("Clear")
38
+
39
+ with gr.Column(scale=2):
40
+ output = gr.Textbox(
41
+ lines=30,
42
+ elem_classes="output-box",
43
+ label="Response"
44
+ )
45
+
46
+ submit_btn.click(
47
+ fn=agent_interface,
48
+ inputs=[user_question, debug_mode],
49
+ outputs=output
50
+ )
51
+
52
+ clear_btn.click(
53
+ fn=lambda: "",
54
+ inputs=None,
55
+ outputs=[user_question, output]
56
+ )
57
+
58
+ if __name__ == "__main__":
59
+ demo.launch()
data/mtsamples_surgery.csv ADDED
The diff for this file is too large to render. See raw diff
 
debug.log ADDED
@@ -0,0 +1,560 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2025-04-27 21:21:08,399 - sentence_transformers.SentenceTransformer - INFO - Use pytorch device_name: mps
2
+ 2025-04-27 21:21:08,399 - sentence_transformers.SentenceTransformer - INFO - Load pretrained SentenceTransformer: all-MiniLM-L6-v2
3
+ 2025-04-27 21:21:08,401 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
4
+ 2025-04-27 21:21:08,515 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json HTTP/1.1" 200 0
5
+ 2025-04-27 21:21:08,645 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/config_sentence_transformers.json HTTP/1.1" 200 0
6
+ 2025-04-27 21:21:08,740 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/README.md HTTP/1.1" 200 0
7
+ 2025-04-27 21:21:09,077 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json HTTP/1.1" 200 0
8
+ 2025-04-27 21:21:09,172 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/sentence_bert_config.json HTTP/1.1" 200 0
9
+ 2025-04-27 21:21:09,270 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/adapter_config.json HTTP/1.1" 404 0
10
+ 2025-04-27 21:21:09,590 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/config.json HTTP/1.1" 200 0
11
+ 2025-04-27 21:21:09,902 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/tokenizer_config.json HTTP/1.1" 200 0
12
+ 2025-04-27 21:21:10,048 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "GET /api/models/sentence-transformers/all-MiniLM-L6-v2/revision/main HTTP/1.1" 200 6766
13
+ 2025-04-27 21:21:10,165 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "GET /api/models/sentence-transformers/all-MiniLM-L6-v2 HTTP/1.1" 200 6766
14
+ 2025-04-27 21:21:53,101 - asyncio - DEBUG - Using selector: KqueueSelector
15
+ 2025-04-27 21:21:53,102 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
16
+ 2025-04-27 21:21:53,122 - httpcore.connection - DEBUG - connect_tcp.started host='api.gradio.app' port=443 local_address=None timeout=3 socket_options=None
17
+ 2025-04-27 21:21:53,184 - asyncio - DEBUG - Using selector: KqueueSelector
18
+ 2025-04-27 21:21:53,198 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x15bed1e20>
19
+ 2025-04-27 21:21:53,198 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x159359350> server_hostname='api.gradio.app' timeout=3
20
+ 2025-04-27 21:21:53,222 - httpcore.connection - DEBUG - connect_tcp.started host='127.0.0.1' port=7861 local_address=None timeout=None socket_options=None
21
+ 2025-04-27 21:21:53,222 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x1695c3ec0>
22
+ 2025-04-27 21:21:53,222 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'GET']>
23
+ 2025-04-27 21:21:53,222 - httpcore.http11 - DEBUG - send_request_headers.complete
24
+ 2025-04-27 21:21:53,222 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'GET']>
25
+ 2025-04-27 21:21:53,222 - httpcore.http11 - DEBUG - send_request_body.complete
26
+ 2025-04-27 21:21:53,222 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'GET']>
27
+ 2025-04-27 21:21:53,223 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'date', b'Mon, 28 Apr 2025 04:21:53 GMT'), (b'server', b'uvicorn'), (b'content-length', b'4'), (b'content-type', b'application/json')])
28
+ 2025-04-27 21:21:53,223 - httpx - INFO - HTTP Request: GET http://127.0.0.1:7861/gradio_api/startup-events "HTTP/1.1 200 OK"
29
+ 2025-04-27 21:21:53,223 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'GET']>
30
+ 2025-04-27 21:21:53,223 - httpcore.http11 - DEBUG - receive_response_body.complete
31
+ 2025-04-27 21:21:53,223 - httpcore.http11 - DEBUG - response_closed.started
32
+ 2025-04-27 21:21:53,223 - httpcore.http11 - DEBUG - response_closed.complete
33
+ 2025-04-27 21:21:53,223 - httpcore.connection - DEBUG - close.started
34
+ 2025-04-27 21:21:53,223 - httpcore.connection - DEBUG - close.complete
35
+ 2025-04-27 21:21:53,223 - httpcore.connection - DEBUG - connect_tcp.started host='127.0.0.1' port=7861 local_address=None timeout=3 socket_options=None
36
+ 2025-04-27 21:21:53,224 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x1695e4b30>
37
+ 2025-04-27 21:21:53,224 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'HEAD']>
38
+ 2025-04-27 21:21:53,224 - httpcore.http11 - DEBUG - send_request_headers.complete
39
+ 2025-04-27 21:21:53,224 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'HEAD']>
40
+ 2025-04-27 21:21:53,224 - httpcore.http11 - DEBUG - send_request_body.complete
41
+ 2025-04-27 21:21:53,224 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'HEAD']>
42
+ 2025-04-27 21:21:53,232 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'date', b'Mon, 28 Apr 2025 04:21:53 GMT'), (b'server', b'uvicorn'), (b'content-length', b'14879'), (b'content-type', b'text/html; charset=utf-8')])
43
+ 2025-04-27 21:21:53,232 - httpx - INFO - HTTP Request: HEAD http://127.0.0.1:7861/ "HTTP/1.1 200 OK"
44
+ 2025-04-27 21:21:53,232 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'HEAD']>
45
+ 2025-04-27 21:21:53,232 - httpcore.http11 - DEBUG - receive_response_body.complete
46
+ 2025-04-27 21:21:53,232 - httpcore.http11 - DEBUG - response_closed.started
47
+ 2025-04-27 21:21:53,232 - httpcore.http11 - DEBUG - response_closed.complete
48
+ 2025-04-27 21:21:53,232 - httpcore.connection - DEBUG - close.started
49
+ 2025-04-27 21:21:53,232 - httpcore.connection - DEBUG - close.complete
50
+ 2025-04-27 21:21:53,232 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
51
+ 2025-04-27 21:21:53,251 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x159368170>
52
+ 2025-04-27 21:21:53,251 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'GET']>
53
+ 2025-04-27 21:21:53,251 - httpcore.http11 - DEBUG - send_request_headers.complete
54
+ 2025-04-27 21:21:53,251 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'GET']>
55
+ 2025-04-27 21:21:53,251 - httpcore.http11 - DEBUG - send_request_body.complete
56
+ 2025-04-27 21:21:53,251 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'GET']>
57
+ 2025-04-27 21:21:53,252 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /api/telemetry/gradio/initiated HTTP/1.1" 200 0
58
+ 2025-04-27 21:21:53,278 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:21:53 GMT'), (b'Content-Type', b'application/json'), (b'Content-Length', b'21'), (b'Connection', b'keep-alive'), (b'Server', b'nginx/1.18.0'), (b'Access-Control-Allow-Origin', b'*')])
59
+ 2025-04-27 21:21:53,278 - httpx - INFO - HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
60
+ 2025-04-27 21:21:53,278 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'GET']>
61
+ 2025-04-27 21:21:53,278 - httpcore.http11 - DEBUG - receive_response_body.complete
62
+ 2025-04-27 21:21:53,278 - httpcore.http11 - DEBUG - response_closed.started
63
+ 2025-04-27 21:21:53,278 - httpcore.http11 - DEBUG - response_closed.complete
64
+ 2025-04-27 21:21:53,278 - httpcore.connection - DEBUG - close.started
65
+ 2025-04-27 21:21:53,279 - httpcore.connection - DEBUG - close.complete
66
+ 2025-04-27 21:21:53,343 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /api/telemetry/gradio/launched HTTP/1.1" 200 0
67
+ 2025-04-27 21:22:06,659 - __main__ - DEBUG - === New Gradio Request: What was the diagnosis for the ORIF surgery? ===
68
+ 2025-04-27 21:22:06,659 - agent - DEBUG - Received question: What was the diagnosis for the ORIF surgery?
69
+ 2025-04-27 21:22:06,661 - anthropic._base_client - DEBUG - Request options: {'method': 'post', 'url': '/v1/messages', 'timeout': Timeout(connect=5.0, read=600, write=600, pool=600), 'files': None, 'idempotency_key': 'stainless-python-retry-181188d5-b8ee-4428-9965-bf2141870ecd', 'json_data': {'max_tokens': 500, 'messages': [{'role': 'user', 'content': 'Question: "Decide which tool(s) are needed to answer this question: "What was the diagnosis for the ORIF surgery?".\n Available tools:\n - Document RAG (for clinical facts)\n - Search (for public info)\n\n Reply in format:\n TOOL: [Document/Search/Both/All]\n "\n\nDecide the best tool for answering it. Reply exactly with TOOL: [Document] or TOOL: [Search]. No other text.'}], 'model': 'claude-3-7-sonnet-20250219', 'system': 'You are an expert clinical AI assistant. You must strictly reply in ONLY one of the following formats: TOOL: [Document] or TOOL: [Search]. Never explain, never say anything else.', 'temperature': 0}}
70
+ 2025-04-27 21:22:06,696 - anthropic._base_client - DEBUG - Sending HTTP Request: POST https://api.anthropic.com/v1/messages
71
+ 2025-04-27 21:22:06,696 - httpcore.connection - DEBUG - connect_tcp.started host='api.anthropic.com' port=443 local_address=None timeout=5.0 socket_options=[(65535, 8, True), (6, 257, 60), (6, 258, 5)]
72
+ 2025-04-27 21:22:06,710 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x15bef2300>
73
+ 2025-04-27 21:22:06,710 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x117af8c50> server_hostname='api.anthropic.com' timeout=5.0
74
+ 2025-04-27 21:22:06,729 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x16a0414f0>
75
+ 2025-04-27 21:22:06,729 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'POST']>
76
+ 2025-04-27 21:22:06,730 - httpcore.http11 - DEBUG - send_request_headers.complete
77
+ 2025-04-27 21:22:06,730 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'POST']>
78
+ 2025-04-27 21:22:06,730 - httpcore.http11 - DEBUG - send_request_body.complete
79
+ 2025-04-27 21:22:06,730 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'POST']>
80
+ 2025-04-27 21:22:10,014 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:22:09 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'anthropic-ratelimit-input-tokens-limit', b'20000'), (b'anthropic-ratelimit-input-tokens-remaining', b'20000'), (b'anthropic-ratelimit-input-tokens-reset', b'2025-04-28T04:22:09Z'), (b'anthropic-ratelimit-output-tokens-limit', b'8000'), (b'anthropic-ratelimit-output-tokens-remaining', b'8000'), (b'anthropic-ratelimit-output-tokens-reset', b'2025-04-28T04:22:09Z'), (b'anthropic-ratelimit-requests-limit', b'50'), (b'anthropic-ratelimit-requests-remaining', b'49'), (b'anthropic-ratelimit-requests-reset', b'2025-04-28T04:22:08Z'), (b'anthropic-ratelimit-tokens-limit', b'28000'), (b'anthropic-ratelimit-tokens-remaining', b'28000'), (b'anthropic-ratelimit-tokens-reset', b'2025-04-28T04:22:09Z'), (b'request-id', b'req_011CNaVSME8QX85HLpE83gLm'), (b'anthropic-organization-id', b'961c62a8-661b-402f-b3ec-38f150bfa917'), (b'via', b'1.1 google'), (b'CF-Cache-Status', b'DYNAMIC'), (b'X-Robots-Tag', b'none'), (b'Server', b'cloudflare'), (b'CF-RAY', b'9373c6d41fb77af2-SJC'), (b'Content-Encoding', b'gzip')])
81
+ 2025-04-27 21:22:10,015 - httpx - INFO - HTTP Request: POST https://api.anthropic.com/v1/messages "HTTP/1.1 200 OK"
82
+ 2025-04-27 21:22:10,015 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'POST']>
83
+ 2025-04-27 21:22:10,015 - httpcore.http11 - DEBUG - receive_response_body.complete
84
+ 2025-04-27 21:22:10,015 - httpcore.http11 - DEBUG - response_closed.started
85
+ 2025-04-27 21:22:10,015 - httpcore.http11 - DEBUG - response_closed.complete
86
+ 2025-04-27 21:22:10,016 - anthropic._base_client - DEBUG - HTTP Response: POST https://api.anthropic.com/v1/messages "200 OK" Headers({'date': 'Mon, 28 Apr 2025 04:22:09 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'anthropic-ratelimit-input-tokens-limit': '20000', 'anthropic-ratelimit-input-tokens-remaining': '20000', 'anthropic-ratelimit-input-tokens-reset': '2025-04-28T04:22:09Z', 'anthropic-ratelimit-output-tokens-limit': '8000', 'anthropic-ratelimit-output-tokens-remaining': '8000', 'anthropic-ratelimit-output-tokens-reset': '2025-04-28T04:22:09Z', 'anthropic-ratelimit-requests-limit': '50', 'anthropic-ratelimit-requests-remaining': '49', 'anthropic-ratelimit-requests-reset': '2025-04-28T04:22:08Z', 'anthropic-ratelimit-tokens-limit': '28000', 'anthropic-ratelimit-tokens-remaining': '28000', 'anthropic-ratelimit-tokens-reset': '2025-04-28T04:22:09Z', 'request-id': 'req_011CNaVSME8QX85HLpE83gLm', 'anthropic-organization-id': '961c62a8-661b-402f-b3ec-38f150bfa917', 'via': '1.1 google', 'cf-cache-status': 'DYNAMIC', 'x-robots-tag': 'none', 'server': 'cloudflare', 'cf-ray': '9373c6d41fb77af2-SJC', 'content-encoding': 'gzip'})
87
+ 2025-04-27 21:22:10,016 - anthropic._base_client - DEBUG - request_id: req_011CNaVSME8QX85HLpE83gLm
88
+ 2025-04-27 21:22:10,023 - agent - DEBUG - Tool decision raw response: 'TOOL: [Document]'
89
+ 2025-04-27 21:22:10,023 - agent - DEBUG - Parsed decision - Use Document: True, Use Search: False
90
+ 2025-04-27 21:22:10,024 - agent - DEBUG - Retrieving from documents...
91
+ 2025-04-27 21:22:10,601 - agent - DEBUG - Document retrieval returned 43 characters
92
+ 2025-04-27 21:23:57,297 - httpcore.connection - DEBUG - close.started
93
+ 2025-04-27 21:23:57,298 - httpcore.connection - DEBUG - close.complete
94
+ 2025-04-27 21:24:02,496 - sentence_transformers.SentenceTransformer - INFO - Use pytorch device_name: mps
95
+ 2025-04-27 21:24:02,496 - sentence_transformers.SentenceTransformer - INFO - Load pretrained SentenceTransformer: all-MiniLM-L6-v2
96
+ 2025-04-27 21:24:02,498 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
97
+ 2025-04-27 21:24:02,664 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json HTTP/1.1" 200 0
98
+ 2025-04-27 21:24:02,755 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/config_sentence_transformers.json HTTP/1.1" 200 0
99
+ 2025-04-27 21:24:02,858 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/README.md HTTP/1.1" 200 0
100
+ 2025-04-27 21:24:02,952 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json HTTP/1.1" 200 0
101
+ 2025-04-27 21:24:03,050 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/sentence_bert_config.json HTTP/1.1" 200 0
102
+ 2025-04-27 21:24:03,149 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/adapter_config.json HTTP/1.1" 404 0
103
+ 2025-04-27 21:24:03,250 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/config.json HTTP/1.1" 200 0
104
+ 2025-04-27 21:24:03,559 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/tokenizer_config.json HTTP/1.1" 200 0
105
+ 2025-04-27 21:24:03,676 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "GET /api/models/sentence-transformers/all-MiniLM-L6-v2/revision/main HTTP/1.1" 200 6766
106
+ 2025-04-27 21:24:03,791 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "GET /api/models/sentence-transformers/all-MiniLM-L6-v2 HTTP/1.1" 200 6766
107
+ 2025-04-27 21:24:46,687 - asyncio - DEBUG - Using selector: KqueueSelector
108
+ 2025-04-27 21:24:46,688 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
109
+ 2025-04-27 21:24:46,696 - httpcore.connection - DEBUG - connect_tcp.started host='api.gradio.app' port=443 local_address=None timeout=3 socket_options=None
110
+ 2025-04-27 21:24:46,767 - asyncio - DEBUG - Using selector: KqueueSelector
111
+ 2025-04-27 21:24:46,805 - httpcore.connection - DEBUG - connect_tcp.started host='127.0.0.1' port=7861 local_address=None timeout=None socket_options=None
112
+ 2025-04-27 21:24:46,805 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x16a270920>
113
+ 2025-04-27 21:24:46,805 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'GET']>
114
+ 2025-04-27 21:24:46,805 - httpcore.http11 - DEBUG - send_request_headers.complete
115
+ 2025-04-27 21:24:46,805 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'GET']>
116
+ 2025-04-27 21:24:46,805 - httpcore.http11 - DEBUG - send_request_body.complete
117
+ 2025-04-27 21:24:46,805 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'GET']>
118
+ 2025-04-27 21:24:46,806 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'date', b'Mon, 28 Apr 2025 04:24:46 GMT'), (b'server', b'uvicorn'), (b'content-length', b'4'), (b'content-type', b'application/json')])
119
+ 2025-04-27 21:24:46,806 - httpx - INFO - HTTP Request: GET http://127.0.0.1:7861/gradio_api/startup-events "HTTP/1.1 200 OK"
120
+ 2025-04-27 21:24:46,806 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'GET']>
121
+ 2025-04-27 21:24:46,806 - httpcore.http11 - DEBUG - receive_response_body.complete
122
+ 2025-04-27 21:24:46,806 - httpcore.http11 - DEBUG - response_closed.started
123
+ 2025-04-27 21:24:46,806 - httpcore.http11 - DEBUG - response_closed.complete
124
+ 2025-04-27 21:24:46,806 - httpcore.connection - DEBUG - close.started
125
+ 2025-04-27 21:24:46,806 - httpcore.connection - DEBUG - close.complete
126
+ 2025-04-27 21:24:46,807 - httpcore.connection - DEBUG - connect_tcp.started host='127.0.0.1' port=7861 local_address=None timeout=3 socket_options=None
127
+ 2025-04-27 21:24:46,807 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x16a2c0890>
128
+ 2025-04-27 21:24:46,807 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'HEAD']>
129
+ 2025-04-27 21:24:46,807 - httpcore.http11 - DEBUG - send_request_headers.complete
130
+ 2025-04-27 21:24:46,807 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'HEAD']>
131
+ 2025-04-27 21:24:46,807 - httpcore.http11 - DEBUG - send_request_body.complete
132
+ 2025-04-27 21:24:46,807 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'HEAD']>
133
+ 2025-04-27 21:24:46,815 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'date', b'Mon, 28 Apr 2025 04:24:46 GMT'), (b'server', b'uvicorn'), (b'content-length', b'14879'), (b'content-type', b'text/html; charset=utf-8')])
134
+ 2025-04-27 21:24:46,815 - httpx - INFO - HTTP Request: HEAD http://127.0.0.1:7861/ "HTTP/1.1 200 OK"
135
+ 2025-04-27 21:24:46,815 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'HEAD']>
136
+ 2025-04-27 21:24:46,815 - httpcore.http11 - DEBUG - receive_response_body.complete
137
+ 2025-04-27 21:24:46,815 - httpcore.http11 - DEBUG - response_closed.started
138
+ 2025-04-27 21:24:46,815 - httpcore.http11 - DEBUG - response_closed.complete
139
+ 2025-04-27 21:24:46,815 - httpcore.connection - DEBUG - close.started
140
+ 2025-04-27 21:24:46,815 - httpcore.connection - DEBUG - close.complete
141
+ 2025-04-27 21:24:46,816 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
142
+ 2025-04-27 21:24:46,816 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /api/telemetry/gradio/initiated HTTP/1.1" 200 0
143
+ 2025-04-27 21:24:46,830 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x132f0b020>
144
+ 2025-04-27 21:24:46,830 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x132c5aad0> server_hostname='api.gradio.app' timeout=3
145
+ 2025-04-27 21:24:46,885 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x1312796a0>
146
+ 2025-04-27 21:24:46,885 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'GET']>
147
+ 2025-04-27 21:24:46,885 - httpcore.http11 - DEBUG - send_request_headers.complete
148
+ 2025-04-27 21:24:46,885 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'GET']>
149
+ 2025-04-27 21:24:46,886 - httpcore.http11 - DEBUG - send_request_body.complete
150
+ 2025-04-27 21:24:46,886 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'GET']>
151
+ 2025-04-27 21:24:46,913 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:24:46 GMT'), (b'Content-Type', b'application/json'), (b'Content-Length', b'21'), (b'Connection', b'keep-alive'), (b'Server', b'nginx/1.18.0'), (b'Access-Control-Allow-Origin', b'*')])
152
+ 2025-04-27 21:24:46,913 - httpx - INFO - HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
153
+ 2025-04-27 21:24:46,913 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'GET']>
154
+ 2025-04-27 21:24:46,913 - httpcore.http11 - DEBUG - receive_response_body.complete
155
+ 2025-04-27 21:24:46,913 - httpcore.http11 - DEBUG - response_closed.started
156
+ 2025-04-27 21:24:46,913 - httpcore.http11 - DEBUG - response_closed.complete
157
+ 2025-04-27 21:24:46,913 - httpcore.connection - DEBUG - close.started
158
+ 2025-04-27 21:24:46,914 - httpcore.connection - DEBUG - close.complete
159
+ 2025-04-27 21:24:46,916 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /api/telemetry/gradio/launched HTTP/1.1" 200 0
160
+ 2025-04-27 21:25:24,297 - __main__ - DEBUG - === New Gradio Request: What was the diagnosis for the ORIF surgery? ===
161
+ 2025-04-27 21:25:24,297 - agent - DEBUG - Received question: What was the diagnosis for the ORIF surgery?
162
+ 2025-04-27 21:25:24,299 - anthropic._base_client - DEBUG - Request options: {'method': 'post', 'url': '/v1/messages', 'timeout': Timeout(connect=5.0, read=600, write=600, pool=600), 'files': None, 'idempotency_key': 'stainless-python-retry-65bcf5f3-5a4f-48be-9b3c-9ceb5ef695ab', 'json_data': {'max_tokens': 500, 'messages': [{'role': 'user', 'content': 'Question: "Decide which tool(s) are needed to answer this question: "What was the diagnosis for the ORIF surgery?".\n Available tools:\n - Document RAG (for clinical facts)\n - Search (for public info)\n\n Reply in format:\n TOOL: [Document/Search/Both/All]\n "\n\nDecide the best tool for answering it. Reply exactly with TOOL: [Document] or TOOL: [Search]. No other text.'}], 'model': 'claude-3-7-sonnet-20250219', 'system': 'You are an expert clinical AI assistant. You must strictly reply in ONLY one of the following formats: TOOL: [Document] or TOOL: [Search]. Never explain, never say anything else.', 'temperature': 0}}
163
+ 2025-04-27 21:25:24,329 - anthropic._base_client - DEBUG - Sending HTTP Request: POST https://api.anthropic.com/v1/messages
164
+ 2025-04-27 21:25:24,329 - httpcore.connection - DEBUG - connect_tcp.started host='api.anthropic.com' port=443 local_address=None timeout=5.0 socket_options=[(65535, 8, True), (6, 257, 60), (6, 258, 5)]
165
+ 2025-04-27 21:25:24,342 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x16a4257f0>
166
+ 2025-04-27 21:25:24,342 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x1312aef50> server_hostname='api.anthropic.com' timeout=5.0
167
+ 2025-04-27 21:25:24,359 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x16a425a60>
168
+ 2025-04-27 21:25:24,359 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'POST']>
169
+ 2025-04-27 21:25:24,359 - httpcore.http11 - DEBUG - send_request_headers.complete
170
+ 2025-04-27 21:25:24,359 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'POST']>
171
+ 2025-04-27 21:25:24,359 - httpcore.http11 - DEBUG - send_request_body.complete
172
+ 2025-04-27 21:25:24,359 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'POST']>
173
+ 2025-04-27 21:25:24,979 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:25:24 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'anthropic-ratelimit-input-tokens-limit', b'20000'), (b'anthropic-ratelimit-input-tokens-remaining', b'20000'), (b'anthropic-ratelimit-input-tokens-reset', b'2025-04-28T04:25:24Z'), (b'anthropic-ratelimit-output-tokens-limit', b'8000'), (b'anthropic-ratelimit-output-tokens-remaining', b'8000'), (b'anthropic-ratelimit-output-tokens-reset', b'2025-04-28T04:25:24Z'), (b'anthropic-ratelimit-requests-limit', b'50'), (b'anthropic-ratelimit-requests-remaining', b'49'), (b'anthropic-ratelimit-requests-reset', b'2025-04-28T04:25:25Z'), (b'anthropic-ratelimit-tokens-limit', b'28000'), (b'anthropic-ratelimit-tokens-remaining', b'28000'), (b'anthropic-ratelimit-tokens-reset', b'2025-04-28T04:25:24Z'), (b'request-id', b'req_011CNaVgvABBjqeDgRbZmWXJ'), (b'anthropic-organization-id', b'961c62a8-661b-402f-b3ec-38f150bfa917'), (b'via', b'1.1 google'), (b'CF-Cache-Status', b'DYNAMIC'), (b'X-Robots-Tag', b'none'), (b'Server', b'cloudflare'), (b'CF-RAY', b'9373cba74ac9254e-SJC'), (b'Content-Encoding', b'gzip')])
174
+ 2025-04-27 21:25:24,981 - httpx - INFO - HTTP Request: POST https://api.anthropic.com/v1/messages "HTTP/1.1 200 OK"
175
+ 2025-04-27 21:25:24,981 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'POST']>
176
+ 2025-04-27 21:25:24,982 - httpcore.http11 - DEBUG - receive_response_body.complete
177
+ 2025-04-27 21:25:24,982 - httpcore.http11 - DEBUG - response_closed.started
178
+ 2025-04-27 21:25:24,982 - httpcore.http11 - DEBUG - response_closed.complete
179
+ 2025-04-27 21:25:24,983 - anthropic._base_client - DEBUG - HTTP Response: POST https://api.anthropic.com/v1/messages "200 OK" Headers({'date': 'Mon, 28 Apr 2025 04:25:24 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'anthropic-ratelimit-input-tokens-limit': '20000', 'anthropic-ratelimit-input-tokens-remaining': '20000', 'anthropic-ratelimit-input-tokens-reset': '2025-04-28T04:25:24Z', 'anthropic-ratelimit-output-tokens-limit': '8000', 'anthropic-ratelimit-output-tokens-remaining': '8000', 'anthropic-ratelimit-output-tokens-reset': '2025-04-28T04:25:24Z', 'anthropic-ratelimit-requests-limit': '50', 'anthropic-ratelimit-requests-remaining': '49', 'anthropic-ratelimit-requests-reset': '2025-04-28T04:25:25Z', 'anthropic-ratelimit-tokens-limit': '28000', 'anthropic-ratelimit-tokens-remaining': '28000', 'anthropic-ratelimit-tokens-reset': '2025-04-28T04:25:24Z', 'request-id': 'req_011CNaVgvABBjqeDgRbZmWXJ', 'anthropic-organization-id': '961c62a8-661b-402f-b3ec-38f150bfa917', 'via': '1.1 google', 'cf-cache-status': 'DYNAMIC', 'x-robots-tag': 'none', 'server': 'cloudflare', 'cf-ray': '9373cba74ac9254e-SJC', 'content-encoding': 'gzip'})
180
+ 2025-04-27 21:25:24,983 - anthropic._base_client - DEBUG - request_id: req_011CNaVgvABBjqeDgRbZmWXJ
181
+ 2025-04-27 21:25:24,993 - agent - DEBUG - Tool decision raw response: 'TOOL: [Document]'
182
+ 2025-04-27 21:25:24,994 - agent - DEBUG - Parsed decision - Use Document: True, Use Search: False
183
+ 2025-04-27 21:25:24,994 - agent - DEBUG - Retrieving from documents...
184
+ 2025-04-27 21:25:25,434 - agent - DEBUG - Document retrieval returned 5595 characters
185
+ 2025-04-27 21:25:59,797 - __main__ - DEBUG - === New Gradio Request: How long is recovery after a bilateral reduction mammoplasty? ===
186
+ 2025-04-27 21:25:59,798 - agent - DEBUG - Received question: How long is recovery after a bilateral reduction mammoplasty?
187
+ 2025-04-27 21:25:59,798 - anthropic._base_client - DEBUG - Request options: {'method': 'post', 'url': '/v1/messages', 'timeout': Timeout(connect=5.0, read=600, write=600, pool=600), 'files': None, 'idempotency_key': 'stainless-python-retry-11e0ec95-e1e5-4035-8aa1-2c399f7ce71d', 'json_data': {'max_tokens': 500, 'messages': [{'role': 'user', 'content': 'Question: "Decide which tool(s) are needed to answer this question: "How long is recovery after a bilateral reduction mammoplasty?".\n Available tools:\n - Document RAG (for clinical facts)\n - Search (for public info)\n\n Reply in format:\n TOOL: [Document/Search/Both/All]\n "\n\nDecide the best tool for answering it. Reply exactly with TOOL: [Document] or TOOL: [Search]. No other text.'}], 'model': 'claude-3-7-sonnet-20250219', 'system': 'You are an expert clinical AI assistant. You must strictly reply in ONLY one of the following formats: TOOL: [Document] or TOOL: [Search]. Never explain, never say anything else.', 'temperature': 0}}
188
+ 2025-04-27 21:25:59,799 - anthropic._base_client - DEBUG - Sending HTTP Request: POST https://api.anthropic.com/v1/messages
189
+ 2025-04-27 21:25:59,799 - httpcore.connection - DEBUG - close.started
190
+ 2025-04-27 21:25:59,799 - httpcore.connection - DEBUG - close.complete
191
+ 2025-04-27 21:25:59,799 - httpcore.connection - DEBUG - connect_tcp.started host='api.anthropic.com' port=443 local_address=None timeout=5.0 socket_options=[(65535, 8, True), (6, 257, 60), (6, 258, 5)]
192
+ 2025-04-27 21:25:59,817 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x132da3410>
193
+ 2025-04-27 21:25:59,818 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x1312aef50> server_hostname='api.anthropic.com' timeout=5.0
194
+ 2025-04-27 21:25:59,841 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x132da33e0>
195
+ 2025-04-27 21:25:59,842 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'POST']>
196
+ 2025-04-27 21:25:59,842 - httpcore.http11 - DEBUG - send_request_headers.complete
197
+ 2025-04-27 21:25:59,842 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'POST']>
198
+ 2025-04-27 21:25:59,842 - httpcore.http11 - DEBUG - send_request_body.complete
199
+ 2025-04-27 21:25:59,842 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'POST']>
200
+ 2025-04-27 21:26:00,900 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:26:00 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'anthropic-ratelimit-input-tokens-limit', b'20000'), (b'anthropic-ratelimit-input-tokens-remaining', b'20000'), (b'anthropic-ratelimit-input-tokens-reset', b'2025-04-28T04:26:00Z'), (b'anthropic-ratelimit-output-tokens-limit', b'8000'), (b'anthropic-ratelimit-output-tokens-remaining', b'8000'), (b'anthropic-ratelimit-output-tokens-reset', b'2025-04-28T04:26:00Z'), (b'anthropic-ratelimit-requests-limit', b'50'), (b'anthropic-ratelimit-requests-remaining', b'49'), (b'anthropic-ratelimit-requests-reset', b'2025-04-28T04:26:01Z'), (b'anthropic-ratelimit-tokens-limit', b'28000'), (b'anthropic-ratelimit-tokens-remaining', b'28000'), (b'anthropic-ratelimit-tokens-reset', b'2025-04-28T04:26:00Z'), (b'request-id', b'req_011CNaVjXqL3cyKcLd4UdhFn'), (b'anthropic-organization-id', b'961c62a8-661b-402f-b3ec-38f150bfa917'), (b'via', b'1.1 google'), (b'cf-cache-status', b'DYNAMIC'), (b'X-Robots-Tag', b'none'), (b'Server', b'cloudflare'), (b'CF-RAY', b'9373cc850b74cf15-SJC'), (b'Content-Encoding', b'gzip')])
201
+ 2025-04-27 21:26:00,901 - httpx - INFO - HTTP Request: POST https://api.anthropic.com/v1/messages "HTTP/1.1 200 OK"
202
+ 2025-04-27 21:26:00,901 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'POST']>
203
+ 2025-04-27 21:26:00,902 - httpcore.http11 - DEBUG - receive_response_body.complete
204
+ 2025-04-27 21:26:00,902 - httpcore.http11 - DEBUG - response_closed.started
205
+ 2025-04-27 21:26:00,902 - httpcore.http11 - DEBUG - response_closed.complete
206
+ 2025-04-27 21:26:00,902 - anthropic._base_client - DEBUG - HTTP Response: POST https://api.anthropic.com/v1/messages "200 OK" Headers({'date': 'Mon, 28 Apr 2025 04:26:00 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'anthropic-ratelimit-input-tokens-limit': '20000', 'anthropic-ratelimit-input-tokens-remaining': '20000', 'anthropic-ratelimit-input-tokens-reset': '2025-04-28T04:26:00Z', 'anthropic-ratelimit-output-tokens-limit': '8000', 'anthropic-ratelimit-output-tokens-remaining': '8000', 'anthropic-ratelimit-output-tokens-reset': '2025-04-28T04:26:00Z', 'anthropic-ratelimit-requests-limit': '50', 'anthropic-ratelimit-requests-remaining': '49', 'anthropic-ratelimit-requests-reset': '2025-04-28T04:26:01Z', 'anthropic-ratelimit-tokens-limit': '28000', 'anthropic-ratelimit-tokens-remaining': '28000', 'anthropic-ratelimit-tokens-reset': '2025-04-28T04:26:00Z', 'request-id': 'req_011CNaVjXqL3cyKcLd4UdhFn', 'anthropic-organization-id': '961c62a8-661b-402f-b3ec-38f150bfa917', 'via': '1.1 google', 'cf-cache-status': 'DYNAMIC', 'x-robots-tag': 'none', 'server': 'cloudflare', 'cf-ray': '9373cc850b74cf15-SJC', 'content-encoding': 'gzip'})
207
+ 2025-04-27 21:26:00,903 - anthropic._base_client - DEBUG - request_id: req_011CNaVjXqL3cyKcLd4UdhFn
208
+ 2025-04-27 21:26:00,904 - agent - DEBUG - Tool decision raw response: 'TOOL: [Document]'
209
+ 2025-04-27 21:26:00,904 - agent - DEBUG - Parsed decision - Use Document: True, Use Search: False
210
+ 2025-04-27 21:26:00,904 - agent - DEBUG - Retrieving from documents...
211
+ 2025-04-27 21:26:01,136 - agent - DEBUG - Document retrieval returned 9259 characters
212
+ 2025-04-27 21:30:51,555 - httpcore.connection - DEBUG - close.started
213
+ 2025-04-27 21:30:51,556 - httpcore.connection - DEBUG - close.complete
214
+ 2025-04-27 21:30:56,671 - sentence_transformers.SentenceTransformer - INFO - Use pytorch device_name: mps
215
+ 2025-04-27 21:30:56,671 - sentence_transformers.SentenceTransformer - INFO - Load pretrained SentenceTransformer: all-MiniLM-L6-v2
216
+ 2025-04-27 21:30:56,673 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
217
+ 2025-04-27 21:30:56,968 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json HTTP/1.1" 200 0
218
+ 2025-04-27 21:30:57,064 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/config_sentence_transformers.json HTTP/1.1" 200 0
219
+ 2025-04-27 21:30:57,160 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/README.md HTTP/1.1" 200 0
220
+ 2025-04-27 21:30:57,256 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json HTTP/1.1" 200 0
221
+ 2025-04-27 21:30:57,430 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/sentence_bert_config.json HTTP/1.1" 200 0
222
+ 2025-04-27 21:30:57,530 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/adapter_config.json HTTP/1.1" 404 0
223
+ 2025-04-27 21:30:57,631 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/config.json HTTP/1.1" 200 0
224
+ 2025-04-27 21:30:57,920 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/tokenizer_config.json HTTP/1.1" 200 0
225
+ 2025-04-27 21:30:58,048 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "GET /api/models/sentence-transformers/all-MiniLM-L6-v2/revision/main HTTP/1.1" 200 6766
226
+ 2025-04-27 21:30:58,167 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "GET /api/models/sentence-transformers/all-MiniLM-L6-v2 HTTP/1.1" 200 6766
227
+ 2025-04-27 21:31:41,564 - asyncio - DEBUG - Using selector: KqueueSelector
228
+ 2025-04-27 21:31:41,565 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
229
+ 2025-04-27 21:31:41,573 - httpcore.connection - DEBUG - connect_tcp.started host='api.gradio.app' port=443 local_address=None timeout=3 socket_options=None
230
+ 2025-04-27 21:31:41,641 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x14a5136e0>
231
+ 2025-04-27 21:31:41,641 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x159c5aad0> server_hostname='api.gradio.app' timeout=3
232
+ 2025-04-27 21:31:41,647 - asyncio - DEBUG - Using selector: KqueueSelector
233
+ 2025-04-27 21:31:41,685 - httpcore.connection - DEBUG - connect_tcp.started host='127.0.0.1' port=7861 local_address=None timeout=None socket_options=None
234
+ 2025-04-27 21:31:41,685 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x1689f7e60>
235
+ 2025-04-27 21:31:41,685 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'GET']>
236
+ 2025-04-27 21:31:41,685 - httpcore.http11 - DEBUG - send_request_headers.complete
237
+ 2025-04-27 21:31:41,685 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'GET']>
238
+ 2025-04-27 21:31:41,685 - httpcore.http11 - DEBUG - send_request_body.complete
239
+ 2025-04-27 21:31:41,685 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'GET']>
240
+ 2025-04-27 21:31:41,686 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'date', b'Mon, 28 Apr 2025 04:31:41 GMT'), (b'server', b'uvicorn'), (b'content-length', b'4'), (b'content-type', b'application/json')])
241
+ 2025-04-27 21:31:41,686 - httpx - INFO - HTTP Request: GET http://127.0.0.1:7861/gradio_api/startup-events "HTTP/1.1 200 OK"
242
+ 2025-04-27 21:31:41,687 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'GET']>
243
+ 2025-04-27 21:31:41,687 - httpcore.http11 - DEBUG - receive_response_body.complete
244
+ 2025-04-27 21:31:41,687 - httpcore.http11 - DEBUG - response_closed.started
245
+ 2025-04-27 21:31:41,687 - httpcore.http11 - DEBUG - response_closed.complete
246
+ 2025-04-27 21:31:41,687 - httpcore.connection - DEBUG - close.started
247
+ 2025-04-27 21:31:41,687 - httpcore.connection - DEBUG - close.complete
248
+ 2025-04-27 21:31:41,687 - httpcore.connection - DEBUG - connect_tcp.started host='127.0.0.1' port=7861 local_address=None timeout=3 socket_options=None
249
+ 2025-04-27 21:31:41,687 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x168a184d0>
250
+ 2025-04-27 21:31:41,687 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'HEAD']>
251
+ 2025-04-27 21:31:41,688 - httpcore.http11 - DEBUG - send_request_headers.complete
252
+ 2025-04-27 21:31:41,688 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'HEAD']>
253
+ 2025-04-27 21:31:41,688 - httpcore.http11 - DEBUG - send_request_body.complete
254
+ 2025-04-27 21:31:41,688 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'HEAD']>
255
+ 2025-04-27 21:31:41,697 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'date', b'Mon, 28 Apr 2025 04:31:41 GMT'), (b'server', b'uvicorn'), (b'content-length', b'14880'), (b'content-type', b'text/html; charset=utf-8')])
256
+ 2025-04-27 21:31:41,697 - httpx - INFO - HTTP Request: HEAD http://127.0.0.1:7861/ "HTTP/1.1 200 OK"
257
+ 2025-04-27 21:31:41,697 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'HEAD']>
258
+ 2025-04-27 21:31:41,697 - httpcore.http11 - DEBUG - receive_response_body.complete
259
+ 2025-04-27 21:31:41,697 - httpcore.http11 - DEBUG - response_closed.started
260
+ 2025-04-27 21:31:41,697 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x159e76e10>
261
+ 2025-04-27 21:31:41,697 - httpcore.http11 - DEBUG - response_closed.complete
262
+ 2025-04-27 21:31:41,697 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'GET']>
263
+ 2025-04-27 21:31:41,697 - httpcore.connection - DEBUG - close.started
264
+ 2025-04-27 21:31:41,697 - httpcore.connection - DEBUG - close.complete
265
+ 2025-04-27 21:31:41,697 - httpcore.http11 - DEBUG - send_request_headers.complete
266
+ 2025-04-27 21:31:41,697 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'GET']>
267
+ 2025-04-27 21:31:41,698 - httpcore.http11 - DEBUG - send_request_body.complete
268
+ 2025-04-27 21:31:41,698 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'GET']>
269
+ 2025-04-27 21:31:41,698 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /api/telemetry/gradio/initiated HTTP/1.1" 200 0
270
+ 2025-04-27 21:31:41,698 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
271
+ 2025-04-27 21:31:41,725 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:31:41 GMT'), (b'Content-Type', b'application/json'), (b'Content-Length', b'21'), (b'Connection', b'keep-alive'), (b'Server', b'nginx/1.18.0'), (b'Access-Control-Allow-Origin', b'*')])
272
+ 2025-04-27 21:31:41,725 - httpx - INFO - HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
273
+ 2025-04-27 21:31:41,725 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'GET']>
274
+ 2025-04-27 21:31:41,725 - httpcore.http11 - DEBUG - receive_response_body.complete
275
+ 2025-04-27 21:31:41,725 - httpcore.http11 - DEBUG - response_closed.started
276
+ 2025-04-27 21:31:41,725 - httpcore.http11 - DEBUG - response_closed.complete
277
+ 2025-04-27 21:31:41,725 - httpcore.connection - DEBUG - close.started
278
+ 2025-04-27 21:31:41,725 - httpcore.connection - DEBUG - close.complete
279
+ 2025-04-27 21:31:41,813 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /api/telemetry/gradio/launched HTTP/1.1" 200 0
280
+ 2025-04-27 21:32:07,750 - __main__ - DEBUG - === New Gradio Request: How long is recovery after a bilateral reduction mammoplasty? ===
281
+ 2025-04-27 21:32:07,750 - agent - DEBUG - Received question: How long is recovery after a bilateral reduction mammoplasty?
282
+ 2025-04-27 21:32:07,752 - anthropic._base_client - DEBUG - Request options: {'method': 'post', 'url': '/v1/messages', 'timeout': Timeout(connect=5.0, read=600, write=600, pool=600), 'files': None, 'idempotency_key': 'stainless-python-retry-144c710b-054e-477c-b32a-2db40e3324ec', 'json_data': {'max_tokens': 500, 'messages': [{'role': 'user', 'content': 'Question: "Decide which tool(s) are needed to answer this question: "How long is recovery after a bilateral reduction mammoplasty?".\n Available tools:\n - Document RAG (for clinical facts)\n - Search (for public info)\n\n Reply in format:\n TOOL: [Document/Search/Both/All]\n "\n\nDecide the best tool for answering it. Reply exactly with TOOL: [Document], TOOL: [Search], or TOOL: [Both]. No other text.'}], 'model': 'claude-3-7-sonnet-20250219', 'system': 'You are an expert clinical AI assistant. You must strictly reply in ONLY one of the following formats: TOOL: [Document], TOOL: [Search], or TOOL: [Both].\n\nFor questions about general medical information like recovery times, procedure durations, or standard practices, prefer TOOL: [Search].\nFor questions about specific medical cases or rare conditions found in the document database, use TOOL: [Document].\nFor questions that would benefit from both sources, use TOOL: [Both].\n\nNever explain, never say anything else.', 'temperature': 0}}
283
+ 2025-04-27 21:32:07,789 - anthropic._base_client - DEBUG - Sending HTTP Request: POST https://api.anthropic.com/v1/messages
284
+ 2025-04-27 21:32:07,790 - httpcore.connection - DEBUG - connect_tcp.started host='api.anthropic.com' port=443 local_address=None timeout=5.0 socket_options=[(65535, 8, True), (6, 257, 60), (6, 258, 5)]
285
+ 2025-04-27 21:32:07,806 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x168c582f0>
286
+ 2025-04-27 21:32:07,806 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x14a7aef50> server_hostname='api.anthropic.com' timeout=5.0
287
+ 2025-04-27 21:32:07,821 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x168c586b0>
288
+ 2025-04-27 21:32:07,821 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'POST']>
289
+ 2025-04-27 21:32:07,821 - httpcore.http11 - DEBUG - send_request_headers.complete
290
+ 2025-04-27 21:32:07,821 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'POST']>
291
+ 2025-04-27 21:32:07,821 - httpcore.http11 - DEBUG - send_request_body.complete
292
+ 2025-04-27 21:32:07,821 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'POST']>
293
+ 2025-04-27 21:32:08,770 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:32:08 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'anthropic-ratelimit-input-tokens-limit', b'20000'), (b'anthropic-ratelimit-input-tokens-remaining', b'20000'), (b'anthropic-ratelimit-input-tokens-reset', b'2025-04-28T04:32:08Z'), (b'anthropic-ratelimit-output-tokens-limit', b'8000'), (b'anthropic-ratelimit-output-tokens-remaining', b'8000'), (b'anthropic-ratelimit-output-tokens-reset', b'2025-04-28T04:32:08Z'), (b'anthropic-ratelimit-requests-limit', b'50'), (b'anthropic-ratelimit-requests-remaining', b'49'), (b'anthropic-ratelimit-requests-reset', b'2025-04-28T04:32:09Z'), (b'anthropic-ratelimit-tokens-limit', b'28000'), (b'anthropic-ratelimit-tokens-remaining', b'28000'), (b'anthropic-ratelimit-tokens-reset', b'2025-04-28T04:32:08Z'), (b'request-id', b'req_011CNaWCfAMwvKwNtLUtUdDv'), (b'anthropic-organization-id', b'961c62a8-661b-402f-b3ec-38f150bfa917'), (b'via', b'1.1 google'), (b'cf-cache-status', b'DYNAMIC'), (b'X-Robots-Tag', b'none'), (b'Server', b'cloudflare'), (b'CF-RAY', b'9373d580e958ed39-SJC'), (b'Content-Encoding', b'gzip')])
294
+ 2025-04-27 21:32:08,771 - httpx - INFO - HTTP Request: POST https://api.anthropic.com/v1/messages "HTTP/1.1 200 OK"
295
+ 2025-04-27 21:32:08,772 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'POST']>
296
+ 2025-04-27 21:32:08,772 - httpcore.http11 - DEBUG - receive_response_body.complete
297
+ 2025-04-27 21:32:08,772 - httpcore.http11 - DEBUG - response_closed.started
298
+ 2025-04-27 21:32:08,772 - httpcore.http11 - DEBUG - response_closed.complete
299
+ 2025-04-27 21:32:08,773 - anthropic._base_client - DEBUG - HTTP Response: POST https://api.anthropic.com/v1/messages "200 OK" Headers({'date': 'Mon, 28 Apr 2025 04:32:08 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'anthropic-ratelimit-input-tokens-limit': '20000', 'anthropic-ratelimit-input-tokens-remaining': '20000', 'anthropic-ratelimit-input-tokens-reset': '2025-04-28T04:32:08Z', 'anthropic-ratelimit-output-tokens-limit': '8000', 'anthropic-ratelimit-output-tokens-remaining': '8000', 'anthropic-ratelimit-output-tokens-reset': '2025-04-28T04:32:08Z', 'anthropic-ratelimit-requests-limit': '50', 'anthropic-ratelimit-requests-remaining': '49', 'anthropic-ratelimit-requests-reset': '2025-04-28T04:32:09Z', 'anthropic-ratelimit-tokens-limit': '28000', 'anthropic-ratelimit-tokens-remaining': '28000', 'anthropic-ratelimit-tokens-reset': '2025-04-28T04:32:08Z', 'request-id': 'req_011CNaWCfAMwvKwNtLUtUdDv', 'anthropic-organization-id': '961c62a8-661b-402f-b3ec-38f150bfa917', 'via': '1.1 google', 'cf-cache-status': 'DYNAMIC', 'x-robots-tag': 'none', 'server': 'cloudflare', 'cf-ray': '9373d580e958ed39-SJC', 'content-encoding': 'gzip'})
300
+ 2025-04-27 21:32:08,773 - anthropic._base_client - DEBUG - request_id: req_011CNaWCfAMwvKwNtLUtUdDv
301
+ 2025-04-27 21:32:08,781 - agent - DEBUG - Tool decision raw response: 'TOOL: [Search]'
302
+ 2025-04-27 21:32:08,782 - agent - DEBUG - Parsed decision - Use Document: False, Use Search: True
303
+ 2025-04-27 21:32:08,782 - agent - DEBUG - Searching web...
304
+ 2025-04-27 21:32:08,794 - primp.utils - DEBUG - Loaded CA certs
305
+ 2025-04-27 21:32:08,799 - rquest.connect - DEBUG - starting new connection: https://html.duckduckgo.com/
306
+ 2025-04-27 21:32:08,799 - rquest.util.client.connect.dns - DEBUG - resolving html.duckduckgo.com
307
+ 2025-04-27 21:32:08,809 - rquest.util.client.connect.http - DEBUG - connecting to 52.250.42.157:443
308
+ 2025-04-27 21:32:08,838 - rquest.util.client.connect.http - DEBUG - connected to 52.250.42.157:443
309
+ 2025-04-27 21:32:08,870 - rquest.util.client.pool - DEBUG - pooling idle connection for PoolKey { uri: https://html.duckduckgo.com/, alpn_protos: None, network: default }
310
+ 2025-04-27 21:32:09,874 - cookie_store.cookie_store - DEBUG - inserting secure cookie 'kl'
311
+ 2025-04-27 21:32:09,875 - primp - INFO - response: https://html.duckduckgo.com/html 200
312
+ 2025-04-27 21:32:09,876 - duckduckgo_search.DDGS - DEBUG - _get_url() https://html.duckduckgo.com/html 200
313
+ 2025-04-27 21:32:09,886 - agent - DEBUG - Search returned 1319 characters
314
+ 2025-04-27 21:34:34,678 - httpcore.connection - DEBUG - close.started
315
+ 2025-04-27 21:34:34,680 - httpcore.connection - DEBUG - close.complete
316
+ 2025-04-27 21:34:39,730 - sentence_transformers.SentenceTransformer - INFO - Use pytorch device_name: mps
317
+ 2025-04-27 21:34:39,730 - sentence_transformers.SentenceTransformer - INFO - Load pretrained SentenceTransformer: all-MiniLM-L6-v2
318
+ 2025-04-27 21:34:39,732 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
319
+ 2025-04-27 21:34:39,849 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json HTTP/1.1" 200 0
320
+ 2025-04-27 21:34:39,941 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/config_sentence_transformers.json HTTP/1.1" 200 0
321
+ 2025-04-27 21:34:40,039 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/README.md HTTP/1.1" 200 0
322
+ 2025-04-27 21:34:40,137 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json HTTP/1.1" 200 0
323
+ 2025-04-27 21:34:40,235 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/sentence_bert_config.json HTTP/1.1" 200 0
324
+ 2025-04-27 21:34:40,333 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/adapter_config.json HTTP/1.1" 404 0
325
+ 2025-04-27 21:34:40,431 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/config.json HTTP/1.1" 200 0
326
+ 2025-04-27 21:34:40,715 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/tokenizer_config.json HTTP/1.1" 200 0
327
+ 2025-04-27 21:34:40,840 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "GET /api/models/sentence-transformers/all-MiniLM-L6-v2/revision/main HTTP/1.1" 200 6766
328
+ 2025-04-27 21:34:40,954 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "GET /api/models/sentence-transformers/all-MiniLM-L6-v2 HTTP/1.1" 200 6766
329
+ 2025-04-27 21:35:23,504 - asyncio - DEBUG - Using selector: KqueueSelector
330
+ 2025-04-27 21:35:23,505 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
331
+ 2025-04-27 21:35:23,529 - httpcore.connection - DEBUG - connect_tcp.started host='api.gradio.app' port=443 local_address=None timeout=3 socket_options=None
332
+ 2025-04-27 21:35:23,587 - asyncio - DEBUG - Using selector: KqueueSelector
333
+ 2025-04-27 21:35:23,624 - httpcore.connection - DEBUG - connect_tcp.started host='127.0.0.1' port=7861 local_address=None timeout=None socket_options=None
334
+ 2025-04-27 21:35:23,624 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x1401a7110>
335
+ 2025-04-27 21:35:23,624 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'GET']>
336
+ 2025-04-27 21:35:23,624 - httpcore.http11 - DEBUG - send_request_headers.complete
337
+ 2025-04-27 21:35:23,625 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'GET']>
338
+ 2025-04-27 21:35:23,625 - httpcore.http11 - DEBUG - send_request_body.complete
339
+ 2025-04-27 21:35:23,625 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'GET']>
340
+ 2025-04-27 21:35:23,625 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'date', b'Mon, 28 Apr 2025 04:35:23 GMT'), (b'server', b'uvicorn'), (b'content-length', b'4'), (b'content-type', b'application/json')])
341
+ 2025-04-27 21:35:23,625 - httpx - INFO - HTTP Request: GET http://127.0.0.1:7861/gradio_api/startup-events "HTTP/1.1 200 OK"
342
+ 2025-04-27 21:35:23,625 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'GET']>
343
+ 2025-04-27 21:35:23,625 - httpcore.http11 - DEBUG - receive_response_body.complete
344
+ 2025-04-27 21:35:23,625 - httpcore.http11 - DEBUG - response_closed.started
345
+ 2025-04-27 21:35:23,625 - httpcore.http11 - DEBUG - response_closed.complete
346
+ 2025-04-27 21:35:23,626 - httpcore.connection - DEBUG - close.started
347
+ 2025-04-27 21:35:23,626 - httpcore.connection - DEBUG - close.complete
348
+ 2025-04-27 21:35:23,626 - httpcore.connection - DEBUG - connect_tcp.started host='127.0.0.1' port=7861 local_address=None timeout=3 socket_options=None
349
+ 2025-04-27 21:35:23,626 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x1401a7920>
350
+ 2025-04-27 21:35:23,626 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'HEAD']>
351
+ 2025-04-27 21:35:23,626 - httpcore.http11 - DEBUG - send_request_headers.complete
352
+ 2025-04-27 21:35:23,626 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'HEAD']>
353
+ 2025-04-27 21:35:23,626 - httpcore.http11 - DEBUG - send_request_body.complete
354
+ 2025-04-27 21:35:23,626 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'HEAD']>
355
+ 2025-04-27 21:35:23,635 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'date', b'Mon, 28 Apr 2025 04:35:23 GMT'), (b'server', b'uvicorn'), (b'content-length', b'15026'), (b'content-type', b'text/html; charset=utf-8')])
356
+ 2025-04-27 21:35:23,635 - httpx - INFO - HTTP Request: HEAD http://127.0.0.1:7861/ "HTTP/1.1 200 OK"
357
+ 2025-04-27 21:35:23,635 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'HEAD']>
358
+ 2025-04-27 21:35:23,635 - httpcore.http11 - DEBUG - receive_response_body.complete
359
+ 2025-04-27 21:35:23,635 - httpcore.http11 - DEBUG - response_closed.started
360
+ 2025-04-27 21:35:23,635 - httpcore.http11 - DEBUG - response_closed.complete
361
+ 2025-04-27 21:35:23,635 - httpcore.connection - DEBUG - close.started
362
+ 2025-04-27 21:35:23,635 - httpcore.connection - DEBUG - close.complete
363
+ 2025-04-27 21:35:23,636 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
364
+ 2025-04-27 21:35:23,667 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x11859ba10>
365
+ 2025-04-27 21:35:23,667 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x118400550> server_hostname='api.gradio.app' timeout=3
366
+ 2025-04-27 21:35:23,725 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x1185da4b0>
367
+ 2025-04-27 21:35:23,726 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'GET']>
368
+ 2025-04-27 21:35:23,726 - httpcore.http11 - DEBUG - send_request_headers.complete
369
+ 2025-04-27 21:35:23,726 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'GET']>
370
+ 2025-04-27 21:35:23,726 - httpcore.http11 - DEBUG - send_request_body.complete
371
+ 2025-04-27 21:35:23,726 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'GET']>
372
+ 2025-04-27 21:35:23,740 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /api/telemetry/gradio/launched HTTP/1.1" 200 0
373
+ 2025-04-27 21:35:23,754 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:35:23 GMT'), (b'Content-Type', b'application/json'), (b'Content-Length', b'21'), (b'Connection', b'keep-alive'), (b'Server', b'nginx/1.18.0'), (b'Access-Control-Allow-Origin', b'*')])
374
+ 2025-04-27 21:35:23,754 - httpx - INFO - HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
375
+ 2025-04-27 21:35:23,754 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'GET']>
376
+ 2025-04-27 21:35:23,754 - httpcore.http11 - DEBUG - receive_response_body.complete
377
+ 2025-04-27 21:35:23,754 - httpcore.http11 - DEBUG - response_closed.started
378
+ 2025-04-27 21:35:23,754 - httpcore.http11 - DEBUG - response_closed.complete
379
+ 2025-04-27 21:35:23,754 - httpcore.connection - DEBUG - close.started
380
+ 2025-04-27 21:35:23,754 - httpcore.connection - DEBUG - close.complete
381
+ 2025-04-27 21:35:24,025 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /api/telemetry/gradio/initiated HTTP/1.1" 200 0
382
+ 2025-04-27 21:35:32,829 - agent - DEBUG - Received question: What was the diagnosis for the ORIF surgery?
383
+ 2025-04-27 21:35:32,832 - anthropic._base_client - DEBUG - Request options: {'method': 'post', 'url': '/v1/messages', 'timeout': Timeout(connect=5.0, read=600, write=600, pool=600), 'files': None, 'idempotency_key': 'stainless-python-retry-fa4fff39-009c-45c4-9412-9a0a268e6d83', 'json_data': {'max_tokens': 500, 'messages': [{'role': 'user', 'content': 'Question: "Decide which tool(s) are needed to answer this question: "What was the diagnosis for the ORIF surgery?".\n Available tools:\n - Document RAG (for clinical facts)\n - Search (for public info)\n\n Reply in format:\n TOOL: [Document/Search/Both/All]\n "\n\nDecide the best tool for answering it. Reply exactly with TOOL: [Document], TOOL: [Search], or TOOL: [Both]. No other text.'}], 'model': 'claude-3-7-sonnet-20250219', 'system': 'You are an expert clinical AI assistant. You must strictly reply in ONLY one of the following formats: TOOL: [Document], TOOL: [Search], or TOOL: [Both].\n\nFor questions about general medical information like recovery times, procedure durations, or standard practices, prefer TOOL: [Search].\nFor questions about specific medical cases or rare conditions found in the document database, use TOOL: [Document].\nFor questions that would benefit from both sources, use TOOL: [Both].\n\nNever explain, never say anything else.', 'temperature': 0}}
384
+ 2025-04-27 21:35:32,870 - anthropic._base_client - DEBUG - Sending HTTP Request: POST https://api.anthropic.com/v1/messages
385
+ 2025-04-27 21:35:32,870 - httpcore.connection - DEBUG - connect_tcp.started host='api.anthropic.com' port=443 local_address=None timeout=5.0 socket_options=[(65535, 8, True), (6, 257, 60), (6, 258, 5)]
386
+ 2025-04-27 21:35:32,883 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x140540cb0>
387
+ 2025-04-27 21:35:32,883 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x117622e50> server_hostname='api.anthropic.com' timeout=5.0
388
+ 2025-04-27 21:35:32,894 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x140540e90>
389
+ 2025-04-27 21:35:32,894 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'POST']>
390
+ 2025-04-27 21:35:32,894 - httpcore.http11 - DEBUG - send_request_headers.complete
391
+ 2025-04-27 21:35:32,894 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'POST']>
392
+ 2025-04-27 21:35:32,894 - httpcore.http11 - DEBUG - send_request_body.complete
393
+ 2025-04-27 21:35:32,894 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'POST']>
394
+ 2025-04-27 21:35:34,870 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:35:34 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'anthropic-ratelimit-input-tokens-limit', b'20000'), (b'anthropic-ratelimit-input-tokens-remaining', b'20000'), (b'anthropic-ratelimit-input-tokens-reset', b'2025-04-28T04:35:34Z'), (b'anthropic-ratelimit-output-tokens-limit', b'8000'), (b'anthropic-ratelimit-output-tokens-remaining', b'8000'), (b'anthropic-ratelimit-output-tokens-reset', b'2025-04-28T04:35:34Z'), (b'anthropic-ratelimit-requests-limit', b'50'), (b'anthropic-ratelimit-requests-remaining', b'49'), (b'anthropic-ratelimit-requests-reset', b'2025-04-28T04:35:34Z'), (b'anthropic-ratelimit-tokens-limit', b'28000'), (b'anthropic-ratelimit-tokens-remaining', b'28000'), (b'anthropic-ratelimit-tokens-reset', b'2025-04-28T04:35:34Z'), (b'request-id', b'req_011CNaWTmt6eZdUsmiDBpSsa'), (b'anthropic-organization-id', b'961c62a8-661b-402f-b3ec-38f150bfa917'), (b'via', b'1.1 google'), (b'CF-Cache-Status', b'DYNAMIC'), (b'X-Robots-Tag', b'none'), (b'Server', b'cloudflare'), (b'CF-RAY', b'9373da82ab3aed3f-SJC'), (b'Content-Encoding', b'gzip')])
395
+ 2025-04-27 21:35:34,871 - httpx - INFO - HTTP Request: POST https://api.anthropic.com/v1/messages "HTTP/1.1 200 OK"
396
+ 2025-04-27 21:35:34,871 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'POST']>
397
+ 2025-04-27 21:35:34,872 - httpcore.http11 - DEBUG - receive_response_body.complete
398
+ 2025-04-27 21:35:34,872 - httpcore.http11 - DEBUG - response_closed.started
399
+ 2025-04-27 21:35:34,872 - httpcore.http11 - DEBUG - response_closed.complete
400
+ 2025-04-27 21:35:34,873 - anthropic._base_client - DEBUG - HTTP Response: POST https://api.anthropic.com/v1/messages "200 OK" Headers({'date': 'Mon, 28 Apr 2025 04:35:34 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'anthropic-ratelimit-input-tokens-limit': '20000', 'anthropic-ratelimit-input-tokens-remaining': '20000', 'anthropic-ratelimit-input-tokens-reset': '2025-04-28T04:35:34Z', 'anthropic-ratelimit-output-tokens-limit': '8000', 'anthropic-ratelimit-output-tokens-remaining': '8000', 'anthropic-ratelimit-output-tokens-reset': '2025-04-28T04:35:34Z', 'anthropic-ratelimit-requests-limit': '50', 'anthropic-ratelimit-requests-remaining': '49', 'anthropic-ratelimit-requests-reset': '2025-04-28T04:35:34Z', 'anthropic-ratelimit-tokens-limit': '28000', 'anthropic-ratelimit-tokens-remaining': '28000', 'anthropic-ratelimit-tokens-reset': '2025-04-28T04:35:34Z', 'request-id': 'req_011CNaWTmt6eZdUsmiDBpSsa', 'anthropic-organization-id': '961c62a8-661b-402f-b3ec-38f150bfa917', 'via': '1.1 google', 'cf-cache-status': 'DYNAMIC', 'x-robots-tag': 'none', 'server': 'cloudflare', 'cf-ray': '9373da82ab3aed3f-SJC', 'content-encoding': 'gzip'})
401
+ 2025-04-27 21:35:34,873 - anthropic._base_client - DEBUG - request_id: req_011CNaWTmt6eZdUsmiDBpSsa
402
+ 2025-04-27 21:35:34,884 - agent - DEBUG - Tool decision raw response: 'TOOL: [Document]'
403
+ 2025-04-27 21:35:34,884 - agent - DEBUG - Parsed decision - Use Document: True, Use Search: False
404
+ 2025-04-27 21:35:34,885 - agent - DEBUG - Retrieving from documents...
405
+ 2025-04-27 21:35:35,105 - agent - DEBUG - Document retrieval returned 5595 characters
406
+ 2025-04-27 21:37:17,006 - httpcore.connection - DEBUG - close.started
407
+ 2025-04-27 21:37:17,007 - httpcore.connection - DEBUG - close.complete
408
+ 2025-04-27 21:37:22,021 - sentence_transformers.SentenceTransformer - INFO - Use pytorch device_name: mps
409
+ 2025-04-27 21:37:22,021 - sentence_transformers.SentenceTransformer - INFO - Load pretrained SentenceTransformer: all-MiniLM-L6-v2
410
+ 2025-04-27 21:37:22,023 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
411
+ 2025-04-27 21:37:22,183 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json HTTP/1.1" 200 0
412
+ 2025-04-27 21:37:22,365 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/config_sentence_transformers.json HTTP/1.1" 200 0
413
+ 2025-04-27 21:37:22,459 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/README.md HTTP/1.1" 200 0
414
+ 2025-04-27 21:37:22,551 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json HTTP/1.1" 200 0
415
+ 2025-04-27 21:37:22,646 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/sentence_bert_config.json HTTP/1.1" 200 0
416
+ 2025-04-27 21:37:22,740 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/adapter_config.json HTTP/1.1" 404 0
417
+ 2025-04-27 21:37:22,836 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/config.json HTTP/1.1" 200 0
418
+ 2025-04-27 21:37:23,126 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /sentence-transformers/all-MiniLM-L6-v2/resolve/main/tokenizer_config.json HTTP/1.1" 200 0
419
+ 2025-04-27 21:37:23,244 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "GET /api/models/sentence-transformers/all-MiniLM-L6-v2/revision/main HTTP/1.1" 200 6766
420
+ 2025-04-27 21:37:23,362 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "GET /api/models/sentence-transformers/all-MiniLM-L6-v2 HTTP/1.1" 200 6766
421
+ 2025-04-27 21:38:06,564 - asyncio - DEBUG - Using selector: KqueueSelector
422
+ 2025-04-27 21:38:06,565 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
423
+ 2025-04-27 21:38:06,573 - httpcore.connection - DEBUG - connect_tcp.started host='api.gradio.app' port=443 local_address=None timeout=3 socket_options=None
424
+ 2025-04-27 21:38:06,646 - asyncio - DEBUG - Using selector: KqueueSelector
425
+ 2025-04-27 21:38:06,689 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /api/telemetry/gradio/initiated HTTP/1.1" 200 0
426
+ 2025-04-27 21:38:06,693 - httpcore.connection - DEBUG - connect_tcp.started host='127.0.0.1' port=7861 local_address=None timeout=None socket_options=None
427
+ 2025-04-27 21:38:06,693 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x142adb9b0>
428
+ 2025-04-27 21:38:06,693 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'GET']>
429
+ 2025-04-27 21:38:06,693 - httpcore.http11 - DEBUG - send_request_headers.complete
430
+ 2025-04-27 21:38:06,693 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'GET']>
431
+ 2025-04-27 21:38:06,694 - httpcore.http11 - DEBUG - send_request_body.complete
432
+ 2025-04-27 21:38:06,694 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'GET']>
433
+ 2025-04-27 21:38:06,694 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'date', b'Mon, 28 Apr 2025 04:38:06 GMT'), (b'server', b'uvicorn'), (b'content-length', b'4'), (b'content-type', b'application/json')])
434
+ 2025-04-27 21:38:06,694 - httpx - INFO - HTTP Request: GET http://127.0.0.1:7861/gradio_api/startup-events "HTTP/1.1 200 OK"
435
+ 2025-04-27 21:38:06,694 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'GET']>
436
+ 2025-04-27 21:38:06,694 - httpcore.http11 - DEBUG - receive_response_body.complete
437
+ 2025-04-27 21:38:06,694 - httpcore.http11 - DEBUG - response_closed.started
438
+ 2025-04-27 21:38:06,694 - httpcore.http11 - DEBUG - response_closed.complete
439
+ 2025-04-27 21:38:06,694 - httpcore.connection - DEBUG - close.started
440
+ 2025-04-27 21:38:06,694 - httpcore.connection - DEBUG - close.complete
441
+ 2025-04-27 21:38:06,695 - httpcore.connection - DEBUG - connect_tcp.started host='127.0.0.1' port=7861 local_address=None timeout=3 socket_options=None
442
+ 2025-04-27 21:38:06,695 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x168c9b500>
443
+ 2025-04-27 21:38:06,695 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'HEAD']>
444
+ 2025-04-27 21:38:06,695 - httpcore.http11 - DEBUG - send_request_headers.complete
445
+ 2025-04-27 21:38:06,695 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'HEAD']>
446
+ 2025-04-27 21:38:06,695 - httpcore.http11 - DEBUG - send_request_body.complete
447
+ 2025-04-27 21:38:06,695 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'HEAD']>
448
+ 2025-04-27 21:38:06,703 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'date', b'Mon, 28 Apr 2025 04:38:06 GMT'), (b'server', b'uvicorn'), (b'content-length', b'11567'), (b'content-type', b'text/html; charset=utf-8')])
449
+ 2025-04-27 21:38:06,703 - httpx - INFO - HTTP Request: HEAD http://127.0.0.1:7861/ "HTTP/1.1 200 OK"
450
+ 2025-04-27 21:38:06,703 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'HEAD']>
451
+ 2025-04-27 21:38:06,703 - httpcore.http11 - DEBUG - receive_response_body.complete
452
+ 2025-04-27 21:38:06,703 - httpcore.http11 - DEBUG - response_closed.started
453
+ 2025-04-27 21:38:06,703 - httpcore.http11 - DEBUG - response_closed.complete
454
+ 2025-04-27 21:38:06,704 - httpcore.connection - DEBUG - close.started
455
+ 2025-04-27 21:38:06,704 - httpcore.connection - DEBUG - close.complete
456
+ 2025-04-27 21:38:06,704 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): huggingface.co:443
457
+ 2025-04-27 21:38:06,705 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x145730260>
458
+ 2025-04-27 21:38:06,705 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x142b5ecd0> server_hostname='api.gradio.app' timeout=3
459
+ 2025-04-27 21:38:06,762 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x145730470>
460
+ 2025-04-27 21:38:06,762 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'GET']>
461
+ 2025-04-27 21:38:06,762 - httpcore.http11 - DEBUG - send_request_headers.complete
462
+ 2025-04-27 21:38:06,762 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'GET']>
463
+ 2025-04-27 21:38:06,762 - httpcore.http11 - DEBUG - send_request_body.complete
464
+ 2025-04-27 21:38:06,762 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'GET']>
465
+ 2025-04-27 21:38:06,790 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:38:06 GMT'), (b'Content-Type', b'application/json'), (b'Content-Length', b'21'), (b'Connection', b'keep-alive'), (b'Server', b'nginx/1.18.0'), (b'Access-Control-Allow-Origin', b'*')])
466
+ 2025-04-27 21:38:06,790 - httpx - INFO - HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
467
+ 2025-04-27 21:38:06,790 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'GET']>
468
+ 2025-04-27 21:38:06,790 - httpcore.http11 - DEBUG - receive_response_body.complete
469
+ 2025-04-27 21:38:06,790 - httpcore.http11 - DEBUG - response_closed.started
470
+ 2025-04-27 21:38:06,790 - httpcore.http11 - DEBUG - response_closed.complete
471
+ 2025-04-27 21:38:06,790 - httpcore.connection - DEBUG - close.started
472
+ 2025-04-27 21:38:06,790 - httpcore.connection - DEBUG - close.complete
473
+ 2025-04-27 21:38:06,805 - urllib3.connectionpool - DEBUG - https://huggingface.co:443 "HEAD /api/telemetry/gradio/launched HTTP/1.1" 200 0
474
+ 2025-04-27 21:39:42,246 - agent - DEBUG - Received question: What surgery was performed for the Arthroscopic Meniscoplasty note?
475
+ 2025-04-27 21:39:42,250 - anthropic._base_client - DEBUG - Request options: {'method': 'post', 'url': '/v1/messages', 'timeout': Timeout(connect=5.0, read=600, write=600, pool=600), 'files': None, 'idempotency_key': 'stainless-python-retry-77381fe9-d944-4597-8a2d-72fdb0d0c98f', 'json_data': {'max_tokens': 500, 'messages': [{'role': 'user', 'content': 'Question: "Decide which tool(s) are needed to answer this question: "What surgery was performed for the Arthroscopic Meniscoplasty note?".\n Available tools:\n - Document RAG (for clinical facts)\n - Search (for public info)\n\n Reply in format:\n TOOL: [Document/Search/Both/All]\n "\n\nDecide the best tool for answering it. Reply exactly with TOOL: [Document], TOOL: [Search], or TOOL: [Both]. No other text.'}], 'model': 'claude-3-7-sonnet-20250219', 'system': 'You are an expert clinical AI assistant. You must strictly reply in ONLY one of the following formats: TOOL: [Document], TOOL: [Search], or TOOL: [Both].\n\nFor questions about general medical information like recovery times, procedure durations, or standard practices, prefer TOOL: [Search].\nFor questions about specific medical cases or rare conditions found in the document database, use TOOL: [Document].\nFor questions that would benefit from both sources, use TOOL: [Both].\n\nNever explain, never say anything else.', 'temperature': 0}}
476
+ 2025-04-27 21:39:42,283 - anthropic._base_client - DEBUG - Sending HTTP Request: POST https://api.anthropic.com/v1/messages
477
+ 2025-04-27 21:39:42,283 - httpcore.connection - DEBUG - connect_tcp.started host='api.anthropic.com' port=443 local_address=None timeout=5.0 socket_options=[(65535, 8, True), (6, 257, 60), (6, 258, 5)]
478
+ 2025-04-27 21:39:42,299 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x169004a40>
479
+ 2025-04-27 21:39:42,299 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x1418aeed0> server_hostname='api.anthropic.com' timeout=5.0
480
+ 2025-04-27 21:39:42,309 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x1690042f0>
481
+ 2025-04-27 21:39:42,309 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'POST']>
482
+ 2025-04-27 21:39:42,309 - httpcore.http11 - DEBUG - send_request_headers.complete
483
+ 2025-04-27 21:39:42,309 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'POST']>
484
+ 2025-04-27 21:39:42,309 - httpcore.http11 - DEBUG - send_request_body.complete
485
+ 2025-04-27 21:39:42,309 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'POST']>
486
+ 2025-04-27 21:39:43,102 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:39:42 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'anthropic-ratelimit-input-tokens-limit', b'20000'), (b'anthropic-ratelimit-input-tokens-remaining', b'20000'), (b'anthropic-ratelimit-input-tokens-reset', b'2025-04-28T04:39:43Z'), (b'anthropic-ratelimit-output-tokens-limit', b'8000'), (b'anthropic-ratelimit-output-tokens-remaining', b'8000'), (b'anthropic-ratelimit-output-tokens-reset', b'2025-04-28T04:39:42Z'), (b'anthropic-ratelimit-requests-limit', b'50'), (b'anthropic-ratelimit-requests-remaining', b'49'), (b'anthropic-ratelimit-requests-reset', b'2025-04-28T04:39:43Z'), (b'anthropic-ratelimit-tokens-limit', b'28000'), (b'anthropic-ratelimit-tokens-remaining', b'28000'), (b'anthropic-ratelimit-tokens-reset', b'2025-04-28T04:39:42Z'), (b'request-id', b'req_011CNaWnACH6BGQesS1XTtMy'), (b'anthropic-organization-id', b'961c62a8-661b-402f-b3ec-38f150bfa917'), (b'via', b'1.1 google'), (b'cf-cache-status', b'DYNAMIC'), (b'X-Robots-Tag', b'none'), (b'Server', b'cloudflare'), (b'CF-RAY', b'9373e0997e1ccf1a-SJC'), (b'Content-Encoding', b'gzip')])
487
+ 2025-04-27 21:39:43,104 - httpx - INFO - HTTP Request: POST https://api.anthropic.com/v1/messages "HTTP/1.1 200 OK"
488
+ 2025-04-27 21:39:43,104 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'POST']>
489
+ 2025-04-27 21:39:43,105 - httpcore.http11 - DEBUG - receive_response_body.complete
490
+ 2025-04-27 21:39:43,105 - httpcore.http11 - DEBUG - response_closed.started
491
+ 2025-04-27 21:39:43,105 - httpcore.http11 - DEBUG - response_closed.complete
492
+ 2025-04-27 21:39:43,105 - anthropic._base_client - DEBUG - HTTP Response: POST https://api.anthropic.com/v1/messages "200 OK" Headers({'date': 'Mon, 28 Apr 2025 04:39:42 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'anthropic-ratelimit-input-tokens-limit': '20000', 'anthropic-ratelimit-input-tokens-remaining': '20000', 'anthropic-ratelimit-input-tokens-reset': '2025-04-28T04:39:43Z', 'anthropic-ratelimit-output-tokens-limit': '8000', 'anthropic-ratelimit-output-tokens-remaining': '8000', 'anthropic-ratelimit-output-tokens-reset': '2025-04-28T04:39:42Z', 'anthropic-ratelimit-requests-limit': '50', 'anthropic-ratelimit-requests-remaining': '49', 'anthropic-ratelimit-requests-reset': '2025-04-28T04:39:43Z', 'anthropic-ratelimit-tokens-limit': '28000', 'anthropic-ratelimit-tokens-remaining': '28000', 'anthropic-ratelimit-tokens-reset': '2025-04-28T04:39:42Z', 'request-id': 'req_011CNaWnACH6BGQesS1XTtMy', 'anthropic-organization-id': '961c62a8-661b-402f-b3ec-38f150bfa917', 'via': '1.1 google', 'cf-cache-status': 'DYNAMIC', 'x-robots-tag': 'none', 'server': 'cloudflare', 'cf-ray': '9373e0997e1ccf1a-SJC', 'content-encoding': 'gzip'})
493
+ 2025-04-27 21:39:43,106 - anthropic._base_client - DEBUG - request_id: req_011CNaWnACH6BGQesS1XTtMy
494
+ 2025-04-27 21:39:43,119 - agent - DEBUG - Tool decision raw response: 'TOOL: [Document]'
495
+ 2025-04-27 21:39:43,120 - agent - DEBUG - Parsed decision - Use Document: True, Use Search: False
496
+ 2025-04-27 21:39:43,120 - agent - DEBUG - Retrieving from documents...
497
+ 2025-04-27 21:39:43,651 - agent - DEBUG - Document retrieval returned 8878 characters
498
+ 2025-04-27 21:42:48,056 - agent - DEBUG - Received question: What was the diagnosis for the ORIF surgery?
499
+ 2025-04-27 21:42:48,058 - anthropic._base_client - DEBUG - Request options: {'method': 'post', 'url': '/v1/messages', 'timeout': Timeout(connect=5.0, read=600, write=600, pool=600), 'files': None, 'idempotency_key': 'stainless-python-retry-91105f91-14c8-48f6-a5ad-fa0e9781cb16', 'json_data': {'max_tokens': 500, 'messages': [{'role': 'user', 'content': 'Question: "Decide which tool(s) are needed to answer this question: "What was the diagnosis for the ORIF surgery?".\n Available tools:\n - Document RAG (for clinical facts)\n - Search (for public info)\n\n Reply in format:\n TOOL: [Document/Search/Both/All]\n "\n\nDecide the best tool for answering it. Reply exactly with TOOL: [Document], TOOL: [Search], or TOOL: [Both]. No other text.'}], 'model': 'claude-3-7-sonnet-20250219', 'system': 'You are an expert clinical AI assistant. You must strictly reply in ONLY one of the following formats: TOOL: [Document], TOOL: [Search], or TOOL: [Both].\n\nFor questions about general medical information like recovery times, procedure durations, or standard practices, prefer TOOL: [Search].\nFor questions about specific medical cases or rare conditions found in the document database, use TOOL: [Document].\nFor questions that would benefit from both sources, use TOOL: [Both].\n\nNever explain, never say anything else.', 'temperature': 0}}
500
+ 2025-04-27 21:42:48,059 - anthropic._base_client - DEBUG - Sending HTTP Request: POST https://api.anthropic.com/v1/messages
501
+ 2025-04-27 21:42:48,059 - httpcore.connection - DEBUG - close.started
502
+ 2025-04-27 21:42:48,060 - httpcore.connection - DEBUG - close.complete
503
+ 2025-04-27 21:42:48,060 - httpcore.connection - DEBUG - connect_tcp.started host='api.anthropic.com' port=443 local_address=None timeout=5.0 socket_options=[(65535, 8, True), (6, 257, 60), (6, 258, 5)]
504
+ 2025-04-27 21:42:48,076 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x142cb5160>
505
+ 2025-04-27 21:42:48,077 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x1418aeed0> server_hostname='api.anthropic.com' timeout=5.0
506
+ 2025-04-27 21:42:48,089 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x142cb49b0>
507
+ 2025-04-27 21:42:48,089 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'POST']>
508
+ 2025-04-27 21:42:48,090 - httpcore.http11 - DEBUG - send_request_headers.complete
509
+ 2025-04-27 21:42:48,090 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'POST']>
510
+ 2025-04-27 21:42:48,090 - httpcore.http11 - DEBUG - send_request_body.complete
511
+ 2025-04-27 21:42:48,090 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'POST']>
512
+ 2025-04-27 21:42:49,890 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:42:49 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'anthropic-ratelimit-input-tokens-limit', b'20000'), (b'anthropic-ratelimit-input-tokens-remaining', b'20000'), (b'anthropic-ratelimit-input-tokens-reset', b'2025-04-28T04:42:49Z'), (b'anthropic-ratelimit-output-tokens-limit', b'8000'), (b'anthropic-ratelimit-output-tokens-remaining', b'8000'), (b'anthropic-ratelimit-output-tokens-reset', b'2025-04-28T04:42:49Z'), (b'anthropic-ratelimit-requests-limit', b'50'), (b'anthropic-ratelimit-requests-remaining', b'49'), (b'anthropic-ratelimit-requests-reset', b'2025-04-28T04:42:49Z'), (b'anthropic-ratelimit-tokens-limit', b'28000'), (b'anthropic-ratelimit-tokens-remaining', b'28000'), (b'anthropic-ratelimit-tokens-reset', b'2025-04-28T04:42:49Z'), (b'request-id', b'req_011CNaX1rXHupjdqrCZSM1TP'), (b'anthropic-organization-id', b'961c62a8-661b-402f-b3ec-38f150bfa917'), (b'via', b'1.1 google'), (b'cf-cache-status', b'DYNAMIC'), (b'X-Robots-Tag', b'none'), (b'Server', b'cloudflare'), (b'CF-RAY', b'9373e5229e42ed38-SJC'), (b'Content-Encoding', b'gzip')])
513
+ 2025-04-27 21:42:49,891 - httpx - INFO - HTTP Request: POST https://api.anthropic.com/v1/messages "HTTP/1.1 200 OK"
514
+ 2025-04-27 21:42:49,892 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'POST']>
515
+ 2025-04-27 21:42:49,892 - httpcore.http11 - DEBUG - receive_response_body.complete
516
+ 2025-04-27 21:42:49,892 - httpcore.http11 - DEBUG - response_closed.started
517
+ 2025-04-27 21:42:49,892 - httpcore.http11 - DEBUG - response_closed.complete
518
+ 2025-04-27 21:42:49,892 - anthropic._base_client - DEBUG - HTTP Response: POST https://api.anthropic.com/v1/messages "200 OK" Headers({'date': 'Mon, 28 Apr 2025 04:42:49 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'anthropic-ratelimit-input-tokens-limit': '20000', 'anthropic-ratelimit-input-tokens-remaining': '20000', 'anthropic-ratelimit-input-tokens-reset': '2025-04-28T04:42:49Z', 'anthropic-ratelimit-output-tokens-limit': '8000', 'anthropic-ratelimit-output-tokens-remaining': '8000', 'anthropic-ratelimit-output-tokens-reset': '2025-04-28T04:42:49Z', 'anthropic-ratelimit-requests-limit': '50', 'anthropic-ratelimit-requests-remaining': '49', 'anthropic-ratelimit-requests-reset': '2025-04-28T04:42:49Z', 'anthropic-ratelimit-tokens-limit': '28000', 'anthropic-ratelimit-tokens-remaining': '28000', 'anthropic-ratelimit-tokens-reset': '2025-04-28T04:42:49Z', 'request-id': 'req_011CNaX1rXHupjdqrCZSM1TP', 'anthropic-organization-id': '961c62a8-661b-402f-b3ec-38f150bfa917', 'via': '1.1 google', 'cf-cache-status': 'DYNAMIC', 'x-robots-tag': 'none', 'server': 'cloudflare', 'cf-ray': '9373e5229e42ed38-SJC', 'content-encoding': 'gzip'})
519
+ 2025-04-27 21:42:49,893 - anthropic._base_client - DEBUG - request_id: req_011CNaX1rXHupjdqrCZSM1TP
520
+ 2025-04-27 21:42:49,893 - agent - DEBUG - Tool decision raw response: 'TOOL: [Document]'
521
+ 2025-04-27 21:42:49,893 - agent - DEBUG - Parsed decision - Use Document: True, Use Search: False
522
+ 2025-04-27 21:42:49,893 - agent - DEBUG - Retrieving from documents...
523
+ 2025-04-27 21:42:50,317 - agent - DEBUG - Document retrieval returned 5595 characters
524
+ 2025-04-27 21:43:31,235 - agent - DEBUG - Received question: What is the average lifespan of a knee prosthesis after total knee arthroplasty?
525
+ 2025-04-27 21:43:31,236 - anthropic._base_client - DEBUG - Request options: {'method': 'post', 'url': '/v1/messages', 'timeout': Timeout(connect=5.0, read=600, write=600, pool=600), 'files': None, 'idempotency_key': 'stainless-python-retry-0af2d676-3ece-4cbe-8ad7-961cdb5df218', 'json_data': {'max_tokens': 500, 'messages': [{'role': 'user', 'content': 'Question: "Decide which tool(s) are needed to answer this question: "What is the average lifespan of a knee prosthesis after total knee arthroplasty?".\n Available tools:\n - Document RAG (for clinical facts)\n - Search (for public info)\n\n Reply in format:\n TOOL: [Document/Search/Both/All]\n "\n\nDecide the best tool for answering it. Reply exactly with TOOL: [Document], TOOL: [Search], or TOOL: [Both]. No other text.'}], 'model': 'claude-3-7-sonnet-20250219', 'system': 'You are an expert clinical AI assistant. You must strictly reply in ONLY one of the following formats: TOOL: [Document], TOOL: [Search], or TOOL: [Both].\n\nFor questions about general medical information like recovery times, procedure durations, or standard practices, prefer TOOL: [Search].\nFor questions about specific medical cases or rare conditions found in the document database, use TOOL: [Document].\nFor questions that would benefit from both sources, use TOOL: [Both].\n\nNever explain, never say anything else.', 'temperature': 0}}
526
+ 2025-04-27 21:43:31,237 - anthropic._base_client - DEBUG - Sending HTTP Request: POST https://api.anthropic.com/v1/messages
527
+ 2025-04-27 21:43:31,237 - httpcore.connection - DEBUG - close.started
528
+ 2025-04-27 21:43:31,238 - httpcore.connection - DEBUG - close.complete
529
+ 2025-04-27 21:43:31,238 - httpcore.connection - DEBUG - connect_tcp.started host='api.anthropic.com' port=443 local_address=None timeout=5.0 socket_options=[(65535, 8, True), (6, 257, 60), (6, 258, 5)]
530
+ 2025-04-27 21:43:31,248 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x142cb7b90>
531
+ 2025-04-27 21:43:31,248 - httpcore.connection - DEBUG - start_tls.started ssl_context=<ssl.SSLContext object at 0x1418aeed0> server_hostname='api.anthropic.com' timeout=5.0
532
+ 2025-04-27 21:43:31,263 - httpcore.connection - DEBUG - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x142cb67e0>
533
+ 2025-04-27 21:43:31,263 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'POST']>
534
+ 2025-04-27 21:43:31,264 - httpcore.http11 - DEBUG - send_request_headers.complete
535
+ 2025-04-27 21:43:31,264 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'POST']>
536
+ 2025-04-27 21:43:31,264 - httpcore.http11 - DEBUG - send_request_body.complete
537
+ 2025-04-27 21:43:31,264 - httpcore.http11 - DEBUG - receive_response_headers.started request=<Request [b'POST']>
538
+ 2025-04-27 21:43:32,481 - httpcore.http11 - DEBUG - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 28 Apr 2025 04:43:32 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'anthropic-ratelimit-input-tokens-limit', b'20000'), (b'anthropic-ratelimit-input-tokens-remaining', b'20000'), (b'anthropic-ratelimit-input-tokens-reset', b'2025-04-28T04:43:32Z'), (b'anthropic-ratelimit-output-tokens-limit', b'8000'), (b'anthropic-ratelimit-output-tokens-remaining', b'8000'), (b'anthropic-ratelimit-output-tokens-reset', b'2025-04-28T04:43:32Z'), (b'anthropic-ratelimit-requests-limit', b'50'), (b'anthropic-ratelimit-requests-remaining', b'49'), (b'anthropic-ratelimit-requests-reset', b'2025-04-28T04:43:32Z'), (b'anthropic-ratelimit-tokens-limit', b'28000'), (b'anthropic-ratelimit-tokens-remaining', b'28000'), (b'anthropic-ratelimit-tokens-reset', b'2025-04-28T04:43:32Z'), (b'request-id', b'req_011CNaX535sbAUkxd4s5KgDW'), (b'anthropic-organization-id', b'961c62a8-661b-402f-b3ec-38f150bfa917'), (b'via', b'1.1 google'), (b'cf-cache-status', b'DYNAMIC'), (b'X-Robots-Tag', b'none'), (b'Server', b'cloudflare'), (b'CF-RAY', b'9373e6306c9b7aca-SJC'), (b'Content-Encoding', b'gzip')])
539
+ 2025-04-27 21:43:32,482 - httpx - INFO - HTTP Request: POST https://api.anthropic.com/v1/messages "HTTP/1.1 200 OK"
540
+ 2025-04-27 21:43:32,483 - httpcore.http11 - DEBUG - receive_response_body.started request=<Request [b'POST']>
541
+ 2025-04-27 21:43:32,483 - httpcore.http11 - DEBUG - receive_response_body.complete
542
+ 2025-04-27 21:43:32,483 - httpcore.http11 - DEBUG - response_closed.started
543
+ 2025-04-27 21:43:32,483 - httpcore.http11 - DEBUG - response_closed.complete
544
+ 2025-04-27 21:43:32,484 - anthropic._base_client - DEBUG - HTTP Response: POST https://api.anthropic.com/v1/messages "200 OK" Headers({'date': 'Mon, 28 Apr 2025 04:43:32 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'anthropic-ratelimit-input-tokens-limit': '20000', 'anthropic-ratelimit-input-tokens-remaining': '20000', 'anthropic-ratelimit-input-tokens-reset': '2025-04-28T04:43:32Z', 'anthropic-ratelimit-output-tokens-limit': '8000', 'anthropic-ratelimit-output-tokens-remaining': '8000', 'anthropic-ratelimit-output-tokens-reset': '2025-04-28T04:43:32Z', 'anthropic-ratelimit-requests-limit': '50', 'anthropic-ratelimit-requests-remaining': '49', 'anthropic-ratelimit-requests-reset': '2025-04-28T04:43:32Z', 'anthropic-ratelimit-tokens-limit': '28000', 'anthropic-ratelimit-tokens-remaining': '28000', 'anthropic-ratelimit-tokens-reset': '2025-04-28T04:43:32Z', 'request-id': 'req_011CNaX535sbAUkxd4s5KgDW', 'anthropic-organization-id': '961c62a8-661b-402f-b3ec-38f150bfa917', 'via': '1.1 google', 'cf-cache-status': 'DYNAMIC', 'x-robots-tag': 'none', 'server': 'cloudflare', 'cf-ray': '9373e6306c9b7aca-SJC', 'content-encoding': 'gzip'})
545
+ 2025-04-27 21:43:32,484 - anthropic._base_client - DEBUG - request_id: req_011CNaX535sbAUkxd4s5KgDW
546
+ 2025-04-27 21:43:32,484 - agent - DEBUG - Tool decision raw response: 'TOOL: [Search]'
547
+ 2025-04-27 21:43:32,484 - agent - DEBUG - Parsed decision - Use Document: False, Use Search: True
548
+ 2025-04-27 21:43:32,485 - agent - DEBUG - Searching web...
549
+ 2025-04-27 21:43:32,490 - primp.utils - DEBUG - Loaded CA certs
550
+ 2025-04-27 21:43:32,492 - rquest.connect - DEBUG - starting new connection: https://lite.duckduckgo.com/
551
+ 2025-04-27 21:43:32,492 - rquest.util.client.connect.dns - DEBUG - resolving lite.duckduckgo.com
552
+ 2025-04-27 21:43:32,508 - rquest.util.client.connect.http - DEBUG - connecting to 52.250.42.157:443
553
+ 2025-04-27 21:43:32,539 - rquest.util.client.connect.http - DEBUG - connected to 52.250.42.157:443
554
+ 2025-04-27 21:43:32,570 - rquest.util.client.pool - DEBUG - pooling idle connection for PoolKey { uri: https://lite.duckduckgo.com/, alpn_protos: None, network: default }
555
+ 2025-04-27 21:43:33,508 - cookie_store.cookie_store - DEBUG - inserting secure cookie 'kl'
556
+ 2025-04-27 21:43:33,509 - primp - INFO - response: https://lite.duckduckgo.com/lite/ 200
557
+ 2025-04-27 21:43:33,510 - duckduckgo_search.DDGS - DEBUG - _get_url() https://lite.duckduckgo.com/lite/ 200
558
+ 2025-04-27 21:43:33,514 - agent - DEBUG - Search returned 1530 characters
559
+ 2025-04-27 21:45:15,027 - httpcore.connection - DEBUG - close.started
560
+ 2025-04-27 21:45:15,028 - httpcore.connection - DEBUG - close.complete
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ openai
2
+ requests
3
+ python-dotenv
4
+ faiss-cpu
5
+ sentence-transformers
6
+ pandas
7
+ duckduckgo_search
8
+ gradio
run_agent.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from agent import agent_respond
2
+
3
+ def main():
4
+ print("Welcome to the Healthcare Assistant!")
5
+ while True:
6
+ question = input("\nEnter your question (or type 'exit' to quit): ")
7
+ if question.lower() == 'exit':
8
+ break
9
+ answer = agent_respond(question)
10
+ print(f"\Answer:\n{answer}")
11
+
12
+ if __name__ == "__main__":
13
+ main()
tools/__pycache__/retriever_tool.cpython-312.pyc ADDED
Binary file (7.45 kB). View file
 
tools/__pycache__/search_tool.cpython-312.pyc ADDED
Binary file (1.21 kB). View file
 
tools/requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ openai
2
+ requests
3
+ python-dotenv
4
+ faiss-cpu
5
+ sentence-transformers
6
+ pandas
7
+ duckduckgo_search
8
+ gradio
9
+ anthropic
tools/retriever_tool.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import faiss
3
+ import numpy as np
4
+ import pandas as pd
5
+ import gc
6
+ import os
7
+ import time
8
+ from sentence_transformers import SentenceTransformer
9
+
10
+ class Retriever:
11
+ def __init__(self, csv_path="data/mtsamples_surgery.csv", top_k=3, similarity_threshold=0.2, batch_size=8):
12
+ self.model = SentenceTransformer('all-MiniLM-L6-v2')
13
+ self.dimension = self.model.get_sentence_embedding_dimension()
14
+ self.index = faiss.IndexFlatIP(self.dimension)
15
+ self.texts = []
16
+ self.metadata = []
17
+ self.top_k = top_k
18
+ self.similarity_threshold = similarity_threshold
19
+ self.batch_size = batch_size
20
+ self._build_index(csv_path)
21
+
22
+ def _preprocess_text(self, text):
23
+ if not isinstance(text, str):
24
+ return ""
25
+ text = re.sub(r'\s+', ' ', text).strip()
26
+ text = re.sub(r'[^\w\s.,?!:;()\[\]{}\-\'"]+', ' ', text)
27
+ return text
28
+
29
+ def _build_index(self, path):
30
+ gc.collect()
31
+
32
+ print(f"Loading CSV from {path}...")
33
+ df = pd.read_csv(path)
34
+
35
+ print(f"Loaded {len(df)} rows")
36
+
37
+ print("Filtering and preprocessing texts...")
38
+ df = df.dropna(subset=['transcription'])
39
+
40
+ self.metadata = df[['medical_specialty', 'sample_name']].to_dict('records')
41
+
42
+ self.texts = []
43
+ for i in range(0, len(df), self.batch_size):
44
+ batch = df['transcription'].iloc[i:i+self.batch_size].tolist()
45
+ self.texts.extend([self._preprocess_text(text) for text in batch])
46
+ gc.collect()
47
+
48
+ print(f"Preprocessing complete. Starting encoding {len(self.texts)} documents...")
49
+
50
+ for i in range(0, len(self.texts), self.batch_size):
51
+ end_idx = min(i + self.batch_size, len(self.texts))
52
+ batch = self.texts[i:end_idx]
53
+
54
+ print(f"Encoding batch {i//self.batch_size + 1}/{(len(self.texts) + self.batch_size - 1)//self.batch_size}...")
55
+
56
+ batch_embeddings = self.model.encode(batch, show_progress_bar=False)
57
+
58
+ faiss.normalize_L2(batch_embeddings)
59
+
60
+ self.index.add(np.array(batch_embeddings))
61
+
62
+ del batch_embeddings
63
+ gc.collect()
64
+
65
+ time.sleep(0.1)
66
+
67
+ print(f"Index built with {len(self.texts)} documents")
68
+
69
+ def add_documents(self, new_texts, new_metadata=None):
70
+ if not new_texts:
71
+ return
72
+
73
+ processed_texts = [self._preprocess_text(text) for text in new_texts]
74
+
75
+ # Add to existing texts and metadata
76
+ self.texts.extend(processed_texts)
77
+ if new_metadata:
78
+ self.metadata.extend(new_metadata)
79
+
80
+ # Encode and add to index
81
+ for i in range(0, len(processed_texts), self.batch_size):
82
+ batch = processed_texts[i:i+min(self.batch_size, len(processed_texts)-i)]
83
+ batch_embeddings = self.model.encode(batch, show_progress_bar=False)
84
+ faiss.normalize_L2(batch_embeddings)
85
+ self.index.add(np.array(batch_embeddings))
86
+
87
+ def query(self, question, include_metadata=True):
88
+ try:
89
+ q_embedding = self.model.encode([question])
90
+ faiss.normalize_L2(q_embedding)
91
+
92
+ k = min(self.top_k * 2, len(self.texts))
93
+ scores, indices = self.index.search(np.array(q_embedding), k)
94
+
95
+ results = []
96
+ for i, (score, idx) in enumerate(zip(scores[0], indices[0])):
97
+ if idx != -1 and score >= self.similarity_threshold and i < self.top_k:
98
+ doc_text = self.texts[idx]
99
+
100
+ if include_metadata and idx < len(self.metadata):
101
+ meta = self.metadata[idx]
102
+ doc_info = f"[Document {i+1}] (Score: {score:.2f}, Specialty: {meta.get('medical_specialty', 'Unknown')}, Sample: {meta.get('sample_name', 'Unknown')})\n\n{doc_text}"
103
+ else:
104
+ doc_info = f"[Document {i+1}] (Score: {score:.2f})\n\n{doc_text}"
105
+
106
+ results.append(doc_info)
107
+
108
+ gc.collect()
109
+
110
+ if not results:
111
+ return "No relevant documents found for this query."
112
+
113
+ return "\n\n" + "-"*80 + "\n\n".join(results)
114
+ except Exception as e:
115
+ return f"Error during retrieval: {str(e)}"
tools/search_tool.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from duckduckgo_search import DDGS
2
+
3
+
4
+ def search_duckduckgo(query, max_results=3):
5
+ """Perform a DuckDuckGo search for the given query."""
6
+ results = []
7
+ try:
8
+ with DDGS() as ddgs:
9
+ for r in ddgs.text(query, max_results=max_results):
10
+ results.append(f"Title: {r.get('title', 'No title')}\nSource: {r.get('href', 'No source')}\n{r['body']}")
11
+ if results:
12
+ return "\n\n".join(results)
13
+ else:
14
+ return "No relevant information found."
15
+ except Exception as e:
16
+ return f"Search error: {str(e)}"