Use the content service to upload the bytes with proper metadata. The skip_ingestion=True parameter prevents automatic content processing, which is useful for simple file sharing:
reference=ContentReference(id=uploaded_content.id,sequence_number=1,message_id=event.payload.assistant_message.id,name="document.txt",source=event.payload.name,source_id=event.payload.chat_id,url=f"unique://content/{uploaded_content.id}",)chat_service.modify_assistant_message(content="Please find the translated document below in the references.",message_id=assistant_message.id,references=[reference],)
# %%frompathlibimportPathfromunique_toolkitimport(ChatService,KnowledgeBaseService,)fromunique_toolkit.app.dev_utilimportget_event_generatorfromunique_toolkit.app.schemasimportChatEventfromunique_toolkit.app.unique_settingsimportUniqueSettingsfromunique_toolkit.content.schemasimport(ContentReference,)settings=UniqueSettings.from_env_auto_with_sdk_init()foreventinget_event_generator(unique_settings=settings,event_type=ChatEvent):settings.update_from_event(event)# Initialize services from eventchat_service=ChatService(event)kb_service=KnowledgeBaseService.from_event(event)fromdotenvimportdotenv_valuesdemo_env_vars=dotenv_values(Path(__file__).parent/"demo.env")scope_id=demo_env_vars.get("UNIQUE_SCOPE_ID")or"unknown"assistant_message=chat_service.create_assistant_message(content="Hi there, the agent has started to create your document.",)content_bytes=b"Hello, world!"uploaded_content=kb_service.upload_content_from_bytes(content=content_bytes,content_name="document.txt",mime_type="text/plain",scope_id=scope_id,skip_ingestion=True,)reference=ContentReference(id=uploaded_content.id,sequence_number=1,message_id=event.payload.assistant_message.id,name="document.txt",source=event.payload.name,source_id=event.payload.chat_id,url=f"unique://content/{uploaded_content.id}",)chat_service.modify_assistant_message(content="Please find the translated document below in the references.",message_id=assistant_message.id,references=[reference],)chat_service.free_user_input()