From 987cabae7a9a8329091232072cd771422cef196e Mon Sep 17 00:00:00 2001 From: Jonas Geertsen Lund Date: Fri, 19 Jan 2024 10:14:54 +0100 Subject: [PATCH] Concept linking outcommented --- .../multilingual/llm_messenger.py | 19 ++++++++++++++++--- requirements.txt | 2 +- requirements_docker.txt | 2 +- server/server.py | 4 ++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/relation_extraction/multilingual/llm_messenger.py b/relation_extraction/multilingual/llm_messenger.py index 783bc4e..9ff5a4b 100644 --- a/relation_extraction/multilingual/llm_messenger.py +++ b/relation_extraction/multilingual/llm_messenger.py @@ -2,6 +2,7 @@ import requests import re import os +from llama_cpp import Llama class LLMMessenger(APIHandler): @@ -9,9 +10,21 @@ def API_endpoint(): return "http://knox-proxy01.srv.aau.dk/llama-api/llama" def send_request(request): - HEADERS = {"Access-Authorization": os.getenv("ACCESS_SECRET")} - response = requests.post(url=LLMMessenger.API_endpoint(), json=request, headers=HEADERS) - return response + # Put the location of the GGUF model that you've download from HuggingFace here + model_path = "relation_extraction\multilingual\llama-2-7b-chat.Q2_K.gguf" + + # Create a llama model + model = Llama(model_path=model_path, n_ctx=4096) + + prompt = f"""[INST] <> + {request["system_message"]} + <> + {request["user_message"]} [/INST]""" + + # Run the model + output = model(prompt, max_tokens=request["max_tokens"], echo=True) + + return output def process_message(response): print("Recieved response from Llama2...") diff --git a/requirements.txt b/requirements.txt index 9995c03..87322fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ #For python #---------- # Concept linking --r concept_linking/requirements.txt +# -r concept_linking/requirements.txt # Relation extraction -r relation_extraction/requirements.txt \ No newline at end of file diff --git a/requirements_docker.txt b/requirements_docker.txt index c1ff3d9..30009ab 100644 --- a/requirements_docker.txt +++ b/requirements_docker.txt @@ -1,7 +1,7 @@ #For docker #---------- # Concept linking --r /code/concept_linking/requirements.txt +# -r /code/concept_linking/requirements.txt # Relation extraction -r /code/relation_extraction/requirements.txt \ No newline at end of file diff --git a/server/server.py b/server/server.py index f08c331..478ae8e 100644 --- a/server/server.py +++ b/server/server.py @@ -2,7 +2,7 @@ import json import os from relation_extraction.relation_extractor import RelationExtractor -from concept_linking.main import entity_type_classification +# from concept_linking.main import entity_type_classification app = Flask(__name__) @@ -22,7 +22,7 @@ def do_triple_construction(): post_json = json.loads(post_data) RelationExtractor.begin_extraction(post_json) # Relation Extraction - entity_type_classification(post_json) # Concept Linking + # entity_type_classification(post_json) # Concept Linking message = "Post request was successfully processed. Relation Extraction and Concept Linking completed." return jsonify(message=message), 200