Update app.py
Browse files
app.py
CHANGED
|
@@ -70,7 +70,15 @@ agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=False)
|
|
| 70 |
|
| 71 |
client = InferenceClient(token=os.environ["HUGGINGFACEHUB_API_TOKEN"])
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
def respond(message, history: list[dict]):
|
|
|
|
|
|
|
| 74 |
|
| 75 |
agent_output = agent_executor.invoke({
|
| 76 |
"query": message,
|
|
@@ -93,6 +101,7 @@ def respond(message, history: list[dict]):
|
|
| 93 |
assistant_text = raw
|
| 94 |
|
| 95 |
response = {"role": "assistant", "content": assistant_text}
|
|
|
|
| 96 |
|
| 97 |
yield response
|
| 98 |
|
|
|
|
| 70 |
|
| 71 |
client = InferenceClient(token=os.environ["HUGGINGFACEHUB_API_TOKEN"])
|
| 72 |
|
| 73 |
+
LOG_PATH = "/mnt/data/chat_log.txt"
|
| 74 |
+
|
| 75 |
+
def log_message(role: str, text: str):
|
| 76 |
+
with open(LOG_PATH, "a", encoding="utf-8") as f:
|
| 77 |
+
f.write(f"{role.upper()}: {text}\n\n")
|
| 78 |
+
|
| 79 |
def respond(message, history: list[dict]):
|
| 80 |
+
|
| 81 |
+
log_message("user", message)
|
| 82 |
|
| 83 |
agent_output = agent_executor.invoke({
|
| 84 |
"query": message,
|
|
|
|
| 101 |
assistant_text = raw
|
| 102 |
|
| 103 |
response = {"role": "assistant", "content": assistant_text}
|
| 104 |
+
log_message("assistant", assistant_text)
|
| 105 |
|
| 106 |
yield response
|
| 107 |
|