Skip to content

Commit

Permalink
fix(huixiangdou): test main.py passed
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisonooo committed Jan 15, 2024
1 parent ad61889 commit 68bd522
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 13 deletions.
4 changes: 2 additions & 2 deletions huixiangdou/frontend/lark.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def post(self, data):
headers=self.headers,
data=post_data,
verify=False,
timeout=5)
timeout=60)
except requests.exceptions.HTTPError as exc:
code = exc.response.status_code
reason = exc.response.reason
Expand Down Expand Up @@ -96,5 +96,5 @@ def post(self, data):
requests.post(self.webhook,
headers=self.headers,
data=json.dumps(error_data),
timeout=5)
timeout=60)
return result
2 changes: 1 addition & 1 deletion huixiangdou/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def check_env(args):
f'{CONFIG_NAME} not found, download a template from {CONFIG_URL}.')

try:
response = requests.get(CONFIG_URL, timeout=5)
response = requests.get(CONFIG_URL, timeout=60)
response.raise_for_status()
with open(CONFIG_NAME, 'wb') as f:
f.write(response.content)
Expand Down
17 changes: 14 additions & 3 deletions huixiangdou/service/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,22 @@ def load_feature(self,
feature_reject: str = 'db_reject'):
"""Load extracted feature."""
# https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html#langchain.vectorstores.faiss.FAISS

resp_dir = os.path.join(work_dir, feature_response)
reject_dir = os.path.join(work_dir, feature_reject)

if not os.path.exists(resp_dir) or not os.path.exists(reject_dir):
logger.error(
'Please check README.md first and `python3 -m huixiangdou.service.feature_store`' # noqa E501
)
raise Exception(
f'{resp_dir} or {reject_dir} not exist, please initialize with feature_store.' # noqa E501
)

self.vector_store_reject = Vectorstore.load_local(
os.path.join(work_dir, feature_response),
embeddings=self.embeddings)
reject_dir, embeddings=self.embeddings)
self.vector_store_db = Vectorstore.load_local(
os.path.join(work_dir, feature_reject), embeddings=self.embeddings)
resp_dir, embeddings=self.embeddings)

def get_doc_by_id(self, _id, vector_store):
"""Get doc by search id."""
Expand Down
2 changes: 1 addition & 1 deletion huixiangdou/service/llm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def generate_response(self, prompt, history=[], remote=False):
resp = requests.post(url,
headers=header,
data=json.dumps(data),
timeout=5)
timeout=300)
if resp.status_code != 200:
raise Exception(str((resp.status_code, resp.reason)))
return resp.json()['text']
Expand Down
6 changes: 5 additions & 1 deletion huixiangdou/service/llm_server_hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ def generate_response(self, prompt, history=[], remote=False):

else:
prompt = prompt[0:self.local_max_length]
"""# Caution: For the results of this software to be reliable and verifiable, # noqa E501
it's essential to ensure reproducibility. Thus `GenerationMode.GREEDY_SEARCH` # noqa E501
must enabled."""
output_text, _ = self.model.chat(self.tokenizer,
prompt,
history,
top_k=1)
top_k=1,
do_sample=False)
print((prompt, output_text))
time_finish = time.time()

Expand Down
6 changes: 3 additions & 3 deletions huixiangdou/service/web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def google(self, query: str, max_article):
url,
headers=headers,
data=payload,
timeout=3) # noqa E501
timeout=60) # noqa E501
jsonobj = json.loads(response.text)

# 带偏序的 url 连接拾取
Expand Down Expand Up @@ -137,7 +137,7 @@ def google(self, query: str, max_article):
while life < self.retry:
try:
logger.info(f'extract: {target_link}')
response = requests.get(target_link, timeout=5)
response = requests.get(target_link, timeout=60)
if len(response.text) < 1:
break

Expand Down Expand Up @@ -233,7 +233,7 @@ def fetch_web_content(target_link: str):
Extracts the main content and title from the HTML of the page. Returns the
title and content as a single string.
"""
response = requests.get(target_link, timeout=5)
response = requests.get(target_link, timeout=60)

doc = Document(response.text)
content_html = doc.summary()
Expand Down
3 changes: 1 addition & 2 deletions huixiangdou/service/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ def generate(self, query, history, groupname):
default=0):
reborn_code = ErrorCode.BAD_ANSWER

reborn_code = ErrorCode.BAD_ANSWER
if self.config['worker']['enable_sg_search']:
if reborn_code == ErrorCode.BAD_ANSWER or reborn_code == ErrorCode.NO_SEARCH_RESULT: # noqa E501
# reborn
Expand Down Expand Up @@ -292,7 +291,7 @@ def generate(self, query, history, groupname):
default=0):
return ErrorCode.BAD_ANSWER, response

if response is not None and len(response) >= 500:
if response is not None and len(response) >= 800:
# reply too long, summarize it
response = self.llm.generate_response(
prompt=self.SUMMARIZE_TEMPLATE.format(response))
Expand Down
19 changes: 19 additions & 0 deletions tests/test_internlm2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pdb

from transformers import AutoModelForCausalLM, AutoTokenizer

model_path = '/internlm/ampere_7b_v1_7_0'

tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_path,
trust_remote_code=True,
device_map='auto',
torch_dtype='auto').eval()

# 不能像某些 LLM 一样 AutoModelForCausalLM.from_pretrained(.. fp16=True) 这样写,会 Internlm2Config.__init__() 报错

queries = ['how to install mmdeploy ?']
for query in queries:
pdb.set_trace()
output_text, _ = model.chat(tokenizer, query, top_k=1, do_sample=False)
print(query, output_text)

0 comments on commit 68bd522

Please sign in to comment.