MH0386 commited on
Commit
9b3b414
·
verified ·
1 Parent(s): 88c05ed

Upload folder using huggingface_hub

Browse files
src/chattr/__init__.py CHANGED
@@ -17,7 +17,9 @@ MCP_VOICE_GENERATOR: str = getenv(
17
  MCP_VIDEO_GENERATOR: str = getenv(
18
  key="MCP_VIDEO_GENERATOR", default="http://localhost:8002/"
19
  )
20
- VECTOR_DATABASE_NAME: str = getenv(key="VECTOR_DATABASE_NAME", default="chattr")
 
 
21
  DOCKER_MODEL_RUNNER_URL: str = getenv(
22
  key="DOCKER_MODEL_RUNNER_URL", default="http://127.0.0.1:12434/engines/v1"
23
  )
@@ -25,7 +27,9 @@ DOCKER_MODEL_RUNNER_MODEL_NAME: str = getenv(
25
  key="DOCKER_MODEL_RUNNER_MODEL_NAME",
26
  default="ai/qwen3:0.6B-Q4_0",
27
  )
28
- GROQ_URL: str = getenv(key="MODEL_URL", default="https://api.groq.com/openai/v1")
 
 
29
  GROQ_MODEL_NAME: str = getenv(key="GROQ_MODEL_NAME", default="llama3-70b-8192")
30
 
31
  BASE_DIR: Path = Path.cwd()
@@ -56,7 +60,9 @@ MODEL_NAME: str = (
56
  else GROQ_MODEL_NAME
57
  )
58
  MODEL_API_KEY: str = (
59
- "not-needed" if MODEL_URL == DOCKER_MODEL_RUNNER_URL else getenv("GROQ_API_KEY")
 
 
60
  )
61
  MODEL_TEMPERATURE: float = float(getenv(key="MODEL_TEMPERATURE", default=0.0))
62
 
 
17
  MCP_VIDEO_GENERATOR: str = getenv(
18
  key="MCP_VIDEO_GENERATOR", default="http://localhost:8002/"
19
  )
20
+ VECTOR_DATABASE_NAME: str = getenv(
21
+ key="VECTOR_DATABASE_NAME", default="chattr"
22
+ )
23
  DOCKER_MODEL_RUNNER_URL: str = getenv(
24
  key="DOCKER_MODEL_RUNNER_URL", default="http://127.0.0.1:12434/engines/v1"
25
  )
 
27
  key="DOCKER_MODEL_RUNNER_MODEL_NAME",
28
  default="ai/qwen3:0.6B-Q4_0",
29
  )
30
+ GROQ_URL: str = getenv(
31
+ key="MODEL_URL", default="https://api.groq.com/openai/v1"
32
+ )
33
  GROQ_MODEL_NAME: str = getenv(key="GROQ_MODEL_NAME", default="llama3-70b-8192")
34
 
35
  BASE_DIR: Path = Path.cwd()
 
60
  else GROQ_MODEL_NAME
61
  )
62
  MODEL_API_KEY: str = (
63
+ "not-needed"
64
+ if MODEL_URL == DOCKER_MODEL_RUNNER_URL
65
+ else getenv("GROQ_API_KEY")
66
  )
67
  MODEL_TEMPERATURE: float = float(getenv(key="MODEL_TEMPERATURE", default=0.0))
68
 
src/chattr/graph.py CHANGED
@@ -46,7 +46,9 @@ async def create_graph() -> CompiledStateGraph:
46
  )
47
  _model = _model.bind_tools(_tools, parallel_tool_calls=False)
48
  except Exception as e:
49
- raise RuntimeError(f"Failed to initialize ChatOpenAI model: {e}") from e
 
 
50
 
51
  def call_model(state: MessagesState) -> MessagesState:
52
  """
@@ -58,7 +60,9 @@ async def create_graph() -> CompiledStateGraph:
58
  Returns:
59
  MessagesState: A new state with the model's response appended to the messages.
60
  """
61
- return {"messages": [_model.invoke([SYSTEM_MESSAGE] + state["messages"])]}
 
 
62
 
63
  _builder: StateGraph = StateGraph(MessagesState)
64
  _builder.add_node("agent", call_model)
@@ -74,7 +78,9 @@ def draw_graph(graph: CompiledStateGraph) -> None:
74
  """
75
  Render the compiled state graph as a Mermaid PNG image and save it to the assets directory.
76
  """
77
- graph.get_graph().draw_mermaid_png(output_file_path=ASSETS_DIR / "graph.png")
 
 
78
 
79
 
80
  if __name__ == "__main__":
 
46
  )
47
  _model = _model.bind_tools(_tools, parallel_tool_calls=False)
48
  except Exception as e:
49
+ raise RuntimeError(
50
+ f"Failed to initialize ChatOpenAI model: {e}"
51
+ ) from e
52
 
53
  def call_model(state: MessagesState) -> MessagesState:
54
  """
 
60
  Returns:
61
  MessagesState: A new state with the model's response appended to the messages.
62
  """
63
+ return {
64
+ "messages": [_model.invoke([SYSTEM_MESSAGE] + state["messages"])]
65
+ }
66
 
67
  _builder: StateGraph = StateGraph(MessagesState)
68
  _builder.add_node("agent", call_model)
 
78
  """
79
  Render the compiled state graph as a Mermaid PNG image and save it to the assets directory.
80
  """
81
+ graph.get_graph().draw_mermaid_png(
82
+ output_file_path=ASSETS_DIR / "graph.png"
83
+ )
84
 
85
 
86
  if __name__ == "__main__":
src/chattr/gui.py CHANGED
@@ -2,7 +2,9 @@ import gradio
2
  from gradio import Blocks, Button, Chatbot, ChatMessage, Row, Textbox
3
 
4
 
5
- def generate_response(history: list[ChatMessage], thread_id: str) -> list[ChatMessage]:
 
 
6
  """
7
  Appends an assistant message about a quarterly sales plot to the chat history for the specified thread ID.
8
 
@@ -33,7 +35,9 @@ def app_block() -> Blocks:
33
 
34
  history = [
35
  ChatMessage(role="assistant", content="How can I help you?"),
36
- ChatMessage(role="user", content="Can you make me a plot of quarterly sales?"),
 
 
37
  ChatMessage(
38
  role="assistant",
39
  content="I am happy to provide you that report and plot.",
@@ -41,13 +45,17 @@ def app_block() -> Blocks:
41
  ]
42
  with Blocks() as app:
43
  with Row():
44
- thread_id: Textbox = Textbox(label="Thread ID", info="Enter Thread ID")
 
 
45
 
46
  chatbot: Chatbot = Chatbot(history, type="messages")
47
 
48
  with Row():
49
  generate_btn: Button = Button(value="Generate", variant="primary")
50
  stop_btn: Button = Button(value="Stop", variant="stop")
51
- _event = generate_btn.click(generate_response, [chatbot, thread_id], chatbot)
 
 
52
  stop_btn.click(cancels=[_event])
53
  return app
 
2
  from gradio import Blocks, Button, Chatbot, ChatMessage, Row, Textbox
3
 
4
 
5
+ def generate_response(
6
+ history: list[ChatMessage], thread_id: str
7
+ ) -> list[ChatMessage]:
8
  """
9
  Appends an assistant message about a quarterly sales plot to the chat history for the specified thread ID.
10
 
 
35
 
36
  history = [
37
  ChatMessage(role="assistant", content="How can I help you?"),
38
+ ChatMessage(
39
+ role="user", content="Can you make me a plot of quarterly sales?"
40
+ ),
41
  ChatMessage(
42
  role="assistant",
43
  content="I am happy to provide you that report and plot.",
 
45
  ]
46
  with Blocks() as app:
47
  with Row():
48
+ thread_id: Textbox = Textbox(
49
+ label="Thread ID", info="Enter Thread ID"
50
+ )
51
 
52
  chatbot: Chatbot = Chatbot(history, type="messages")
53
 
54
  with Row():
55
  generate_btn: Button = Button(value="Generate", variant="primary")
56
  stop_btn: Button = Button(value="Stop", variant="stop")
57
+ _event = generate_btn.click(
58
+ generate_response, [chatbot, thread_id], chatbot
59
+ )
60
  stop_btn.click(cancels=[_event])
61
  return app