sonika-langchain-bot 0.0.8__tar.gz → 0.0.10__tar.gz
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.
- {sonika_langchain_bot-0.0.8/src/sonika_langchain_bot.egg-info → sonika_langchain_bot-0.0.10}/PKG-INFO +8 -2
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/README.md +7 -1
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/setup.py +1 -1
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot/langchain_bdi.py +3 -10
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot/langchain_bot_agent_bdi.py +24 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot/langchain_models.py +16 -3
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10/src/sonika_langchain_bot.egg-info}/PKG-INFO +8 -2
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/test/test.py +26 -4
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/LICENSE +0 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/setup.cfg +0 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot/__init__.py +0 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot/langchain_clasificator.py +0 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot/langchain_class.py +0 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot/langchain_files.py +0 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot/langchain_tools.py +0 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot.egg-info/SOURCES.txt +0 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot.egg-info/dependency_links.txt +0 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot.egg-info/requires.txt +0 -0
- {sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sonika-langchain-bot
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.10
|
4
4
|
Summary: Agente langchain con LLM
|
5
5
|
Author: Erley Blanco Carvajal
|
6
6
|
License: MIT License
|
@@ -30,7 +30,8 @@ Provides-Extra: dev
|
|
30
30
|
Requires-Dist: sphinx<9.0.0,>=8.1.3; extra == "dev"
|
31
31
|
Requires-Dist: sphinx-rtd-theme<4.0.0,>=3.0.1; extra == "dev"
|
32
32
|
|
33
|
-
# Sonika LangChain Bot
|
33
|
+
# Sonika LangChain Bot <a href="https://pepy.tech/projects/sonika-langchain-bot"><img src="https://static.pepy.tech/badge/sonika-langchain-bot" alt="PyPI Downloads"></a>
|
34
|
+
|
34
35
|
|
35
36
|
Una librería Python que implementa un bot conversacional utilizando LangChain con capacidades BDI (Belief-Desire-Intention) y clasificación de texto.
|
36
37
|
|
@@ -104,6 +105,10 @@ bot_response = response_model
|
|
104
105
|
|
105
106
|
print(bot_response)
|
106
107
|
|
108
|
+
#o por streaming
|
109
|
+
for chunk in bot.get_response_stream(user_message):
|
110
|
+
print(chunk)
|
111
|
+
|
107
112
|
```
|
108
113
|
|
109
114
|
### Ejemplo de Clasificación de Texto
|
@@ -137,3 +142,4 @@ result = classifier.classify("Tu texto aquí")
|
|
137
142
|
## Contribución
|
138
143
|
|
139
144
|
Las contribuciones son bienvenidas. Por favor, abre un issue para discutir los cambios importantes que te gustaría hacer.
|
145
|
+
|
@@ -1,4 +1,5 @@
|
|
1
|
-
# Sonika LangChain Bot
|
1
|
+
# Sonika LangChain Bot <a href="https://pepy.tech/projects/sonika-langchain-bot"><img src="https://static.pepy.tech/badge/sonika-langchain-bot" alt="PyPI Downloads"></a>
|
2
|
+
|
2
3
|
|
3
4
|
Una librería Python que implementa un bot conversacional utilizando LangChain con capacidades BDI (Belief-Desire-Intention) y clasificación de texto.
|
4
5
|
|
@@ -72,6 +73,10 @@ bot_response = response_model
|
|
72
73
|
|
73
74
|
print(bot_response)
|
74
75
|
|
76
|
+
#o por streaming
|
77
|
+
for chunk in bot.get_response_stream(user_message):
|
78
|
+
print(chunk)
|
79
|
+
|
75
80
|
```
|
76
81
|
|
77
82
|
### Ejemplo de Clasificación de Texto
|
@@ -105,3 +110,4 @@ result = classifier.classify("Tu texto aquí")
|
|
105
110
|
## Contribución
|
106
111
|
|
107
112
|
Las contribuciones son bienvenidas. Por favor, abre un issue para discutir los cambios importantes que te gustaría hacer.
|
113
|
+
|
{sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot/langchain_bdi.py
RENAMED
@@ -64,16 +64,6 @@ class BotBeliefSystem:
|
|
64
64
|
def _initialize_core_beliefs(self):
|
65
65
|
"""Initializes the core beliefs of the bot."""
|
66
66
|
core_beliefs = [
|
67
|
-
Belief(
|
68
|
-
f"My name is {self.bot_name}.",
|
69
|
-
BeliefType.CORE,
|
70
|
-
confidence=1.0
|
71
|
-
),
|
72
|
-
Belief(
|
73
|
-
f"I operate on Telegram, and my responses should be as concise and accurate as possible.",
|
74
|
-
BeliefType.CORE,
|
75
|
-
confidence=1.0
|
76
|
-
),
|
77
67
|
# Add more core beliefs as needed
|
78
68
|
]
|
79
69
|
|
@@ -81,6 +71,9 @@ class BotBeliefSystem:
|
|
81
71
|
self.add_belief(belief)
|
82
72
|
|
83
73
|
def add_tools_beliefs(self, tools: List[Tool]):
|
74
|
+
|
75
|
+
if len(tools) == 0:
|
76
|
+
return
|
84
77
|
"""Carga y procesa las herramientas disponibles para el bot."""
|
85
78
|
# Instrucciones sobre el uso de herramientas en inglés
|
86
79
|
instrucciones_de_uso = '''\nWhen you want to execute a tool, enclose the command with three asterisks and provide all parameters needed.
|
@@ -1,3 +1,4 @@
|
|
1
|
+
from typing import Generator
|
1
2
|
from typing import List
|
2
3
|
from langchain.memory import ConversationBufferMemory
|
3
4
|
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, HumanMessagePromptTemplate
|
@@ -45,6 +46,7 @@ class LangChainBot:
|
|
45
46
|
"""
|
46
47
|
beliefs_context = self.belief_system.generate_prompt_context()
|
47
48
|
full_system_prompt = f"{beliefs_context}\n\n"
|
49
|
+
print(full_system_prompt)
|
48
50
|
|
49
51
|
prompt = ChatPromptTemplate.from_messages([
|
50
52
|
SystemMessagePromptTemplate.from_template(full_system_prompt),
|
@@ -93,6 +95,8 @@ class LangChainBot:
|
|
93
95
|
if context:
|
94
96
|
augmented_input = f"Context from attached files:\n{context}\n\nUser question: {user_input}"
|
95
97
|
|
98
|
+
print(augmented_input)
|
99
|
+
|
96
100
|
bot_response = self.conversation.invoke({"input": augmented_input, "history": self.memory.chat_memory.messages})
|
97
101
|
|
98
102
|
token_usage= bot_response.response_metadata['token_usage']
|
@@ -128,6 +132,26 @@ class LangChainBot:
|
|
128
132
|
self.save_messages(user_input, bot_response)
|
129
133
|
|
130
134
|
return ResponseModel(user_tokens=user_tokens, bot_tokens=bot_tokens, response=bot_response)
|
135
|
+
|
136
|
+
def get_response_stream(self, user_input: str) -> Generator[str, None, None]:
|
137
|
+
"""
|
138
|
+
Genera una respuesta en streaming para la entrada del usuario, procesando el contexto.
|
139
|
+
|
140
|
+
Args:
|
141
|
+
user_input (str): Entrada del usuario
|
142
|
+
|
143
|
+
Yields:
|
144
|
+
str: Fragmentos de la respuesta generada por el modelo en tiempo real
|
145
|
+
"""
|
146
|
+
context = self._get_context(user_input)
|
147
|
+
augmented_input = f"User question: {user_input}"
|
148
|
+
if context:
|
149
|
+
augmented_input = f"Context from attached files:\n{context}\n\nUser question: {user_input}"
|
150
|
+
|
151
|
+
result_stream = self.conversation.stream({"input": augmented_input, "history": self.memory.chat_memory.messages})
|
152
|
+
for response in result_stream:
|
153
|
+
yield response.content
|
154
|
+
|
131
155
|
|
132
156
|
def _get_context(self, query: str) -> str:
|
133
157
|
"""
|
@@ -1,8 +1,7 @@
|
|
1
1
|
from langchain_openai import ChatOpenAI
|
2
2
|
from sonika_langchain_bot.langchain_class import ILanguageModel
|
3
3
|
from langchain_core.messages import HumanMessage
|
4
|
-
from typing import
|
5
|
-
from pydantic import BaseModel
|
4
|
+
from typing import Generator
|
6
5
|
|
7
6
|
|
8
7
|
class OpenAILanguageModel(ILanguageModel):
|
@@ -46,4 +45,18 @@ class OpenAILanguageModel(ILanguageModel):
|
|
46
45
|
"""
|
47
46
|
message = HumanMessage(content=prompt)
|
48
47
|
response = self.model.invoke([message])
|
49
|
-
return response
|
48
|
+
return response
|
49
|
+
|
50
|
+
def stream_response(self, prompt: str) -> Generator[str, None, None]:
|
51
|
+
"""
|
52
|
+
Genera una respuesta en streaming basada en el prompt proporcionado.
|
53
|
+
|
54
|
+
Args:
|
55
|
+
prompt (str): Texto de entrada para generar la respuesta
|
56
|
+
|
57
|
+
Yields:
|
58
|
+
str: Fragmentos de la respuesta generada por el modelo en tiempo real
|
59
|
+
"""
|
60
|
+
message = HumanMessage(content=prompt)
|
61
|
+
for chunk in self.model.stream([message]):
|
62
|
+
yield chunk.content
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sonika-langchain-bot
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.10
|
4
4
|
Summary: Agente langchain con LLM
|
5
5
|
Author: Erley Blanco Carvajal
|
6
6
|
License: MIT License
|
@@ -30,7 +30,8 @@ Provides-Extra: dev
|
|
30
30
|
Requires-Dist: sphinx<9.0.0,>=8.1.3; extra == "dev"
|
31
31
|
Requires-Dist: sphinx-rtd-theme<4.0.0,>=3.0.1; extra == "dev"
|
32
32
|
|
33
|
-
# Sonika LangChain Bot
|
33
|
+
# Sonika LangChain Bot <a href="https://pepy.tech/projects/sonika-langchain-bot"><img src="https://static.pepy.tech/badge/sonika-langchain-bot" alt="PyPI Downloads"></a>
|
34
|
+
|
34
35
|
|
35
36
|
Una librería Python que implementa un bot conversacional utilizando LangChain con capacidades BDI (Belief-Desire-Intention) y clasificación de texto.
|
36
37
|
|
@@ -104,6 +105,10 @@ bot_response = response_model
|
|
104
105
|
|
105
106
|
print(bot_response)
|
106
107
|
|
108
|
+
#o por streaming
|
109
|
+
for chunk in bot.get_response_stream(user_message):
|
110
|
+
print(chunk)
|
111
|
+
|
107
112
|
```
|
108
113
|
|
109
114
|
### Ejemplo de Clasificación de Texto
|
@@ -137,3 +142,4 @@ result = classifier.classify("Tu texto aquí")
|
|
137
142
|
## Contribución
|
138
143
|
|
139
144
|
Las contribuciones son bienvenidas. Por favor, abre un issue para discutir los cambios importantes que te gustaría hacer.
|
145
|
+
|
@@ -28,8 +28,8 @@ def bot_bdi():
|
|
28
28
|
email_tool = EmailTool()
|
29
29
|
|
30
30
|
tools =[search, email_tool]
|
31
|
-
beliefs = [Belief(content="Eres
|
32
|
-
bot = LangChainBot(language_model, embeddings, beliefs=beliefs, tools=
|
31
|
+
beliefs = [Belief(content="Eres la voz de mi conciencia", type=BeliefType.CORE, confidence=1, source='core')]
|
32
|
+
bot = LangChainBot(language_model, embeddings, beliefs=beliefs, tools=[])
|
33
33
|
|
34
34
|
user_message = 'Hola como me llamo?'
|
35
35
|
|
@@ -40,8 +40,29 @@ def bot_bdi():
|
|
40
40
|
|
41
41
|
print(bot_response)
|
42
42
|
|
43
|
+
def bot_bdi_streaming():
|
44
|
+
# Obtener claves de API desde el archivo .env
|
45
|
+
api_key = os.getenv("OPENAI_API_KEY")
|
46
|
+
api_key_tavily = os.getenv("TAVILY_API_KEY")
|
47
|
+
|
48
|
+
language_model = OpenAILanguageModel(api_key, model_name='gpt-4o-mini-2024-07-18', temperature=1)
|
49
|
+
embeddings = OpenAIEmbeddings(api_key=api_key)
|
50
|
+
|
51
|
+
# Configuración de herramientas y bots
|
52
|
+
search = TavilySearchResults(max_results=2, api_key=api_key_tavily)
|
53
|
+
email_tool = EmailTool()
|
54
|
+
|
55
|
+
tools =[search, email_tool]
|
56
|
+
beliefs = [Belief(content="Eres un asistente de chat", type=BeliefType.PERSONALITY, confidence=1, source='personality')]
|
57
|
+
bot = LangChainBot(language_model, embeddings, beliefs=beliefs, tools=tools)
|
58
|
+
|
59
|
+
user_message = 'Hola como me llamo?'
|
43
60
|
|
61
|
+
bot.load_conversation_history([Message(content="Mi nombre es Erley", is_bot=False)])
|
62
|
+
for chunk in bot.get_response_stream(user_message):
|
63
|
+
print(chunk)
|
44
64
|
|
65
|
+
|
45
66
|
|
46
67
|
# Definir la clase 'Classification' con Pydantic para validar la estructura
|
47
68
|
class Classification(BaseModel):
|
@@ -63,5 +84,6 @@ def clasification():
|
|
63
84
|
result = classifier.classify("how are you?")
|
64
85
|
print(result)
|
65
86
|
|
66
|
-
|
67
|
-
|
87
|
+
bot_bdi()
|
88
|
+
#bot_bdi_streaming()
|
89
|
+
#clasification()
|
File without changes
|
File without changes
|
{sonika_langchain_bot-0.0.8 → sonika_langchain_bot-0.0.10}/src/sonika_langchain_bot/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|