sonika-langchain-bot 0.0.18__tar.gz → 0.0.19__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.

Potentially problematic release.


This version of sonika-langchain-bot might be problematic. Click here for more details.

Files changed (21) hide show
  1. {sonika_langchain_bot-0.0.18/src/sonika_langchain_bot.egg-info → sonika_langchain_bot-0.0.19}/PKG-INFO +1 -1
  2. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/setup.py +1 -1
  3. sonika_langchain_bot-0.0.19/src/sonika_langchain_bot/langchain_clasificator.py +66 -0
  4. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19/src/sonika_langchain_bot.egg-info}/PKG-INFO +1 -1
  5. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/test/test.py +2 -2
  6. sonika_langchain_bot-0.0.18/src/sonika_langchain_bot/langchain_clasificator.py +0 -30
  7. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/LICENSE +0 -0
  8. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/README.md +0 -0
  9. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/setup.cfg +0 -0
  10. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot/__init__.py +0 -0
  11. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot/document_processor.py +0 -0
  12. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot/langchain_bot_agent.py +0 -0
  13. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot/langchain_class.py +0 -0
  14. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot/langchain_files.py +0 -0
  15. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot/langchain_models.py +0 -0
  16. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot/langchain_tools.py +0 -0
  17. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot.egg-info/SOURCES.txt +0 -0
  18. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot.egg-info/dependency_links.txt +0 -0
  19. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot.egg-info/requires.txt +0 -0
  20. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/src/sonika_langchain_bot.egg-info/top_level.txt +0 -0
  21. {sonika_langchain_bot-0.0.18 → sonika_langchain_bot-0.0.19}/test/test_document_processor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sonika-langchain-bot
3
- Version: 0.0.18
3
+ Version: 0.0.19
4
4
  Summary: Agente langchain con LLM
5
5
  Author: Erley Blanco Carvajal
6
6
  License: MIT License
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="sonika-langchain-bot",
5
- version="0.0.18",
5
+ version="0.0.19",
6
6
  description="Agente langchain con LLM",
7
7
  author="Erley Blanco Carvajal",
8
8
  license="MIT License",
@@ -0,0 +1,66 @@
1
+ from pydantic import BaseModel
2
+ from typing import Dict, Any, Type
3
+ from sonika_langchain_bot.langchain_class import ILanguageModel
4
+
5
+ class ClassificationResponse(BaseModel):
6
+ """Respuesta de clasificación con tokens utilizados"""
7
+ input_tokens: int
8
+ output_tokens: int
9
+ result: Dict[str, Any]
10
+
11
+ class TextClassifier:
12
+ def __init__(self, validation_class: Type[BaseModel], llm: ILanguageModel):
13
+ self.llm = llm
14
+ self.validation_class = validation_class
15
+ # Guardamos ambas versiones del modelo
16
+ self.original_model = self.llm.model # Sin structured output
17
+ self.structured_model = self.llm.model.with_structured_output(validation_class)
18
+
19
+ def classify(self, text: str) -> ClassificationResponse:
20
+ """
21
+ Clasifica el texto según la clase de validación.
22
+
23
+ Args:
24
+ text: Texto a clasificar
25
+
26
+ Returns:
27
+ ClassificationResponse: Objeto con result, input_tokens y output_tokens
28
+ """
29
+ prompt = f"""
30
+ Classify the following text based on the properties defined in the validation class.
31
+
32
+ Text: {text}
33
+
34
+ Only extract the properties mentioned in the validation class.
35
+ """
36
+
37
+ # Primero invocamos el modelo ORIGINAL para obtener metadata de tokens
38
+ raw_response = self.original_model.invoke(prompt)
39
+
40
+ # Extraer información de tokens del AIMessage original
41
+ input_tokens = 0
42
+ output_tokens = 0
43
+
44
+ if hasattr(raw_response, 'response_metadata'):
45
+ token_usage = raw_response.response_metadata.get('token_usage', {})
46
+ input_tokens = token_usage.get('prompt_tokens', 0)
47
+ output_tokens = token_usage.get('completion_tokens', 0)
48
+
49
+ # Ahora invocamos con structured output para obtener el objeto parseado
50
+ response = self.structured_model.invoke(prompt)
51
+
52
+ # Validar que el response es de la clase correcta
53
+ if isinstance(response, self.validation_class):
54
+ # Crear el resultado dinámicamente basado en los atributos
55
+ result_data = {
56
+ field: getattr(response, field)
57
+ for field in self.validation_class.__fields__.keys()
58
+ }
59
+
60
+ return ClassificationResponse(
61
+ input_tokens=input_tokens,
62
+ output_tokens=output_tokens,
63
+ result=result_data
64
+ )
65
+ else:
66
+ raise ValueError(f"The response is not of type '{self.validation_class.__name__}'")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sonika-langchain-bot
3
- Version: 0.0.18
3
+ Version: 0.0.19
4
4
  Summary: Agente langchain con LLM
5
5
  Author: Erley Blanco Carvajal
6
6
  License: MIT License
@@ -76,6 +76,6 @@ def clasification():
76
76
  result = classifier.classify("how are you?")
77
77
  print(result)
78
78
 
79
- bot_bdi()
79
+ #bot_bdi()
80
80
  #bot_bdi_streaming()
81
- #clasification()
81
+ clasification()
@@ -1,30 +0,0 @@
1
- from pydantic import BaseModel
2
- from typing import Dict, Any, Type
3
- from sonika_langchain_bot.langchain_class import ILanguageModel
4
-
5
- # Clase para realizar la clasificación de texto
6
- class TextClassifier:
7
- def __init__(self, validation_class: Type[BaseModel], llm: ILanguageModel):
8
- self.llm =llm
9
- self.validation_class = validation_class
10
- #configuramos el modelo para que tenga una estructura de salida
11
- self.llm.model = self.llm.model.with_structured_output(validation_class)
12
-
13
- def classify(self, text: str) -> Dict[str, Any]:
14
- # Crear el template del prompt
15
- prompt = f"""
16
- Classify the following text based on the properties defined in the validation class.
17
-
18
- Text: {text}
19
-
20
- Only extract the properties mentioned in the validation class.
21
- """
22
- response = self.llm.invoke(prompt=prompt)
23
-
24
- # Asegurarse de que el `response` es de la clase de validación proporcionada
25
- if isinstance(response, self.validation_class):
26
- # Crear el resultado dinámicamente basado en los atributos de la clase de validación
27
- result = {field: getattr(response, field) for field in self.validation_class.__fields__.keys()}
28
- return result
29
- else:
30
- raise ValueError(f"The response is not of type '{self.validation_class.__name__}'")