taspol commited on
Commit
faaabaa
·
1 Parent(s): bfad56c

fix: Restqdrant

Browse files
class_mod/rest_qdrant.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ class RestQdrantClient:
4
+ def __init__(self, url, api_key=None, verify=True, timeout=5):
5
+ self.url = url.rstrip("/")
6
+ self.session = requests.Session()
7
+ self.session.verify = verify
8
+ self.session.headers.update({"Content-Type": "application/json"})
9
+ if api_key:
10
+ self.session.headers.update({"api-key": api_key})
11
+ self.timeout = timeout
12
+
13
+ def get_collections(self):
14
+ r = self.session.get(f"{self.url}/collections", timeout=self.timeout)
15
+ r.raise_for_status()
16
+ return r.json()
17
+
18
+ def upsert(self, collection_name, points):
19
+ r = self.session.put(
20
+ f"{self.url}/collections/{collection_name}/points",
21
+ json={"points": points},
22
+ timeout=self.timeout
23
+ )
24
+ r.raise_for_status()
25
+ return r.json()
26
+
27
+ # Example usage:
28
+ client = RestQdrantClient(
29
+ url="https://qdrant.taspolsd.dev",
30
+ api_key="YOUR_API_KEY", # or None
31
+ verify=False # only if needed
32
+ )
33
+
34
+ print(client.get_collections())
data_importer.py CHANGED
@@ -3,6 +3,7 @@ from sentence_transformers import SentenceTransformer
3
  from qdrant_client import QdrantClient
4
  from qdrant_client.models import Distance, VectorParams, PointStruct
5
  from typing import List, Dict, Optional, Union
 
6
  import uuid
7
 
8
  class DataImporter:
@@ -20,7 +21,7 @@ class DataImporter:
20
  def _init_qdrant(self):
21
  """Initialize Qdrant client with error handling"""
22
  try:
23
- self.client = QdrantClient(url=self.qdrant_url)
24
  # Test connection
25
  self.client.get_collections()
26
  self.qdrant_available = True
 
3
  from qdrant_client import QdrantClient
4
  from qdrant_client.models import Distance, VectorParams, PointStruct
5
  from typing import List, Dict, Optional, Union
6
+ from class_mod.rest_qdrant import RestQdrantClient
7
  import uuid
8
 
9
  class DataImporter:
 
21
  def _init_qdrant(self):
22
  """Initialize Qdrant client with error handling"""
23
  try:
24
+ self.client = RestQdrantClient(url=self.qdrant_url)
25
  # Test connection
26
  self.client.get_collections()
27
  self.qdrant_available = True
utils/llm_caller.py CHANGED
@@ -8,6 +8,7 @@ from qdrant_client import QdrantClient
8
  from openai import OpenAI
9
  from sentence_transformers import SentenceTransformer
10
  from interface import PlanResponse, TripPlan, PlanStep, TransportInfo, RetrievedItem, PlanRequest
 
11
  import json
12
 
13
  load_dotenv()
@@ -15,14 +16,6 @@ SYSTEM_PROMPT = """You are a helpful travel assistant. Use the provided context
15
  If the context doesn't contain relevant information, say so politely and provide general advice if possible."""
16
  '''
17
  '''
18
- # @dataclass
19
- # class RetrievedItem:
20
- # place_id: str
21
- # place_name: str
22
- # description: Optional[str]
23
- # score: float
24
- # metadata: Dict[str, Any]
25
-
26
  class LLMCaller:
27
  def __init__(self):
28
  # Environment variables
@@ -32,7 +25,7 @@ class LLMCaller:
32
  )
33
  self.top_k = 3
34
  self.qdrant_host = os.getenv("QDRANT_HOST")
35
- self.qdrant = QdrantClient(
36
  url=self.qdrant_host,
37
  )
38
  self.system_prompt = SYSTEM_PROMPT
 
8
  from openai import OpenAI
9
  from sentence_transformers import SentenceTransformer
10
  from interface import PlanResponse, TripPlan, PlanStep, TransportInfo, RetrievedItem, PlanRequest
11
+ from class_mod.rest_qdrant import RestQdrantClient
12
  import json
13
 
14
  load_dotenv()
 
16
  If the context doesn't contain relevant information, say so politely and provide general advice if possible."""
17
  '''
18
  '''
 
 
 
 
 
 
 
 
19
  class LLMCaller:
20
  def __init__(self):
21
  # Environment variables
 
25
  )
26
  self.top_k = 3
27
  self.qdrant_host = os.getenv("QDRANT_HOST")
28
+ self.qdrant = RestQdrantClient(
29
  url=self.qdrant_host,
30
  )
31
  self.system_prompt = SYSTEM_PROMPT