Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def __call__(
self,
inputs: dict[str, Any],
) -> dict[str, str]:
system_prompt = inputs['system_prompt']
if inputs.get('memories'):
system_prompt += "\n\nYou can remember things from other conversations with the user. If they are relevant, take into account the following memories: \n" + "\n\n".join(inputs['memories']) + "\n\n"
return {'output': self.runnable.invoke(
[(message['role'], message['content']) for message in [json.loads(message) for message in inputs['history']]] + [('human', inputs['input'])]
[('human', system_prompt)] + [(message['role'], message['content']) for message in [json.loads(message) for message in inputs['history']]] + [('human', inputs['input'])]
Comment thread
kyteinsky marked this conversation as resolved.
).content}
24 changes: 14 additions & 10 deletions lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from fastapi import FastAPI
from nc_py_api import AsyncNextcloudApp, NextcloudApp, NextcloudException
from nc_py_api.ex_app import LogLvl, persistent_storage, run_app, set_handlers
from nc_py_api.ex_app.providers.task_processing import TaskProcessingProvider, ShapeEnumValue
from nc_py_api.ex_app.providers.task_processing import ShapeDescriptor, ShapeType, TaskProcessingProvider, \
ShapeEnumValue

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', handlers=[logging.StreamHandler()])
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -157,15 +158,18 @@ async def enabled_handler(enabled: bool, nc: AsyncNextcloudApp) -> str:
name="Local Large language Model: " + model,
task_type=task,
expected_runtime=30,
input_shape_enum_values= {
"tone": [
ShapeEnumValue(name= "Friendlier", value= "friendlier"),
ShapeEnumValue(name= "More formal", value= "more formal"),
ShapeEnumValue(name= "Funnier", value= "funnier"),
ShapeEnumValue(name= "More casual", value= "more casual"),
ShapeEnumValue(name= "More urgent", value= "more urgent"),
],
} if task == "core:text2text:changetone" else {}
input_shape_enum_values= {
"tone": [
ShapeEnumValue(name= "Friendlier", value= "friendlier"),
ShapeEnumValue(name= "More formal", value= "more formal"),
ShapeEnumValue(name= "Funnier", value= "funnier"),
ShapeEnumValue(name= "More casual", value= "more casual"),
ShapeEnumValue(name= "More urgent", value= "more urgent"),
],
} if task == "core:text2text:changetone" else {},
optional_input_shape=[
ShapeDescriptor(name="memories", description="Memories to inject into the prompt", shape_type=ShapeType.LIST_OF_TEXTS)
] if task == "core:text2text:chat" else [],
)
await nc.providers.task_processing.register(provider)
log(nc, LogLvl.INFO, f"Registered {task_processor_name}")
Expand Down
Loading