diff --git a/api/.env.template b/api/.env.template new file mode 100644 index 00000000..816aa809 --- /dev/null +++ b/api/.env.template @@ -0,0 +1,2 @@ +DATABASE_TYPE=sqlite +CONNECTION_URI=sqlite:///api.db diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 00000000..e69de29b diff --git a/api/api/crud.py b/api/api/crud.py index ab23c702..929aa9c9 100644 --- a/api/api/crud.py +++ b/api/api/crud.py @@ -36,6 +36,7 @@ def create_session(db: Session, user_id: str, session: schemas.SessionCreate): db.refresh(db_session) return db_session +# TODO add a method to update a session and change the active state def create_message(db: Session, message: schemas.MessageCreate, session_id: int): db_message = models.Message( diff --git a/api/api/main.py b/api/api/main.py index 67f78a1f..e6ede188 100644 --- a/api/api/main.py +++ b/api/api/main.py @@ -8,7 +8,6 @@ models.Base.metadata.create_all(bind=engine) app = FastAPI() - def get_db(): db = SessionLocal() try: @@ -16,6 +15,9 @@ def get_db(): finally: db.close() +######################################################## +# Session Routes +######################################################## @app.get("/users/{user_id}/sessions", response_model=list[schemas.Session]) def get_sessions(user_id: str, db: Session = Depends(get_db)): @@ -28,6 +30,25 @@ def create_session( ): return crud.create_session(db, user_id, session) +@app.put("/users/{user_id}/sessions/{session_id}") +def update_session( + user_id: str, + session_id: int, + session: schemas.SessionCreate, + db: Session = Depends(get_db), + ): + # TODO finish implementation + pass + +@app.delete("/users/{user_id}/sessions/{session_id}") +def delete_session( + user_id: str, + session_id: int, + session: schemas.SessionCreate, + db: Session = Depends(get_db), + ): + # TODO finish implementation + pass @app.get("/users/{user_id}/sessions/{session_id}", response_model=schemas.Session) def get_session(user_id: str, session_id: int, db: Session = Depends(get_db)): @@ -36,6 +57,9 @@ def get_session(user_id: str, session_id: int, db: Session = Depends(get_db)): raise HTTPException(status_code=404, detail="Session not found") return db_session +######################################################## +# Message Routes +######################################################## @app.post( "/users/{user_id}/sessions/{session_id}/messages/", response_model=schemas.Message @@ -48,6 +72,9 @@ def create_message_for_session( ): return crud.create_message(db, message, session_id) +######################################################## +# Metacognition Routes +######################################################## @app.get( "/users/{user_id}/sessions/{session_id}/messages/{message_id}/metacognitions/", diff --git a/api/api/models.py b/api/api/models.py index 50bd5b9f..c4875639 100644 --- a/api/api/models.py +++ b/api/api/models.py @@ -1,28 +1,37 @@ from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, DateTime import datetime -from sqlalchemy.orm import relationship +from sqlalchemy.orm import relationship, Mapped, mapped_column from .db import Base class Session(Base): __tablename__ = "sessions" - id = Column(Integer, primary_key=True, index=True, autoincrement=True) - user_id = Column(String, index=True) - location_id = Column(String, index=True) - is_active = Column(Boolean, default=True) - session_data = Column(String) - created_at = Column(DateTime, default=datetime.datetime.utcnow) - + # id = Column(Integer, primary_key=True, index=True, autoincrement=True) + # user_id = Column(String, index=True) + # location_id = Column(String, index=True) + # is_active = Column(Boolean, default=True) + # session_data = Column(String) + # created_at = Column(DateTime, default=datetime.datetime.utcnow) + id: Mapped[int] = mapped_column(primary_key=True, index=True, autoincrement=True) + user_id: Mapped[str] = mapped_column(index=True) + location_id: Mapped[str] = mapped_column(index=True) + is_active: Mapped[bool] = mapped_column(default=True) + session_data: Mapped[str] + created_at: Mapped[datetime.datetime] = mapped_column(default=datetime.datetime.utcnow) messages = relationship("Message", back_populates="session") class Message(Base): __tablename__ = "messages" - id = Column(Integer, primary_key=True, index=True, autoincrement=True) - session_id = Column(Integer, ForeignKey("sessions.id")) - is_user = Column(Boolean) - content = Column(String) + # id = Column(Integer, primary_key=True, index=True, autoincrement=True) + # session_id = Column(Integer, ForeignKey("sessions.id")) + # is_user = Column(Boolean) + # content = Column(String) + id: Mapped[int] = mapped_column(primary_key=True, index=True, autoincrement=True) + session_id: Mapped[int] = mapped_column(ForeignKey("sessions.id")) + is_user: Mapped[bool] + content: Mapped[str] # TODO add a max message length session = relationship("Session", back_populates="messages") metacognitions = relationship("Metacognitions", back_populates="message") @@ -31,9 +40,12 @@ class Message(Base): # TODO: add metacognitive data to messages class Metacognitions(Base): __tablename__ = "metacognitions" - id = Column(Integer, primary_key=True, index=True, autoincrement=True) + id: Mapped[int] = mapped_column(primary_key=True, index=True, autoincrement=True) + metacognition_type: Mapped[str] # TODO add a max metacognition type length + content: Mapped[str] + # id = Column(Integer, primary_key=True, index=True, autoincrement=True) message_id = Column(Integer, ForeignKey("messages.id")) - metacognition_type = Column(String, index=True) - content = Column(String) + # metacognition_type = Column(String, index=True) + # content = Column(String) message = relationship("Message", back_populates="metacognitions") diff --git a/api/pyproject.toml b/api/pyproject.toml index e18682a4..8b280fab 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -1,8 +1,8 @@ [tool.poetry] -name = "api2" +name = "honcho" version = "0.1.0" description = "" -authors = ["hyusap "] +authors = ["Plastic Labs "] readme = "README.md" [tool.poetry.dependencies] diff --git a/example/main.py b/example/cli/main.py similarity index 74% rename from example/main.py rename to example/cli/main.py index 9c23507f..a31dab9e 100644 --- a/example/main.py +++ b/example/cli/main.py @@ -1,8 +1,11 @@ from langchain.prompts import ChatPromptTemplate -from langchain_community.chat_models import ChatOllama +# from langchain_community.chat_models import ChatOllama +from langchain_community.chat_models.fake import FakeListChatModel from langchain.schema import HumanMessage, SystemMessage, AIMessage -llm = ChatOllama(model="phi") +# llm = ChatOllama(model="phi") +responses = ["Fake LLM Response :)"] +llm = FakeListChatModel(responses=responses) system = SystemMessage(content="You are world class technical documentation writer. Be as concise as possible") memory = [] @@ -21,6 +24,7 @@ def chat(): ]) chain = prompt | llm response = chain.invoke({}) + print(type(response)) print(f"AI: {response.content}") memory.append(HumanMessage(content=user_input)) memory.append(response) diff --git a/example/poetry.lock b/example/cli/poetry.lock similarity index 100% rename from example/poetry.lock rename to example/cli/poetry.lock diff --git a/example/pyproject.toml b/example/cli/pyproject.toml similarity index 92% rename from example/pyproject.toml rename to example/cli/pyproject.toml index fcf35ea5..6f15c055 100644 --- a/example/pyproject.toml +++ b/example/cli/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "example" +name = "honcho-cli-example" version = "0.1.0" description = "" authors = ["Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com>"] diff --git a/example/discord/pyproject.toml b/example/discord/pyproject.toml new file mode 100644 index 00000000..db99d606 --- /dev/null +++ b/example/discord/pyproject.toml @@ -0,0 +1,16 @@ +[tool.poetry] +name = "honcho-discord-example" +version = "0.1.0" +description = "" +authors = ["Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com>"] +readme = "README.md" +packages = [{include = "honcho_discord_example"}] + +[tool.poetry.dependencies] +python = "^3.11" +langchain = "^0.1.0" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"