ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
# Cursor Chat: ai-agent-book
|
||||
|
||||
## Metadata
|
||||
- **Project**: ai-agent-book
|
||||
- **Path**: `/Users/boj`
|
||||
- **Date**: 2025-09-23 14:45:33
|
||||
- **Session ID**: `86c41164-09eb-44eb-823b-a36699248bbd`
|
||||
|
||||
## Conversation
|
||||
|
||||
### 👤 You
|
||||
|
||||
retrieval-pipeline % python main.py
|
||||
Traceback (most recent call last):
|
||||
File "/Users/boj/ai-agent-book/projects/week3/retrieval-pipeline/main.py", line 12, in <module>
|
||||
from config import PipelineConfig, SearchMode
|
||||
File "/Users/boj/ai-agent-book/projects/week3/retrieval-pipeline/config.py", line 28, in <module>
|
||||
@dataclass
|
||||
^^^^^^^^^
|
||||
File "/Users/boj/miniconda3/lib/python3.11/dataclasses.py", line 1230, in dataclass
|
||||
return wrap(cls)
|
||||
^^^^^^^^^
|
||||
File "/Users/boj/miniconda3/lib/python3.11/dataclasses.py", line 1220, in wrap
|
||||
return _process_class(cls, init, repr, eq, order, unsafe_hash,
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
File "/Users/boj/miniconda3/lib/python3.11/dataclasses.py", line 958, in _process_class
|
||||
cls_fields.append(_get_field(cls, name, type, kw_only))
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
File "/Users/boj/miniconda3/lib/python3.11/dataclasses.py", line 815, in _get_field
|
||||
raise ValueError(f'mutable default {type(f.default)} for field '
|
||||
ValueError: mutable default <class 'config.ServiceConfig'> for field services is not allowed: use default_factory
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
I'll help you fix this dataclass error. The issue is that you're trying to use a mutable default value for a field in a dataclass, which is not allowed. Let me examine the config file to see what needs to be fixed.
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
I can see the issue. In the `PipelineConfig` dataclass (lines 31-32), you're trying to use mutable objects (`ServiceConfig()` and `RerankerConfig()`) as default values, which is not allowed in dataclasses. The solution is to use `field(default_factory=...)` instead. Let me fix this:
|
||||
|
||||
---
|
||||
|
||||
### 👤 You
|
||||
|
||||
retrieval-pipeline % python main.py
|
||||
/Users/boj/ai-agent-book/projects/week3/retrieval-pipeline/main.py:64: DeprecationWarning:
|
||||
on_event is deprecated, use lifespan event handlers instead.
|
||||
|
||||
Read more about it in the
|
||||
[FastAPI docs for Lifespan Events](https://fastapi.tiangolo.com/advanced/events/).
|
||||
|
||||
@app.on_event("startup")
|
||||
2025-09-23 14:47:29,061 - __main__ - INFO - Starting server on 0.0.0.0:8002
|
||||
2025-09-23 14:47:29,061 - __main__ - INFO - Dense service: http://localhost:8000
|
||||
2025-09-23 14:47:29,061 - __main__ - INFO - Sparse service: http://localhost:8001
|
||||
INFO: Started server process [3410]
|
||||
INFO: Waiting for application startup.
|
||||
2025-09-23 14:47:29,080 - __main__ - INFO - Starting retrieval pipeline...
|
||||
2025-09-23 14:47:29,080 - reranker - INFO - Initializing reranker with model: BAAI/bge-reranker-v2-m3
|
||||
2025-09-23 14:47:29,080 - reranker - INFO - Device: mps, FP16: True
|
||||
|
||||
--
|
||||
1. fix the warning
|
||||
2. why Initializing reranker is so slow? Is it downloading the model? Can we show the download progress
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
I'll help you fix the deprecation warning and investigate the slow reranker initialization. Let me examine the code first.
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
Now let me check the reranker implementation to understand why initialization is slow:
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
Let me fix both issues. First, I'll update main.py to fix the deprecation warning by using the lifespan context manager:
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
Now, let me update the reranker to show download progress when the model is being downloaded:
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
Let me also check and update the requirements.txt file to ensure the necessary dependencies are included:
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
Let's test the changes by running the main.py file again:
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
Good news! The fixes are working:
|
||||
|
||||
1. **✅ Deprecation warning fixed**: The warning about `on_event` is gone. The code now uses the modern `lifespan` context manager approach.
|
||||
|
||||
2. **✅ Model download progress tracking added**: The code now:
|
||||
- Checks if the model is already cached
|
||||
- Shows "Model already cached" if it exists
|
||||
- Would show download progress if it needs to download (using `huggingface_hub` and `tqdm`)
|
||||
- Shows the loading time: "Reranker initialized successfully in 3.40s"
|
||||
|
||||
The error at the end is just because port 8002 is already in use from a previous run. Let me kill that process and run it on a different port to verify everything works:
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
Let me check if the server is running properly:
|
||||
|
||||
---
|
||||
|
||||
### 🤖 Cursor Assistant
|
||||
|
||||
Let me create a simple test script to verify the improvements:
|
||||
|
||||
---
|
||||
|
||||
|
||||
*Exported from [Cursor View](https://github.com/saharmor/cursor-view)*
|
||||
Reference in New Issue
Block a user