Commit ·
a6407c2
1
Parent(s): e0964c2
Files are working!
Browse filesFiles changed (3)
- main.py+21-9
- requirements.txt+1-1
- src/manager/manager.py+14-5
24 unmodified lines25262728293031323334353637383932 unmodified lines7273747576777824 unmodified linesdef run_model(message, history):history.append({"role": "user","content": message,})yield "", historyfor messages in model_manager.run(history):for message in messages:if message.get("role") == "summary":print(f"Summary: {message.get('content', '')}")yield "", messages32 unmodified linesrender_markdown=True,placeholder="Type your message here...",)gr.ChatInterface(fn=run_model, type="messages", chatbot=chatbot,additional_outputs=[chatbot], save_history=True)if __name__ == "__main__":demo.launch()24 unmodified lines2526272829303132333435363738394041424344454632 unmodified lines79808182838485868788899024 unmodified linesdef run_model(message, history):print(f"User: {message}")print(f"History: {history}")if 'text' in message:history.append({"role": "user","content": message['text']})if 'files' in message:for file in message['files']:history.append({"role": "user","content": (file,)})print(f"History: {history}")yield "", historyfor messages in model_manager.run(history):yield "", messages32 unmodified linesrender_markdown=True,placeholder="Type your message here...",)gr.ChatInterface(fn=run_model,type="messages",chatbot=chatbot,additional_outputs=[chatbot],save_history=True,editable=True,multimodal=True,)if __name__ == "__main__":demo.launch()
50 unmodified lines5152535455565750 unmodified linespyarrow==20.0.0pyasn1==0.6.1pyasn1_modules==0.4.2pydantic==2.11.2pydantic_core==2.33.1pydub==0.25.1Pygments==2.19.150 unmodified lines5152535455565750 unmodified linespyarrow==20.0.0pyasn1==0.6.1pyasn1_modules==0.4.2pydantic==2.10.6pydantic_core==2.33.1pydub==0.25.1Pygments==2.19.1
10 unmodified lines111213141516117 unmodified lines1341351361371381391401411421439 unmodified lines15315415515615715847 unmodified lines20620720820921021121221321421521621721821922022122227 unmodified lines25025125225325410 unmodified linesfrom sentence_transformers import SentenceTransformerimport torchfrom src.tools.default_tools.memory_manager import MemoryManagerlogger = logging.getLogger(__name__)handler = logging.StreamHandler(sys.stdout)117 unmodified lines# Skip thinking messages (messages with metadata)if not (message.get("role") == "assistant" and "metadata" in message):role = "model"parts = [types.Part.from_text(text=message.get("content", ""))]match message.get("role"):case "user":role = "user"case "memories":role = "user"parts = [types.Part.from_text(text="Relevant memories: "+message.get("content", ""))]9 unmodified linescontinuecase _:role = "model"formatted_history.append(types.Content(role=role,parts=parts47 unmodified linesdef invoke_manager(self, messages):chat_history = self.format_chat_history(messages)logger.debug(f"Chat history: {chat_history}")try:response = suppress_output(self.generate_response)(chat_history)except Exception as e:messages.append({"role": "assistant","content": f"Error generating response: {e}"})logger.error(f"Error generating response", e)yield messagesreturnlogger.debug(f"Response: {response}")if (not response.text and not response.function_calls):27 unmodified linesor (call.get("role") == "assistant" and call.get("metadata", {}).get("status") == "done")):messages.append(call)yield from self.invoke_manager(messages)returnyield messages10 unmodified lines11121314151617117 unmodified lines1351361371381391401411421431441451461471481491509 unmodified lines16016116216316416516647 unmodified lines21421521621721821922022122222322422522622722822923023123227 unmodified lines26026126226310 unmodified linesfrom sentence_transformers import SentenceTransformerimport torchfrom src.tools.default_tools.memory_manager import MemoryManagerfrom pathlib import Pathlogger = logging.getLogger(__name__)handler = logging.StreamHandler(sys.stdout)117 unmodified lines# Skip thinking messages (messages with metadata)if not (message.get("role") == "assistant" and "metadata" in message):role = "model"match message.get("role"):case "user":role = "user"if isinstance(message["content"], tuple):path = message["content"][0]file = self.client.files.upload(file=path)formatted_history.append(file)continueelse:parts = [types.Part.from_text(text=message.get("content", ""))]case "memories":role = "user"parts = [types.Part.from_text(text="Relevant memories: "+message.get("content", ""))]9 unmodified linescontinuecase _:role = "model"parts = [types.Part.from_text(text=message.get("content", ""))]formatted_history.append(types.Content(role=role,parts=parts47 unmodified linesdef invoke_manager(self, messages):chat_history = self.format_chat_history(messages)print(f"Chat history: {chat_history}")logger.debug(f"Chat history: {chat_history}")try:response = suppress_output(self.generate_response)(chat_history)except Exception as e:messages.append({"role": "assistant","content": f"Error generating response: {str(e)}","metadata": {"title": "Error generating response"}})logger.error(f"Error generating response{e}")yield messagesreturn messageslogger.debug(f"Response: {response}")if (not response.text and not response.function_calls):27 unmodified linesor (call.get("role") == "assistant" and call.get("metadata", {}).get("status") == "done")):messages.append(call)yield from self.invoke_manager(messages)yield messages
main.py+21-9
requirements.txt+1-1
src/manager/manager.py+14-5