NyashaK commited on
Commit
a282318
·
1 Parent(s): 66ff523

adding logging

Browse files
.chainlit/config.toml CHANGED
@@ -67,7 +67,7 @@ edit_message = true
67
  # Name of the assistant.
68
  name = "Ronald AI"
69
 
70
- logo = "/public/logo_1.png"
71
 
72
  default_theme = "dark"
73
 
 
67
  # Name of the assistant.
68
  name = "Ronald AI"
69
 
70
+ logo = "/public/logo_dark.png"
71
 
72
  default_theme = "dark"
73
 
.gitignore CHANGED
@@ -1 +1,3 @@
1
- .idea
 
 
 
1
+ .idea
2
+
3
+ .env
__pycache__/app.cpython-310.pyc ADDED
Binary file (5.09 kB). View file
 
app.py CHANGED
@@ -3,7 +3,10 @@ from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageCon
3
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
4
  from llama_index.llms.openrouter import OpenRouter
5
  import os
 
6
 
 
 
7
 
8
  @cl.set_starters
9
  async def set_starters():
@@ -16,7 +19,7 @@ async def set_starters():
16
 
17
  cl.Starter(
18
  label="Project highlights",
19
- message="List Ronald’s most impactful projects in bullet points. For each, include the project name, tools used, the problem it addressed, and the outcome. Format the response in markdown.",
20
  icon="https://cdn-icons-png.flaticon.com/512/979/979585.png",
21
  ),
22
 
@@ -49,6 +52,11 @@ async def set_starters():
49
 
50
  @cl.on_chat_start
51
  async def start():
 
 
 
 
 
52
  cl.user_session.set("llm", OpenRouter(
53
  model="opengvlab/internvl3-14b:free",
54
  temperature=0.1,
@@ -60,6 +68,7 @@ async def start():
60
  model_name="BAAI/bge-small-en-v1.5"
61
  )
62
  Settings.context_window = 4096
 
63
 
64
  try:
65
  storage_context = StorageContext.from_defaults(persist_dir="storage")
@@ -99,12 +108,24 @@ async def start():
99
 
100
  @cl.on_message
101
  async def main(message: cl.Message):
102
- query_engine = cl.user_session.get("query_engine")
 
 
 
 
 
 
 
 
 
103
 
104
- msg = cl.Message(content="", author="Assistant")
105
- res = await cl.make_async(query_engine.query)(message.content)
106
 
107
- for token in res.response_gen:
108
- await msg.stream_token(token)
109
 
110
- await msg.send()
 
 
 
 
3
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
4
  from llama_index.llms.openrouter import OpenRouter
5
  import os
6
+ from loguru import logger
7
 
8
+ logger.add("logs/ronald_ai.log", rotation="1 MB", retention="7 days", level="INFO")
9
+ logger.info("Starting Ronald AI App")
10
 
11
  @cl.set_starters
12
  async def set_starters():
 
19
 
20
  cl.Starter(
21
  label="Project highlights",
22
+ message="List Ronald’s most impactful projects in bullet points. For each, include the project name, tools used, the problem it addressed, and the outcome. Use clear paragraphs or bullet points for readability.",
23
  icon="https://cdn-icons-png.flaticon.com/512/979/979585.png",
24
  ),
25
 
 
52
 
53
  @cl.on_chat_start
54
  async def start():
55
+ api_key = os.getenv("API_KEY")
56
+ if not api_key:
57
+ logger.warning("API_KEY not found in environment variables.")
58
+ else:
59
+ logger.info("API_KEY loaded.")
60
  cl.user_session.set("llm", OpenRouter(
61
  model="opengvlab/internvl3-14b:free",
62
  temperature=0.1,
 
68
  model_name="BAAI/bge-small-en-v1.5"
69
  )
70
  Settings.context_window = 4096
71
+ logger.info("LLM and embedding models initialized.")
72
 
73
  try:
74
  storage_context = StorageContext.from_defaults(persist_dir="storage")
 
108
 
109
  @cl.on_message
110
  async def main(message: cl.Message):
111
+ try:
112
+ query_engine = cl.user_session.get("query_engine")
113
+ if query_engine is None:
114
+ raise ValueError("Query engine not found in session.")
115
+
116
+ msg = cl.Message(content="", author="Assistant")
117
+ logger.info(f"Received message: {message.content}")
118
+
119
+ res = await cl.make_async(query_engine.query)(message.content)
120
+ logger.info("LLM response received.")
121
 
122
+ for token in res.response_gen:
123
+ await msg.stream_token(token)
124
 
125
+ await msg.send()
126
+ logger.info("Message sent back to client.")
127
 
128
+ except Exception as e:
129
+ error_msg = f"An error occurred: {str(e)}"
130
+ await cl.Message(content=error_msg, author="Assistant").send()
131
+ logger.error(error_msg)
logs/ronald_ai.log ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2025-06-12 12:30:47.741 | INFO | app.py:<module>:9 - Starting Ronald AI App
2
+ 2025-06-12 12:30:49.701 | INFO | app.py:start:59 - API_KEY loaded.
3
+ 2025-06-12 12:30:52.185 | INFO | app.py:start:71 - LLM and embedding models initialized.
4
+ 2025-06-12 12:30:52.214 | INFO | app.py:start:59 - API_KEY loaded.
5
+ 2025-06-12 12:30:53.003 | INFO | app.py:start:71 - LLM and embedding models initialized.
6
+ 2025-06-12 12:30:53.062 | INFO | app.py:start:59 - API_KEY loaded.
7
+ 2025-06-12 12:30:53.842 | INFO | app.py:start:71 - LLM and embedding models initialized.
8
+ 2025-06-12 12:31:00.857 | INFO | app.py:main:117 - Received message: List Ronald’s most impactful projects in bullet points. For each, include the project name, tools used, the problem it addressed, and the outcome. Use clear paragraphs or bullet points for readability.
9
+ 2025-06-12 12:31:01.419 | INFO | app.py:main:120 - LLM response received.
10
+ 2025-06-12 12:31:03.741 | INFO | app.py:main:126 - Message sent back to client.
11
+ 2025-06-12 12:31:36.349 | INFO | app.py:main:117 - Received message: provide more
12
+ 2025-06-12 12:31:36.424 | INFO | app.py:main:120 - LLM response received.
13
+ 2025-06-12 12:31:40.804 | INFO | app.py:main:126 - Message sent back to client.
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  chainlit>=0.7.700
2
  llama-index-core~=0.12.41
3
  llama-index-embeddings-huggingface~=0.5.4
4
- llama-index-llms-openrouter~=0.3.2
 
 
1
  chainlit>=0.7.700
2
  llama-index-core~=0.12.41
3
  llama-index-embeddings-huggingface~=0.5.4
4
+ llama-index-llms-openrouter~=0.3.2
5
+ loguru