thanthamky commited on
Commit
1f34084
·
verified ·
1 Parent(s): 182304c

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +5 -5
src/app.py CHANGED
@@ -1,19 +1,19 @@
1
  import os
2
  import chainlit as cl
3
  from langchain_community.llms import Ollama
4
- from langchain_core.callbacks import CallbackManager, StreamingStdOutCallbackHandler
5
 
6
  # Get the Ollama URL from the environment, defaulting to localhost if not found
7
  OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL", "https://thanthamky-ollama-api-analytic.hf.space")
8
  # Define the model you want to use (make sure you pull it first!)
9
  MODEL_NAME = "qwen3:0.6b"
 
 
10
  @cl.on_chat_start
11
  async def on_chat_start():
12
- # Initialize the Ollama LLM
13
  llm = Ollama(
14
  base_url=OLLAMA_BASE_URL,
15
- model=MODEL_NAME,
16
- callback_manager=CallbackManager([StreamingStdOutCallbackHandler()])
17
  )
18
 
19
  # Store the LLM in the user session
@@ -32,7 +32,7 @@ async def on_message(message: cl.Message):
32
  msg = cl.Message(content="")
33
  await msg.send()
34
 
35
- # Stream the response from Ollama
36
  async for chunk in llm.astream(message.content):
37
  if chunk:
38
  await msg.stream_token(chunk)
 
1
  import os
2
  import chainlit as cl
3
  from langchain_community.llms import Ollama
 
4
 
5
  # Get the Ollama URL from the environment, defaulting to localhost if not found
6
  OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL", "https://thanthamky-ollama-api-analytic.hf.space")
7
  # Define the model you want to use (make sure you pull it first!)
8
  MODEL_NAME = "qwen3:0.6b"
9
+
10
+
11
  @cl.on_chat_start
12
  async def on_chat_start():
13
+ # Initialize the Ollama LLM without the forbidden callback_manager
14
  llm = Ollama(
15
  base_url=OLLAMA_BASE_URL,
16
+ model=MODEL_NAME
 
17
  )
18
 
19
  # Store the LLM in the user session
 
32
  msg = cl.Message(content="")
33
  await msg.send()
34
 
35
+ # Stream the response natively to the Chainlit UI
36
  async for chunk in llm.astream(message.content):
37
  if chunk:
38
  await msg.stream_token(chunk)