Skip to content

Commit

Permalink
rm clean_messages, logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kushal-10 committed Apr 26, 2024
1 parent 510980f commit 50207c9
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions backends/huggingface_multimodal_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,17 @@ def generate_response(self, messages: List[Dict],
:return: the continuation
"""

# log current given messages list:
if log_messages:
logger.info(f"Raw messages passed: {messages}")

# Cleanup double user messages
cleaned_messages = clean_messages(messages)

# Get prompt by applying jinja template
template_str = self.template
template = Template(template_str)
prompt_text = template.render(messages=cleaned_messages)
prompt_text = template.render(messages=messages)

# Get a list of images that will be passed to the Processor
images = get_images(prompt_text, messages, self.image_placeholder)
if self.padding:
images = pad_images(images)

prompt = {"inputs": prompt_text, "max_new_tokens": self.get_max_tokens(), "temprature": self.get_temperature()}
prompt = {"inputs": prompt_text, "max_new_tokens": self.get_max_tokens(), "temeprature": self.get_temperature()}
# Generate the output
inputs = self.processor(prompt_text, images=images, return_tensors="pt").to(self.device)
model_output = self.multimodal_model.generate(**inputs, max_new_tokens=self.get_max_tokens())
Expand All @@ -200,7 +193,6 @@ def generate_response(self, messages: List[Dict],
# Store generated text
response = {'response': generated_text}

for text in generated_text:
response_text = text.split(self.assistant_tag)[-1] # Get the last assistant response
response_text = generated_text[0].split(self.assistant_tag)[-1] # Get the last assistant response

return prompt, response, response_text

0 comments on commit 50207c9

Please sign in to comment.