CV_analyzer / main.py
Ahmed007's picture
Update main.py
1cb89c4 verified
raw
history blame
1.81 kB
from flask import Flask, request, jsonify
from langchain_community.llms import LlamaCpp
from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain.prompts import PromptTemplate
from langchain.schema.output_parser import StrOutputParser
# from langchain.llms import LlamaCpp
app = Flask(__name__)
n_gpu_layers = 0
n_batch = 1024
callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
llm = LlamaCpp(
model_path="Meta-Llama-3-8B-Instruct.Q5_K_M.gguf",
temperature=0.1,
n_gpu_layers=n_gpu_layers,
n_batch=n_batch,
callback_manager=callback_manager,
verbose=True,
n_ctx=2048
)
@app.route('/', methods=['POST'])
def get_skills():
cv_body = request.json.get('cv_body')
template = """[INST] <<SYS>>
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
<</SYS>>
{cv_body}[/INST]"""
prompt = PromptTemplate(template=template, input_variables=["text"])
chain = prompt | llm | StrOutputParser()
ans = chain.invoke({"question": "What are his best skills? write in points","cv_body":cv_body},
config={
# "callbacks": [ConsoleCallbackHandler()]
})
return jsonify({'skills': ans})
if __name__ == '__main__':
app.run()