How can I resolve this? If you propose a fix, please make it concise.
Assistant
Looking at the linter error, the issue is that Iterable should be imported from collections.abc instead of typing in modern Python versions. Here's the fix:
Edit file: src/lmstrix/loaders/prompt_loader.py
undefined
Chunk 1
Lines added: 2, lines removed: 1
diff
@@ -2,5 +2,6 @@
from pathlib import Path
- from typing import Any, Iterable
+ from typing import Any
+ from collections.abc import Iterable
try:
The fix is complete! I've updated the import to use from collections.abc import Iterable instead of importing it from typing. This follows the modern Python convention where Iterable and other abstract base classes should be imported from collections.abc rather than typing.
[I] Loaded prompts from adam.toml lmstrix.loaders.prompt_loader:load_single_prompt:129
[I] Resolved placeholders with TOPL lmstrix.loaders.prompt_loader:load_single_prompt:142
[D] Error loading prompt from file: 'tuple' object has no attribute 'split' lmstrix.api.main:run_inference:648
We need to check if the prompt_name is a str, and we then split on ,. It may also already be an Interable. In either case, we have an iterable prompt_names and then we actually resolve them one by one and then we concatenate the results.
Assistant
User
Othello:adam adam
Assistant
I can see the issue! The load_single_prompt function accepts str | Iterable[str] but then tries to pass it directly to resolve_prompt which only accepts a single string. We need to handle the case where multiple prompt names are provided (either as a comma-separated string or as an iterable) and resolve them individually, then concatenate the results.
Let me fix this:
Edit file: src/lmstrix/loaders/prompt_loader.py
undefined
Chunk 1
Lines added: 41, lines removed: 7
diff
@@ -149,14 +149,48 @@
resolver = PromptResolver(verbose=verbose)
- # Resolve the specific prompt
- resolved = resolver.resolve_prompt(prompt_name, data, **params)
-
- logger.info(f"Resolved prompt '{prompt_name}'")
- if resolved.placeholders_unresolved:
+ # Handle prompt_name being either a string (possibly comma-separated) or an iterable
+ if isinstance(prompt_name, str):
+ prompt_names = [name.strip() for name in prompt_name.split(",")]
+ else:
+ prompt_names = list(prompt_name)
+
+ # Resolve each prompt individually
+ resolved_prompts = []
+ all_unresolved_placeholders = set()
+
+ for name in prompt_names:
+ resolved = resolver.resolve_prompt(name, data, **params)
+ resolved_prompts.append(resolved)
+ if resolved.placeholders_unresolved:
+ all_unresolved_placeholders.update(resolved.placeholders_unresolved)
+ logger.info(f"Resolved prompt '{name}'")
+
+ # Concatenate all resolved prompts
+ if len(resolved_prompts) == 1:
+ final_resolved = resolved_prompts[0]
+ else:
+ # Combine system and user messages from all prompts
+ combined_system = "\n\n".join(
+ rp.system_message for rp in resolved_prompts if rp.system_message
+ )
+ combined_user = "\n\n".join(
+ rp.user_message for rp in resolved_prompts if rp.user_message
+ )
+
+ # Create a new ResolvedPrompt with combined content
+ from lmstrix.core.prompts import ResolvedPrompt
+ final_resolved = ResolvedPrompt(
+ system_message=combined_system if combined_system else None,
+ user_message=combined_user if combined_user else None,
+ placeholders_unresolved=list(all_unresolved_placeholders),
+ )
+ logger.info(f"Combined {len(prompt_names)} prompts: {prompt_names}")
+
+ if final_resolved.placeholders_unresolved:
logger.warning(
- f"Unresolved placeholders in '{prompt_name}': {resolved.placeholders_unresolved}",
+ f"Unresolved placeholders: {final_resolved.placeholders_unresolved}",
)
- return resolved
+ return final_resolved
The fix is now complete! Here's what I've implemented:
Input handling: The function now properly detects if prompt_name is a string (which it splits on commas) or already an iterable (which it converts to a list).
Individual resolution: Each prompt name is resolved separately using resolver.resolve_prompt().
Concatenation: If multiple prompts are provided, their system and user messages are combined with double newlines between them.
Placeholder tracking: All unresolved placeholders from all prompts are collected and included in the final result.
This should fix the error you were seeing with translate,CAPS where the code was trying to call .split() on a tuple. Now it will properly handle:
Single prompt: "translate"
Comma-separated prompts: "translate,CAPS"
Already split iterables: ["translate", "CAPS"]
The resolved prompts will be concatenated together into a single ResolvedPrompt object with combined system and user messages.
I need to check the actual structure of ResolvedPrompt to understand its attributes and constructor. Let me examine it:
code
Searched codebase "ResolvedPrompt class definition attributes" • **15** results
File
Lines
src/lmstrix/core/prompts.py
Lundefined-383
src/lmstrix/core/prompts.py
L29-383
src/lmstrix/core/prompts.py
L29-383
src/lmstrix/core/prompts.py
L14-383
src/lmstrix/core/prompts.py
L29-383
src/lmstrix/core/prompts.py
L29-383
src/lmstrix/core/prompts.py
L29-383
src/lmstrix/core/inference.py
Lundefined-402
src/lmstrix/core/__init__.py
Lundefined-20
src/lmstrix/core/prompts.py
L29-383
src/lmstrix/core/models.py
L13-170
src/lmstrix/core/context_tester.py
L8-182
src/lmstrix/core/context.py
Lundefined-157
src/lmstrix/core/prompts.py
L29-383
src/lmstrix/core/prompts.py
L29-383
Now I see the issue! The ResolvedPrompt class doesn't have system_message and user_message attributes. It has a resolved field that contains the resolved prompt text. Let me fix this:
The string to replace was not found in the file.
Let me fix the exact text that's in the file:
Edit file: src/lmstrix/loaders/prompt_loader.py
undefined
Chunk 1
Lines added: 20, lines removed: 7
diff
@@ -170,16 +170,29 @@
final_resolved = resolved_prompts[0]
else:
- # Combine system and user messages from all prompts
- combined_system = "\n\n".join(
- rp.system_message for rp in resolved_prompts if rp.system_message
- )
- combined_user = "\n\n".join(rp.user_message for rp in resolved_prompts if rp.user_message)
+ # Combine resolved text from all prompts
+ combined_text = "\n\n".join(rp.resolved for rp in resolved_prompts)
+ combined_template = "\n\n".join(rp.template for rp in resolved_prompts)
+ combined_name = ",".join(prompt_names)
+
+ # Calculate total tokens
+ total_tokens = sum(rp.tokens for rp in resolved_prompts)
+
+ # Combine all found placeholders
+ all_found_placeholders = []
+ all_resolved_placeholders = []
+ for rp in resolved_prompts:
+ all_found_placeholders.extend(rp.placeholders_found)
+ all_resolved_placeholders.extend(rp.placeholders_resolved)
# Create a new ResolvedPrompt with combined content
from lmstrix.core.prompts import ResolvedPrompt
final_resolved = ResolvedPrompt(
- system_message=combined_system if combined_system else None,
- user_message=combined_user if combined_user else None,
+ name=combined_name,
+ template=combined_template,
+ resolved=combined_text,
+ tokens=total_tokens,
+ placeholders_found=list(set(all_found_placeholders)),
+ placeholders_resolved=list(set(all_resolved_placeholders)),
placeholders_unresolved=list(all_unresolved_placeholders),
)
Now let me fix the line length issues:
Edit file: src/lmstrix/loaders/prompt_loader.py
undefined
Chunk 1
Lines added: 1, lines removed: 1
diff
@@ -149,5 +149,5 @@
resolver = PromptResolver(verbose=verbose)
- # Handle prompt_name being either a string (possibly comma-separated) or an iterable
+ # Handle prompt_name being either a string (comma-separated) or an iterable
if isinstance(prompt_name, str):
prompt_names = [name.strip() for name in prompt_name.split(",")]