llama_model.py 602 B

123456789101112131415
  1. from llama_cpp import Llama
  2. class LLAMAModel:
  3. def __init__(self, path):
  4. self.llm = Llama(model_path=path, chat_format="llama-2", n_ctx=1524)
  5. def make_request(self, conversation, add_image=None, logit_bias=None, max_tokens=None, skip_cache=False):
  6. conversation = [{"role": "user" if i%2 == 0 else "assistant", "content": content} for i,content in enumerate(conversation)]
  7. print("Start chat")
  8. out = self.llm.create_chat_completion(
  9. messages = conversation
  10. )
  11. print("End chat")
  12. return out['choices'][0]['message']['content']