Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2ce0014
generated sqlite code
mkorpela Apr 11, 2024
34c40ba
go install -tags sqlite3 github.com/golang-migrate/migrate/v4/cmd/mig…
mkorpela Apr 11, 2024
f3e4cd3
make everything awaitable
mkorpela Apr 11, 2024
2c6fcde
sqlite
mkorpela Apr 12, 2024
c584c75
listing assistants
mkorpela Apr 12, 2024
6ad76e9
more working
mkorpela Apr 15, 2024
775e1cc
Add Chroma vectorstore.
bakar-io Apr 17, 2024
1df1076
Update checkpointer.
bakar-io Apr 17, 2024
d251e84
Add aiosqlite dependency.
bakar-io Apr 21, 2024
0a29bfb
Separete storage methods for pg and sqlite.
bakar-io Apr 21, 2024
827b96f
Separate postgres and sqlite migrations.
bakar-io Apr 21, 2024
ce0f462
Fix circular import.
bakar-io Apr 22, 2024
326e46c
Prevent concurrent requests from raising UniqueViolationError for pg'…
bakar-io Apr 22, 2024
e078dfa
Merge branch 'langchain-main' into pg-sqlite
bakar-io Apr 22, 2024
755dd15
Format.
bakar-io Apr 22, 2024
5fa0483
poetry lock --no-update.
bakar-io Apr 22, 2024
74b9c2c
Fix SqliteCheckpointer's init.
bakar-io Apr 22, 2024
36dbed8
Include STORAGE_TYPE in the make test command.
bakar-io Apr 22, 2024
5a49941
Use storage settings during tests.
bakar-io Apr 22, 2024
735ce54
Update readme.
bakar-io Apr 22, 2024
5b98719
Temporarily use PGVector for both sqlite and postgres.
bakar-io Apr 30, 2024
c5cc23e
Cleanup.
bakar-io Apr 30, 2024
84543cd
Merge branch 'langchain-main' into pg-sqlite
bakar-io Apr 30, 2024
3fd7d6a
Update public assistants storage method.
bakar-io Apr 30, 2024
edf3d0b
Add a TODO comment for the future.
bakar-io Apr 30, 2024
d5c3327
Minor fixes and cleanup.
bakar-io Apr 30, 2024
b0ff0ca
Create storage setup and teardown methods.
bakar-io May 3, 2024
c1d78c7
Merge branch 'main' into pg-sqlite
bakar-io May 3, 2024
37b2413
poetry lock --no-update
bakar-io May 3, 2024
bf3bd82
Clean up PostgresStorage.
bakar-io May 3, 2024
5e2a9dd
WIP/POC sharing a single sqlite connection across the application.
bakar-io May 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# Local db files
chroma_db/
opengpts.db
2 changes: 1 addition & 1 deletion backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ start:
poetry run uvicorn app.server:app --reload --port 8100

migrate:
migrate -database postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST):$(POSTGRES_PORT)/$(POSTGRES_DB)?sslmode=disable -path ./migrations up
migrate -database sqlite3://$(PWD)/opengpts.db -path ./migrations up

test:
# We need to update handling of env variables for tests
Expand Down
4 changes: 2 additions & 2 deletions backend/app/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from app.agent_types.tools_agent import get_tools_agent_executor
from app.agent_types.xml_agent import get_xml_agent_executor
from app.chatbot import get_chatbot_executor
from app.checkpoint import PostgresCheckpoint
from app.checkpoint import SQLiteCheckpoint
from app.llms import (
get_anthropic_llm,
get_google_llm,
Expand Down Expand Up @@ -70,7 +70,7 @@ class AgentType(str, Enum):

DEFAULT_SYSTEM_MESSAGE = "You are a helpful assistant."

CHECKPOINTER = PostgresCheckpoint(at=CheckpointAt.END_OF_STEP)
CHECKPOINTER = SQLiteCheckpoint(at=CheckpointAt.END_OF_STEP)


def get_agent_executor(
Expand Down
12 changes: 6 additions & 6 deletions backend/app/api/assistants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class AssistantPayload(BaseModel):


@router.get("/")
async def list_assistants(user: AuthedUser) -> List[Assistant]:
def list_assistants(user: AuthedUser) -> List[Assistant]:
"""List all assistants for the current user."""
return await storage.list_assistants(user["user_id"])
return storage.list_assistants(user["user_id"])


@router.get("/public/")
Expand All @@ -37,7 +37,7 @@ async def list_public_assistants(
] = None,
) -> List[Assistant]:
"""List all public assistants."""
return await storage.list_public_assistants(
return storage.list_public_assistants(
FEATURED_PUBLIC_ASSISTANTS + ([shared_id] if shared_id else [])
)

Expand All @@ -48,7 +48,7 @@ async def get_assistant(
aid: AssistantID,
) -> Assistant:
"""Get an assistant by ID."""
assistant = await storage.get_assistant(user["user_id"], aid)
assistant = storage.get_assistant(user["user_id"], aid)
if not assistant:
raise HTTPException(status_code=404, detail="Assistant not found")
return assistant
Expand All @@ -60,7 +60,7 @@ async def create_assistant(
payload: AssistantPayload,
) -> Assistant:
"""Create an assistant."""
return await storage.put_assistant(
return storage.put_assistant(
user["user_id"],
str(uuid4()),
name=payload.name,
Expand All @@ -76,7 +76,7 @@ async def upsert_assistant(
payload: AssistantPayload,
) -> Assistant:
"""Create or update an assistant."""
return await storage.put_assistant(
return storage.put_assistant(
user["user_id"],
aid,
name=payload.name,
Expand Down
4 changes: 2 additions & 2 deletions backend/app/api/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class CreateRunPayload(BaseModel):


async def _run_input_and_config(payload: CreateRunPayload, user_id: str):
thread = await get_thread(user_id, payload.thread_id)
thread = get_thread(user_id, payload.thread_id)
if not thread:
raise HTTPException(status_code=404, detail="Thread not found")

assistant = await get_assistant(user_id, str(thread["assistant_id"]))
assistant = get_assistant(user_id, str(thread["assistant_id"]))
if not assistant:
raise HTTPException(status_code=404, detail="Assistant not found")

Expand Down
27 changes: 11 additions & 16 deletions backend/app/api/threads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
from typing import Annotated, Any, Dict, List, Sequence, Union
from uuid import uuid4

Expand Down Expand Up @@ -32,7 +31,7 @@ class ThreadPostRequest(BaseModel):
@router.get("/")
async def list_threads(user: AuthedUser) -> List[Thread]:
"""List all threads for the current user."""
return await storage.list_threads(user["user_id"])
return storage.list_threads(user["user_id"])


@router.get("/{tid}/state")
Expand All @@ -41,10 +40,8 @@ async def get_thread_state(
tid: ThreadID,
):
"""Get state for a thread."""
thread, state = await asyncio.gather(
storage.get_thread(user["user_id"], tid),
storage.get_thread_state(user["user_id"], tid),
)
thread = storage.get_thread(user["user_id"], tid)
state = storage.get_thread_state(user["user_id"], tid)
if not thread:
raise HTTPException(status_code=404, detail="Thread not found")
return state
Expand All @@ -57,10 +54,10 @@ async def add_thread_state(
payload: ThreadPostRequest,
):
"""Add state to a thread."""
thread = await storage.get_thread(user["user_id"], tid)
thread = storage.get_thread(user["user_id"], tid)
if not thread:
raise HTTPException(status_code=404, detail="Thread not found")
return await storage.update_thread_state(user["user_id"], tid, payload.values)
return storage.update_thread_state(user["user_id"], tid, payload.values)


@router.get("/{tid}/history")
Expand All @@ -69,10 +66,8 @@ async def get_thread_history(
tid: ThreadID,
):
"""Get all past states for a thread."""
thread, history = await asyncio.gather(
storage.get_thread(user["user_id"], tid),
storage.get_thread_history(user["user_id"], tid),
)
thread = storage.get_thread(user["user_id"], tid)
history = storage.get_thread_history(user["user_id"], tid)
if not thread:
raise HTTPException(status_code=404, detail="Thread not found")
return history
Expand All @@ -84,7 +79,7 @@ async def get_thread(
tid: ThreadID,
) -> Thread:
"""Get a thread by ID."""
thread = await storage.get_thread(user["user_id"], tid)
thread = storage.get_thread(user["user_id"], tid)
if not thread:
raise HTTPException(status_code=404, detail="Thread not found")
return thread
Expand All @@ -96,7 +91,7 @@ async def create_thread(
thread_put_request: ThreadPutRequest,
) -> Thread:
"""Create a thread."""
return await storage.put_thread(
return storage.put_thread(
user["user_id"],
str(uuid4()),
assistant_id=thread_put_request.assistant_id,
Expand All @@ -111,7 +106,7 @@ async def upsert_thread(
thread_put_request: ThreadPutRequest,
) -> Thread:
"""Update a thread."""
return await storage.put_thread(
return storage.put_thread(
user["user_id"],
tid,
assistant_id=thread_put_request.assistant_id,
Expand All @@ -125,5 +120,5 @@ async def delete_thread(
tid: ThreadID,
):
"""Delete a thread by ID."""
await storage.delete_thread(user["user_id"], tid)
storage.delete_thread(user["user_id"], tid)
return {"status": "ok"}
4 changes: 2 additions & 2 deletions backend/app/auth/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NOOPAuth(AuthHandler):

async def __call__(self, request: Request) -> User:
sub = request.cookies.get("opengpts_user_id") or self._default_sub
user, _ = await storage.get_or_create_user(sub)
user, _ = storage.get_or_create_user(sub)
return user


Expand All @@ -37,7 +37,7 @@ async def __call__(self, request: Request) -> User:
except jwt.PyJWTError as e:
raise HTTPException(status_code=401, detail=str(e))

user, _ = await storage.get_or_create_user(payload["sub"])
user, _ = storage.get_or_create_user(payload["sub"])
return user

@abstractmethod
Expand Down
Loading