nnngoc commited on
Commit
7b4a8f1
1 Parent(s): 2358b5a
Files changed (2) hide show
  1. llm.py +8 -6
  2. rag.py +2 -2
llm.py CHANGED
@@ -1,6 +1,7 @@
1
  import urllib3
2
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
3
- import os
 
4
  import requests
5
  from typing import Any, List, Mapping, Optional
6
 
@@ -9,8 +10,9 @@ from langchain.llms.base import LLM
9
 
10
  class URALLM(LLM):
11
  llm_url = os.environ.get("URL")
 
12
  class Config:
13
- extra = 'forbid'
14
 
15
  @property
16
  def _llm_type(self) -> str:
@@ -35,11 +37,10 @@ class URALLM(LLM):
35
  "repetition_penalty":1.1,
36
  "do_sample":True,
37
  "top_k":10
38
- },
39
- "token": os.environ.get("TOKEN")
40
  }
41
 
42
- headers = {"Content-Type": "application/json"}
43
 
44
  response = requests.post(self.llm_url, json=payload, headers=headers, verify=False)
45
  response.raise_for_status()
@@ -52,4 +53,5 @@ class URALLM(LLM):
52
  @property
53
  def _identifying_params(self) -> Mapping[str, Any]:
54
  """Get the identifying parameters."""
55
- return {"llmUrl": self.llm_url}
 
 
1
  import urllib3
2
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
3
+
4
+ from pydantic import Extra
5
  import requests
6
  from typing import Any, List, Mapping, Optional
7
 
 
10
 
11
  class URALLM(LLM):
12
  llm_url = os.environ.get("URL")
13
+
14
  class Config:
15
+ extra = Extra.forbid
16
 
17
  @property
18
  def _llm_type(self) -> str:
 
37
  "repetition_penalty":1.1,
38
  "do_sample":True,
39
  "top_k":10
40
+ }
 
41
  }
42
 
43
+ headers = {"Content-Type": "application/json", "Authorization": os.environ.get("TOKEN")}
44
 
45
  response = requests.post(self.llm_url, json=payload, headers=headers, verify=False)
46
  response.raise_for_status()
 
53
  @property
54
  def _identifying_params(self) -> Mapping[str, Any]:
55
  """Get the identifying parameters."""
56
+ return {"llmUrl": self.llm_url}
57
+
rag.py CHANGED
@@ -110,9 +110,9 @@ class CustomRetriever(BaseRetriever):
110
  for idx in sim_scores_argsort:
111
  docs.append(documents[idx])
112
 
113
- docs_top_4 = docs[0:4]
114
 
115
- return docs_top_4
116
 
117
  llm = URALLM()
118
  custom_retriever = CustomRetriever(vectorstores = vectordb,retriever = vectordb.as_retriever(search_kwargs={"k": 50}))
 
110
  for idx in sim_scores_argsort:
111
  docs.append(documents[idx])
112
 
113
+ docs_top_2 = docs[0:2]
114
 
115
+ return docs_top_2
116
 
117
  llm = URALLM()
118
  custom_retriever = CustomRetriever(vectorstores = vectordb,retriever = vectordb.as_retriever(search_kwargs={"k": 50}))