Examples and Additional CRUD routes
This commit is contained in:
parent
16b928c384
commit
9bcd6e28d4
|
|
@ -0,0 +1,2 @@
|
|||
DATABASE_TYPE=sqlite
|
||||
CONNECTION_URI=sqlite:///api.db
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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/",
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
[tool.poetry]
|
||||
name = "api2"
|
||||
name = "honcho"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["hyusap <paulayush@gmail.com>"]
|
||||
authors = ["Plastic Labs <hello@plasticlabs.ai>"]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -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>"]
|
||||
|
|
@ -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"
|
||||
Loading…
Reference in New Issue