Views
No views yet
! CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python 1from transformers import AutoTokenizer
2from llama_cpp import Llama
3tokenizer = AutoTokenizer.from_pretrained('meta-llama/Meta-Llama-3-8B')
4example = [{'content': 'You are a financial expert and you can answer any questions related to finance. You will be given a context and a question. Understand the given context and\n try to answer. Users will ask you questions in English and you will generate answer based on the provided CONTEXT.\n CONTEXT:\n D. in Forced Migration from the University of the Witwatersrand (Wits) in Johannesburg, South Africa; A postgraduate diploma in Folklore & Cultural Studies at Indira Gandhi National Open University (IGNOU) in New Delhi, India; A Masters of International Affairs at Columbia University; A BA from Barnard College at Columbia University\n', 'role': 'system'}, {'content': ' In which universities did the individual obtain their academic qualifications?\n', 'role': 'user'}, {'content': ' University of the Witwatersrand (Wits) in Johannesburg, South Africa; Indira Gandhi National Open University (IGNOU) in New Delhi, India; Columbia University; Barnard College at Columbia University.', 'role': 'assistant'}]
5prompt = tokenizer.apply_chat_template(example[:2], tokenize=False, add_generation_prompt=True)
6
7llm = Llama.from_pretrained(
8 repo_id="anamikac2708/Llama3-8b-finetuned-investopedia-q4_k_m_gguf",
9 filename="*Q4_K_M.gguf",
10 verbose=False
11)
12
13output = llm(
14 prompt,
15 max_tokens=256, # Generate up to 256 tokens
16 stop=["<|im_end|>"],
17 echo=True, # Whether to echo the prompt
18)
19
20print(output['choices'][0]['text'])