Skip to content

Commit

Permalink
Fix warning for use_memory, update default title prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinfrlch committed Feb 26, 2025
1 parent 2f4d0d6 commit 5d5b0c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion custom_components/llmvision/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

# Defaults
DEFAULT_SYSTEM_PROMPT = "Your task is to analyze a series of images and provide a concise event description based on user instructions. Focus on identifying and describing the actions of people and dynamic objects (e.g., vehicles) rather than static background details. When multiple images are provided, track and summarize movements or changes over time (e.g., 'A person walks to the front door' or 'A car pulls out of the driveway'). Keep responses brief, objective, and aligned with the user's prompt. Avoid speculation and prioritize observable activity."
DEFAULT_TITLE_PROMPT = "Provide a concise event title based on the description provided. The title should summarize the key actions or events captured in the images and be suitable for use in a notification or alert. Keep the title clear, descriptive, and relevant to the content of the images. Avoid unnecessary details or subjective interpretations. The title should be in the format: '<Object> seen at <location>. For example: 'Person seen at front door'."
DEFAULT_TITLE_PROMPT = "Provide a short and concise event title based on the description provided. The title should summarize the key actions or events captured in the images and be suitable for use in a notification or alert. Keep the title clear, relevant to the content of the images and shorter than 6 words. Avoid unnecessary details or subjective interpretations. The title should be in the format: '<Object> seen at <location>. For example: 'Person seen at front door'."
DATA_EXTRACTION_PROMPT = "You are an advanced image analysis assistant specializing in extracting precise data from images captured by a home security camera. Your task is to analyze one or more images and extract specific information as requested by the user (e.g., the number of cars or a license plate). Provide only the requested information in your response, with no additional text or commentary. Your response must be a {data_format} Ensure the extracted data is accurate and reflects the content of the images."


Expand Down
35 changes: 18 additions & 17 deletions custom_components/llmvision/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def __init__(self, hass, strings=[], paths=[], system_prompt=None):
self.entry = self._find_memory_entry()
if self.entry is None:

self._system_prompt = system_prompt if system_prompt else self.entry.data.get(
CONF_SYSTEM_PROMPT, DEFAULT_SYSTEM_PROMPT)
self._system_prompt = system_prompt if system_prompt else DEFAULT_SYSTEM_PROMPT
self._title_prompt = DEFAULT_TITLE_PROMPT
self.memory_strings = strings
self.memory_paths = paths
Expand All @@ -47,8 +46,9 @@ def _get_memory_images(self, memory_type="OpenAI") -> list:
memory_prompt = "The following images along with descriptions serve as reference. They are not to be mentioned in the response."

if memory_type == "OpenAI":
content.append(
{"type": "text", "text": memory_prompt})
if self.memory_images:
content.append(
{"type": "text", "text": memory_prompt})
for image in self.memory_images:
tag = self.memory_strings[self.memory_images.index(image)]

Expand All @@ -58,8 +58,9 @@ def _get_memory_images(self, memory_type="OpenAI") -> list:
"url": f"data:image/jpeg;base64,{image}"}})

elif memory_type == "OpenAI-legacy":
content.append(
{"type": "text", "text": memory_prompt})
if self.memory_images:
content.append(
{"type": "text", "text": memory_prompt})
for image in self.memory_images:
tag = self.memory_strings[self.memory_images.index(image)]

Expand All @@ -69,17 +70,19 @@ def _get_memory_images(self, memory_type="OpenAI") -> list:
"url": f"data:image/jpeg;base64,{image}"}})

elif memory_type == "Ollama":
content.append(
{"role": "user", "content": memory_prompt})
if self.memory_images:
content.append(
{"role": "user", "content": memory_prompt})
for image in self.memory_images:
tag = self.memory_strings[self.memory_images.index(image)]

content.append({"role": "user",
"content": tag + ":", "images": [image]})

elif memory_type == "Anthropic":
content.append(
{"type": "text", "text": memory_prompt})
if self.memory_images:
content.append(
{"type": "text", "text": memory_prompt})
for image in self.memory_images:
tag = self.memory_strings[self.memory_images.index(image)]

Expand All @@ -88,16 +91,18 @@ def _get_memory_images(self, memory_type="OpenAI") -> list:
content.append({"type": "image", "source": {
"type": "base64", "media_type": "image/jpeg", "data": f"{image}"}})
elif memory_type == "Google":
content.append({"text": memory_prompt})
if self.memory_images:
content.append({"text": memory_prompt})
for image in self.memory_images:
tag = self.memory_strings[self.memory_images.index(image)]

content.append({"text": tag + ":"})
content.append(
{"inline_data": {"mime_type": "image/jpeg", "data": image}})
elif memory_type == "AWS":
content.append(
{"text": memory_prompt})
if self.memory_images:
content.append(
{"text": memory_prompt})
for image in self.memory_images:
tag = self.memory_strings[self.memory_images.index(image)]

Expand Down Expand Up @@ -126,10 +131,6 @@ def _find_memory_entry(self):
memory_entry = entry
break

if memory_entry is None:
_LOGGER.warning("Memory is not set up!")
return None

return memory_entry

async def _encode_images(self, image_paths):
Expand Down

0 comments on commit 5d5b0c5

Please sign in to comment.