Skip to content

Commit

Permalink
[0.0.10] Release
Browse files Browse the repository at this point in the history
* chore: Save Point

* fix(db): change connection logic and remove unnecessary refreshes

* fix(documents): switch to Azure embedding model

* feat: Setup pytest fixtures

* feat(tests): Initial test routes for tranche 1

* feat(test) tranche 2 of tests and associated bug fixes

* feat(test) tranche 3 of tests and associated bug fixes

* fix(tests) Address PR comments and update version and changelog
  • Loading branch information
VVoruganti committed Jul 25, 2024
1 parent 659b13a commit ddcde6b
Show file tree
Hide file tree
Showing 27 changed files with 1,611 additions and 688 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.0.10] — 2024-07-23

### Added

* Test cases for Storage API
* Sentry tracing and profiling
* Additional Error handling

### Changed

* Document API uses same embedding endpoint as deriver
* CRUD operations use one less database call by removing extra refresh
* Use database for timestampz rather than API
* Pydantic schemas to use modern syntax

### Fixed

* Deriver queue resolution


## [0.0.9] — 2024-05-16

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 🫡 Honcho
![Static Badge](https://img.shields.io/badge/Version-0.0.9-blue)
![Static Badge](https://img.shields.io/badge/Version-0.0.10-blue)
[![Discord](https://img.shields.io/discord/1016845111637839922?style=flat&logo=discord&logoColor=23ffffff&label=Plastic%20Labs&labelColor=235865F2)](https://discord.gg/plasticlabs)
[![arXiv](https://img.shields.io/badge/arXiv-2310.06983-b31b1b.svg)](https://arxiv.org/abs/2310.06983)
![GitHub License](https://img.shields.io/github/license/plastic-labs/honcho)
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: "3.8"
services:
api:
image: honcho:latest
build:
context: .
dockerfile: Dockerfile
Expand Down
1,112 changes: 610 additions & 502 deletions poetry.lock

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
[tool.poetry]
name = "honcho"
version = "0.0.9"
version = "0.0.10"
description = "Honcho Server"
authors = ["Plastic Labs <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
fastapi = "^0.111.0"
uvicorn = "^0.29.0"
python-dotenv = "^1.0.0"
sqlalchemy = "^2.0.30"
slowapi = "^0.1.9"
fastapi-pagination = "^0.12.24"
pgvector = "^0.2.5"
openai = "^1.12.0"
sentry-sdk = "^2.3.0"
sentry-sdk = {extras = ["fastapi", "sqlalchemy"], version = "^2.3.1"}
greenlet = "^3.0.3"
psycopg = {extras= ["binary"], version="^3.1.19"}
httpx = "^0.27.0"
uvloop = "^0.19.0"
httptools = "^0.6.1"
mirascope = "^0.15.1"
opentelemetry-instrumentation-fastapi = "^0.45b0"
opentelemetry-sdk = "^1.24.0"
opentelemetry-exporter-otlp = "^1.24.0"
opentelemetry-instrumentation-sqlalchemy = "^0.45b0"
opentelemetry-instrumentation-logging = "^0.45b0"

[tool.poetry.group.test.dependencies]
pytest = "^8.2.2"
sqlalchemy-utils = "^0.41.2"
pytest-asyncio = "^0.23.7"
coverage = "^7.6.0"
interrogate = "^1.7.0"

[tool.ruff.lint]
# from https://docs.astral.sh/ruff/linter/#rule-selection example
select = [
Expand All @@ -51,3 +55,6 @@ extend-immutable-calls = ["fastapi.Depends"]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.lpytest.ini_options]
asyncio_mode = "auto"
64 changes: 40 additions & 24 deletions src/crud.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import datetime
import os
import uuid
from typing import Optional, Sequence

from openai import OpenAI
from openai import AzureOpenAI, OpenAI
from sqlalchemy import Select, select
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession

# from sqlalchemy.orm import Session
from . import models, schemas

openai_client = OpenAI()
openai_client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
)

########################################################
# app methods
Expand Down Expand Up @@ -39,7 +44,7 @@ async def create_app(db: AsyncSession, app: schemas.AppCreate) -> models.App:
honcho_app = models.App(name=app.name, h_metadata=app.metadata)
db.add(honcho_app)
await db.commit()
await db.refresh(honcho_app)
# await db.refresh(honcho_app)
return honcho_app


Expand All @@ -50,12 +55,12 @@ async def update_app(
if honcho_app is None:
raise ValueError("App not found")
if app.name is not None:
honcho_app.content = app.name
honcho_app.name = app.name
if app.metadata is not None:
honcho_app.h_metadata = app.metadata

await db.commit()
await db.refresh(honcho_app)
# await db.refresh(honcho_app)
return honcho_app


Expand Down Expand Up @@ -83,7 +88,7 @@ async def create_user(
)
db.add(honcho_user)
await db.commit()
await db.refresh(honcho_user)
# await db.refresh(honcho_user)
return honcho_user


Expand Down Expand Up @@ -139,12 +144,12 @@ async def update_user(
if honcho_user is None:
raise ValueError("User not found")
if user.name is not None:
honcho_user.content = user.name
honcho_user.name = user.name
if user.metadata is not None:
honcho_user.h_metadata = user.metadata

await db.commit()
await db.refresh(honcho_user)
# await db.refresh(honcho_user)
return honcho_user


Expand Down Expand Up @@ -228,8 +233,18 @@ async def create_session(
h_metadata=session.metadata,
)
db.add(honcho_session)
# print("====== Testing State of ORM Object ====")
# print(honcho_session)
# print("=======================================")
#
# await db.flush()
#
# print("====== Testing State of ORM Object ====")
# print(honcho_session)
# print("=======================================")

await db.commit()
await db.refresh(honcho_session)
# await db.refresh(honcho_session)
return honcho_session


Expand All @@ -250,7 +265,7 @@ async def update_session(
): # Need to explicitly be there won't make it empty by default
honcho_session.h_metadata = session.metadata
await db.commit()
await db.refresh(honcho_session)
# await db.refresh(honcho_session)
return honcho_session


Expand Down Expand Up @@ -300,7 +315,7 @@ async def create_message(
db.add(honcho_message)
await db.commit()
# await db.refresh(honcho_message, attribute_names=["id", "content", "h_metadata"])
await db.refresh(honcho_message)
# await db.refresh(honcho_message)
return honcho_message


Expand Down Expand Up @@ -372,7 +387,7 @@ async def update_message(
): # Need to explicitly be there won't make it empty by default
honcho_message.h_metadata = message.metadata
await db.commit()
await db.refresh(honcho_message)
# await db.refresh(honcho_message)
return honcho_message


Expand All @@ -388,7 +403,7 @@ async def create_metamessage(
user_id: uuid.UUID,
session_id: uuid.UUID,
):
message = get_message(
message = await get_message(
db,
app_id=app_id,
session_id=session_id,
Expand All @@ -407,7 +422,7 @@ async def create_metamessage(

db.add(honcho_metamessage)
await db.commit()
await db.refresh(honcho_metamessage)
# await db.refresh(honcho_metamessage)
return honcho_metamessage


Expand Down Expand Up @@ -498,7 +513,7 @@ async def update_metamessage(
if metamessage.metamessage_type is not None:
honcho_metamessage.metamessage_type = metamessage.metamessage_type
await db.commit()
await db.refresh(honcho_metamessage)
# await db.refresh(honcho_metamessage)
return honcho_metamessage


Expand Down Expand Up @@ -582,7 +597,7 @@ async def create_collection(
except IntegrityError:
await db.rollback()
raise ValueError("Collection already exists") from None
await db.refresh(honcho_collection)
# await db.refresh(honcho_collection)
return honcho_collection


Expand All @@ -601,12 +616,13 @@ async def update_collection(
if collection.metadata is not None:
honcho_collection.h_metadata = collection.metadata
try:
honcho_collection.name = collection.name
await db.commit()
if collection.name is not None:
honcho_collection.name = collection.name
await db.commit()
except IntegrityError:
await db.rollback()
raise ValueError("Collection already exists") from None
await db.refresh(honcho_collection)
# await db.refresh(honcho_collection)
return honcho_collection


Expand Down Expand Up @@ -700,7 +716,7 @@ async def query_documents(
top_k: int = 5,
) -> Sequence[models.Document]:
response = openai_client.embeddings.create(
input=query, model="text-embedding-3-small"
input=query, model=os.getenv("AZURE_OPENAI_EMBED_DEPLOYMENT")
)
embedding_query = response.data[0].embedding
stmt = (
Expand Down Expand Up @@ -736,7 +752,7 @@ async def create_document(
raise ValueError("Session not found or does not belong to user")

response = openai_client.embeddings.create(
input=document.content, model="text-embedding-3-small"
input=document.content, model=os.getenv("AZURE_OPENAI_EMBED_DEPLOYMENT")
)

embedding = response.data[0].embedding
Expand All @@ -749,7 +765,7 @@ async def create_document(
)
db.add(honcho_document)
await db.commit()
await db.refresh(honcho_document)
# await db.refresh(honcho_document)
return honcho_document


Expand All @@ -773,7 +789,7 @@ async def update_document(
if document.content is not None:
honcho_document.content = document.content
response = openai_client.embeddings.create(
input=document.content, model="text-embedding-3-small"
input=document.content, model=os.getenv("AZURE_OPENAI_EMBED_DEPLOYMENT")
)
embedding = response.data[0].embedding
honcho_document.embedding = embedding
Expand All @@ -782,7 +798,7 @@ async def update_document(
if document.metadata is not None:
honcho_document.h_metadata = document.metadata
await db.commit()
await db.refresh(honcho_document)
# await db.refresh(honcho_document)
return honcho_document


Expand Down
17 changes: 13 additions & 4 deletions src/db.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os

from dotenv import load_dotenv
from sqlalchemy import create_engine
from sqlalchemy import MetaData, create_engine
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import declarative_base

# from sqlalchemy.ext.declarative import declarative_base

load_dotenv()

Expand All @@ -21,8 +23,15 @@
pool_pre_ping=True,
)

SessionLocal = async_sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
SessionLocal = async_sessionmaker(
autocommit=False, autoflush=False, expire_on_commit=False, bind=engine
)

table_schema = os.getenv("DATABASE_SCHEMA")
meta = MetaData()
if table_schema:
meta.schema = table_schema
Base = declarative_base(metadata=meta)


def scaffold_db():
Expand Down
Loading

0 comments on commit ddcde6b

Please sign in to comment.