Spaces:
Runtime error
Runtime error
File size: 1,806 Bytes
008045b 4f608eb 008045b fc6816d 008045b 8f2a0d5 008045b 8f2a0d5 008045b 8f2a0d5 008045b 8f2a0d5 1cb89c4 8f2a0d5 008045b 8f2a0d5 fc6816d 008045b 55f0661 008045b b2b346c 008045b b2b346c fc6816d 008045b fc6816d 008045b b2b346c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
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()
|