sonika-langchain-bot 0.0.2__tar.gz → 0.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sonika-langchain-bot
3
- Version: 0.0.2
3
+ Version: 0.0.4
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.2",
5
+ version="0.0.4",
6
6
  description="Agente langchain con LLM",
7
7
  author="Erley Blanco Carvajal",
8
8
  license="MIT License",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sonika-langchain-bot
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Agente langchain con LLM
5
5
  Author: Erley Blanco Carvajal
6
6
  License: MIT License
@@ -5,4 +5,5 @@ sonika_langchain_bot.egg-info/PKG-INFO
5
5
  sonika_langchain_bot.egg-info/SOURCES.txt
6
6
  sonika_langchain_bot.egg-info/dependency_links.txt
7
7
  sonika_langchain_bot.egg-info/requires.txt
8
- sonika_langchain_bot.egg-info/top_level.txt
8
+ sonika_langchain_bot.egg-info/top_level.txt
9
+ test/test.py
@@ -0,0 +1,85 @@
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from langchain_openai import OpenAIEmbeddings
4
+
5
+ from sonika_langchain_bot.langchain_tools import EmailTool
6
+ from sonika_langchain_bot.langchain_bdi import Belief, BeliefType
7
+ from sonika_langchain_bot.langchain_bot_agent_bdi import LangChainBot
8
+ from sonika_langchain_bot.langchain_clasificator import OpenAIModel, TextClassifier
9
+ from sonika_langchain_bot.langchain_class import ResponseModel
10
+ from sonika_langchain_bot.langchain_models import OpenAILanguageModel
11
+ from langchain_community.tools.tavily_search import TavilySearchResults
12
+ from pydantic import BaseModel, Field
13
+
14
+
15
+ env_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env')
16
+ load_dotenv(env_path)
17
+
18
+ def bot_bdi():
19
+ # Obtener claves de API desde el archivo .env
20
+ api_key = os.getenv("OPENAI_API_KEY")
21
+ api_key_tavily = os.getenv("TAVILY_API_KEY")
22
+
23
+ language_model = OpenAILanguageModel(api_key, model_name='gpt-4o-mini-2024-07-18', temperature=1)
24
+ embeddings = OpenAIEmbeddings(api_key=api_key)
25
+
26
+ # Configuración de herramientas y bots
27
+ search = TavilySearchResults(max_results=2, api_key=api_key_tavily)
28
+ email_tool = EmailTool()
29
+
30
+ tools =[search, email_tool]
31
+ beliefs = [Belief(content="Eres un asistente de chat", type=BeliefType.PERSONALITY, confidence=1, source='personality')]
32
+ bot = LangChainBot(language_model, embeddings, beliefs=beliefs, tools=tools)
33
+
34
+ user_message = 'Hola como te llamas?'
35
+ # Obtener la respuesta del bot
36
+ response_model: ResponseModel = bot.get_response(user_message)
37
+ bot_response = response_model.response
38
+
39
+ print(bot_response)
40
+
41
+ def bot():
42
+ # Obtener claves de API desde el archivo .env
43
+ api_key = os.getenv("OPENAI_API_KEY")
44
+ api_key_tavily = os.getenv("TAVILY_API_KEY")
45
+
46
+ language_model = OpenAILanguageModel(api_key, model_name='gpt-4o-mini-2024-07-18', temperature=1)
47
+ embeddings = OpenAIEmbeddings(api_key=api_key)
48
+
49
+ # Configuración de herramientas y bots
50
+ search = TavilySearchResults(max_results=2, api_key=api_key_tavily)
51
+ email_tool = EmailTool()
52
+
53
+ tools =[search, email_tool]
54
+ bot = LangChainBot(language_model, embeddings, instructions="Eres un bot de telegram", tools=tools)
55
+
56
+ user_message = 'Hola como te llamas?'
57
+ # Obtener la respuesta del bot
58
+ response_model: ResponseModel = bot.get_response(user_message)
59
+ bot_response = response_model.response
60
+
61
+ print(bot_response)
62
+
63
+ # Definir la clase 'Classification' con Pydantic para validar la estructura
64
+ class Classification(BaseModel):
65
+ intention: str = Field()
66
+ sentiment: str = Field(..., enum=["feliz", "neutral", "triste", "excitado"])
67
+ aggressiveness: int = Field(
68
+ ...,
69
+ description="describes how aggressive the statement is, the higher the number the more aggressive",
70
+ enum=[1, 2, 3, 4, 5],
71
+ )
72
+ language: str = Field(
73
+ ..., enum=["español", "ingles", "frances", "aleman", "italiano"]
74
+ )
75
+
76
+ def clasification():
77
+ api_key = os.getenv("OPENAI_API_KEY")
78
+ model = OpenAIModel(api_key=api_key,validation_class=Classification)
79
+ classifier = TextClassifier(api_key=api_key,llm=model, validation_class=Classification)
80
+ result = classifier.classify("venga, quiero que vengas a mi casa y nos tomamos un vino tu y yo solos, en mi cuarto sin ropa, que dices")
81
+ print(result)
82
+
83
+ bot_bdi()
84
+ #bot()
85
+ #clasification()