Skip to content

Commit

Permalink
chore(versioning): versioning and linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 9, 2024
1 parent 8ef6ed0 commit eeae37f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
10 changes: 5 additions & 5 deletions vortex/ai/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# %%
from langchain.agents import AgentExecutor
from langchain.agents.format_scratchpad.openai_tools import \
format_to_openai_tool_messages
from langchain.agents.output_parsers.openai_tools import \
OpenAIToolsAgentOutputParser
from langchain.agents.format_scratchpad.openai_tools import (
format_to_openai_tool_messages,
)
from langchain.agents.output_parsers.openai_tools import OpenAIToolsAgentOutputParser
from langchain.prompts import MessagesPlaceholder
from langchain_core.messages import AIMessage, HumanMessage
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(
tools: list = tools,
hub_prompt: str = "hwchase17/openai-tools-agent",
agent_type="vortex_tools_agent",
context: list = [] # represents the chat history, can be pulled from a db
context: list = [], # represents the chat history, can be pulled from a db
):
self.llm: LLM = llm
self.tools: list = tools
Expand Down
1 change: 1 addition & 0 deletions vortex/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

app = FastAPI()


@app.get("/api/check")
def hello_world():
return {"message": "Vortex is Running!"}
Expand Down
10 changes: 7 additions & 3 deletions vortex/api/data_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import os
from datetime import datetime

from sqlalchemy import (JSON, Column, DateTime, Integer, String, Text,
create_engine)
from sqlalchemy import JSON, Column, DateTime, Integer, String, Text, create_engine
from sqlalchemy.engine import URL
from sqlalchemy.orm import declarative_base, sessionmaker

Expand Down Expand Up @@ -32,19 +31,24 @@ class Conversation(Base):
response = Column(String)
created_at = Column(DateTime, default=datetime.utcnow)


class ChatsHistory(Base):
__tablename__ = 'chats_history'
__tablename__ = "chats_history"
# id = Column(Integer, primary_key=True, index=True)
sender = Column(String, primary_key=True, index=True)
history = Column(Text)
updated_at = Column(DateTime, default=datetime.utcnow)


Base.metadata.create_all(engine)


def get_db():
try:
db = SessionLocal()
yield db
finally:
db.close()


# %%
19 changes: 10 additions & 9 deletions vortex/io/twilio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#%%
# %%
import base64
import logging
import os
Expand All @@ -14,8 +14,7 @@
from twilio.rest import Client

from vortex.ai.agents import VortexAgent
from vortex.api.data_models import (ChatsHistory, Conversation, SessionLocal,
get_db)
from vortex.api.data_models import ChatsHistory, Conversation, SessionLocal, get_db

load_dotenv()

Expand All @@ -32,18 +31,19 @@

agents: Dict[str, weakref.ref] = weakref.WeakValueDictionary()


def get_or_create_agent(phone_number: str, db) -> VortexAgent:
agent = agents.get(phone_number)
chat_history = get_chat_history(db, phone_number)
if agent is not None and chat_history: # Same session stil kept
print(f'Using existing agent {agent}')
if agent is not None and chat_history: # Same session stil kept
print(f"Using existing agent {agent}")
...
elif agent is None and chat_history: # New session but existing user
elif agent is None and chat_history: # New session but existing user
agent = VortexAgent(context=chat_history) # Initialize a new agent instance
print(f'using reloaded agent with history {chat_history}')
print(f"using reloaded agent with history {chat_history}")
elif agent is None and not chat_history:
agent = VortexAgent()
print('using a new agent')
print("using a new agent")
agents[phone_number] = agent
return agent

Expand Down Expand Up @@ -90,7 +90,7 @@ def get_chat_history(db_session, phone_number: str) -> list:
chat_history = str(history[0])
print(chat_history)
loaded = pickle.loads(chat_history)
print(f'loaded history {loaded}')
print(f"loaded history {loaded}")
return loaded


Expand Down Expand Up @@ -127,4 +127,5 @@ async def handle_wapp_message(
send_message(whatsapp_number, langchain_response)
return {"response": langchain_response}


# %%

0 comments on commit eeae37f

Please sign in to comment.