Implemented vibecoding functionality for llmchat

This commit is contained in:
Luxferre
2025-12-26 14:10:10 +02:00
parent ab5c859cee
commit e66ebd50a9
4 changed files with 138 additions and 16 deletions
+34
View File
@@ -111,6 +111,40 @@ class LLMChat:
if len(self.messages) > 0: self.messages.pop()
return (False, f"Error: {e}")
def get_last_response(self):
"""
Get the most recent assistant's response.
"""
idx = len(self.messages) - 1
while idx > 0 and self.messages[idx]['role'] != 'assistant':
idx -= 1
if idx == 0:
return (False, 'No assistant messages detected')
else:
return (True, self.messages[idx]['content'])
def export(self):
"""
Export the entire conversation as a string.
"""
out = ''
for msg in self.messages:
out += f'{msg['role']}: {msg['content'].strip()}\n'
return (True, out.strip())
def add_file(self, fname):
"""
Add a (text) file to the context.
"""
try:
with open(fname, 'r') as f:
text = f.read()
prompt = f'Contents of the file {fname}:\n\n{text}'
self.messages.append({'role': 'user', 'content': prompt})
return (True, 'File content added')
except:
return (False, 'Could not read the file')
def list_models(self):
"""
Lists available models for the active provider.