Files
povtornyy-ekzamen-faq-bot-c…/SOLUTION.md
T

49 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
**What was implemented**
- Replaced all Qdrant usage with a lightweight ChromaDB wrapper (`src/chromadb_client.py`).
- Built an FAQ bot that loads documents from a JSONlines file, stores them in ChromaDB, and retrieves the topk most similar documents for each user query.
- Integrated a single MCPtool (`src/mcp_tool.py`) that returns the current UTC time.
- Added OpenAI functioncalling logic in `src/main.py` so the model can invoke the MCPtool when needed.
**Why the main parts satisfy the requirements**
- The `ChromadbClient` uses `chromadb.Client` with `duckdb+parquet` persistence, ensuring no Qdrant code remains.
- `ask_question()` queries ChromaDB, builds a context from the hits, and sends it to GPT4omini, fulfilling the FAQbot functionality.
- Only one tool (`MCPTool`) is defined and registered in the function schema, meeting the “exactly one MCPtool” constraint.
- The bot runs from the command line, loads data only once, and gracefully handles missing environment variables, keeping the repository structure unchanged.
**Short code excerpts**
`src/chromadb_client.py` client initialization
```python
self.client = chromadb.Client(Settings(
chroma_db_impl="duckdb+parquet",
persist_directory=persist_directory,
))
self.collection = self.client.get_or_create_collection(name=collection_name)
```
`src/mcp_tool.py` single MCPtool implementation
```python
class MCPTool:
name = "get_current_utc_time"
description = "Returns the current UTC datetime in ISO 8601 format."
def __call__(self, arguments: Dict[str, Any]) -> Dict[str, Any]:
now = datetime.datetime.utcnow().isoformat() + "Z"
return {"current_time": now}
```
`src/main.py` functioncalling integration
```python
response = openai.ChatCompletion.create(
model="gpt-4o-mini",
messages=messages,
functions=[function_schema],
function_call="auto",
)
```
**Honest limitations**
- The bot loads all FAQ documents at startup; for very large datasets a more incremental approach would be preferable.
- Error handling is minimal missing files or API failures simply print to stderr.
- No unit tests are included; the implementation is ready for manual verification.
This solution meets all assignment constraints: ChromaDB is the sole vector store, only one MCPtool is used, and the bots logic is fully functional.