mb-rag 1.1.13__py3-none-any.whl → 1.1.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mb-rag might be problematic. Click here for more details.
- mb_rag/chatbot/basic.py +103 -0
- mb_rag/version.py +1 -1
- {mb_rag-1.1.13.dist-info → mb_rag-1.1.18.dist-info}/METADATA +1 -1
- {mb_rag-1.1.13.dist-info → mb_rag-1.1.18.dist-info}/RECORD +6 -6
- {mb_rag-1.1.13.dist-info → mb_rag-1.1.18.dist-info}/WHEEL +0 -0
- {mb_rag-1.1.13.dist-info → mb_rag-1.1.18.dist-info}/top_level.txt +0 -0
mb_rag/chatbot/basic.py
CHANGED
|
@@ -145,6 +145,7 @@ class ModelFactory:
|
|
|
145
145
|
raise ImportError("Langchain Community package not found. Please install it using: pip install langchain_ollama")
|
|
146
146
|
|
|
147
147
|
from langchain_ollama import ChatOllama
|
|
148
|
+
print(f"Current Ollama serve model is {os.system('ollama ps')}")
|
|
148
149
|
kwargs["model"] = model_name
|
|
149
150
|
return ChatOllama(**kwargs)
|
|
150
151
|
|
|
@@ -460,3 +461,105 @@ class IPythonStreamHandler(StreamingStdOutCallbackHandler):
|
|
|
460
461
|
"""Handle new token"""
|
|
461
462
|
self.output += token
|
|
462
463
|
display(HTML(self.output), clear=True)
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
class AgentFactory:
|
|
467
|
+
"""Factory class for creating different types of agents"""
|
|
468
|
+
|
|
469
|
+
def __init__(self, agent_type: str = 'basic', model_name: str = "gpt-4o", **kwargs) -> Any:
|
|
470
|
+
"""
|
|
471
|
+
Factory method to create any type of agent
|
|
472
|
+
Args:
|
|
473
|
+
agent_type (str): Type of agent to create. Default is basic.
|
|
474
|
+
model_name (str): Name of the model
|
|
475
|
+
**kwargs: Additional arguments
|
|
476
|
+
Returns:
|
|
477
|
+
Any: Agent
|
|
478
|
+
"""
|
|
479
|
+
creators = {
|
|
480
|
+
'basic': self.create_basic_agent,
|
|
481
|
+
'langgraph': self.create_langgraph_agent,
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
agent_data = creators.get(agent_type)
|
|
485
|
+
if not agent_data:
|
|
486
|
+
raise ValueError(f"Unsupported agent type: {agent_type}")
|
|
487
|
+
|
|
488
|
+
try:
|
|
489
|
+
self.agent = agent_data(model_name, **kwargs)
|
|
490
|
+
except Exception as e:
|
|
491
|
+
raise ValueError(f"Error creating {agent_type} agent: {str(e)}")
|
|
492
|
+
|
|
493
|
+
@classmethod
|
|
494
|
+
def create_basic_agent(cls, model_name: str = "gpt-4o", **kwargs) -> Any:
|
|
495
|
+
"""
|
|
496
|
+
Create basic agent
|
|
497
|
+
Args:
|
|
498
|
+
model_name (str): Name of the model
|
|
499
|
+
**kwargs: Additional arguments
|
|
500
|
+
Returns:
|
|
501
|
+
Runnable: Agent
|
|
502
|
+
"""
|
|
503
|
+
# Basic agent creation logic here
|
|
504
|
+
llm = ModelFactory(model_name=model_name, **kwargs).model
|
|
505
|
+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
506
|
+
prompt = ChatPromptTemplate.from_messages([
|
|
507
|
+
("system", "You are a helpful AI assistant"),
|
|
508
|
+
MessagesPlaceholder(variable_name="messages")
|
|
509
|
+
])
|
|
510
|
+
from langchain_core.runnables import chain
|
|
511
|
+
agent = prompt | llm
|
|
512
|
+
return agent
|
|
513
|
+
|
|
514
|
+
@classmethod
|
|
515
|
+
def create_langgraph_agent(cls, model_name: str = "gpt-4o", **kwargs) -> Any:
|
|
516
|
+
"""
|
|
517
|
+
Create LangGraph agent
|
|
518
|
+
Args:
|
|
519
|
+
model_name (str): Name of the model
|
|
520
|
+
**kwargs: Additional arguments
|
|
521
|
+
Returns:
|
|
522
|
+
Graph: LangGraph agent
|
|
523
|
+
"""
|
|
524
|
+
if not check_package("langgraph"):
|
|
525
|
+
raise ImportError("LangGraph package not found. Please install it using: pip install langgraph")
|
|
526
|
+
|
|
527
|
+
from langgraph.graph import StateGraph, MessageGraph
|
|
528
|
+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
529
|
+
from langchain_core.runnables import chain
|
|
530
|
+
from langchain_core.messages import BaseMessage
|
|
531
|
+
|
|
532
|
+
llm = ModelFactory(model_name=model_name, **kwargs).model
|
|
533
|
+
|
|
534
|
+
# Define the state of the graph
|
|
535
|
+
class GraphState:
|
|
536
|
+
messages: List[BaseMessage]
|
|
537
|
+
agent_state: Dict[str, Any]
|
|
538
|
+
|
|
539
|
+
# Define the nodes
|
|
540
|
+
def agent(state: GraphState):
|
|
541
|
+
prompt = ChatPromptTemplate.from_messages([
|
|
542
|
+
("system", "You are a helpful AI assistant"),
|
|
543
|
+
MessagesPlaceholder(variable_name="messages")
|
|
544
|
+
])
|
|
545
|
+
return (prompt | llm).invoke({"messages": state.messages})
|
|
546
|
+
|
|
547
|
+
def user(state: GraphState, input: str):
|
|
548
|
+
return HumanMessage(content=input)
|
|
549
|
+
|
|
550
|
+
# Define the graph
|
|
551
|
+
graph = MessageGraph()
|
|
552
|
+
|
|
553
|
+
# Add the nodes
|
|
554
|
+
graph.add_node("agent", agent)
|
|
555
|
+
graph.add_node("user", user)
|
|
556
|
+
|
|
557
|
+
# Set the entrypoint
|
|
558
|
+
graph.set_entry_point("user")
|
|
559
|
+
|
|
560
|
+
# Add the edges
|
|
561
|
+
graph.add_edge("user", "agent")
|
|
562
|
+
graph.add_edge("agent", "user")
|
|
563
|
+
|
|
564
|
+
# Compile the graph
|
|
565
|
+
return graph.compile()
|
mb_rag/version.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
mb_rag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
mb_rag/version.py,sha256=
|
|
2
|
+
mb_rag/version.py,sha256=kHqa0xhMfGNm0aT1_krDNIuXwX8m3fsXu737vjLlKwA,207
|
|
3
3
|
mb_rag/chatbot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
mb_rag/chatbot/basic.py,sha256=
|
|
4
|
+
mb_rag/chatbot/basic.py,sha256=8uHwTZ8YepGtphTE0pd2T8p51xzthmtlFmzfIpiK6A0,20395
|
|
5
5
|
mb_rag/chatbot/chains.py,sha256=vDbLX5R29sWN1pcFqJ5fyxJEgMCM81JAikunAEvMC9A,7223
|
|
6
6
|
mb_rag/chatbot/prompts.py,sha256=n1PyiLbU-5fkslRv6aVOzt0dDlwya_cEdQ7kRnRhMuY,1749
|
|
7
7
|
mb_rag/rag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -9,7 +9,7 @@ mb_rag/rag/embeddings.py,sha256=KjBdekFDb5M3dRMco4r3dDMXMsG5dxdzKImuVIipsd0,2709
|
|
|
9
9
|
mb_rag/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
10
|
mb_rag/utils/bounding_box.py,sha256=G0hdDam8QmYtD9lfwMeDHGm-TTo6KZg-yK5ESFL9zaM,8366
|
|
11
11
|
mb_rag/utils/extra.py,sha256=spbFrGgdruNyYQ5PzgvpSIa6Nm0rn9bb4qc8W9g582o,2492
|
|
12
|
-
mb_rag-1.1.
|
|
13
|
-
mb_rag-1.1.
|
|
14
|
-
mb_rag-1.1.
|
|
15
|
-
mb_rag-1.1.
|
|
12
|
+
mb_rag-1.1.18.dist-info/METADATA,sha256=YM6qxjtilsWx2eTouiQTo-8uJavCjxe0IShAwJ4bOBg,234
|
|
13
|
+
mb_rag-1.1.18.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
14
|
+
mb_rag-1.1.18.dist-info/top_level.txt,sha256=FIK1eAa5uYnurgXZquBG-s3PIy-HDTC5yJBW4lTH_pM,7
|
|
15
|
+
mb_rag-1.1.18.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|