Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from UUIDv4 to NanoID #71

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 0 additions & 8 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ CONNECTION_URI=postgresql+psycopg://testuser:testpwd@localhost:5432/honcho # sam
# CONNECTION_URI=postgresql+psycopg://testuser:testpwd@database:5432/honcho # sample for docker-compose database

OPENAI_API_KEY=
ANTHROPIC_API_KEY=

# Azure

AZURE_OPENAI_ENDPOINT=
AZURE_OPENAI_API_KEY=
AZURE_OPENAI_API_VERSION=
AZURE_OPENAI_DEPLOYMENT=

# Logging

Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ jobs:
SENTRY_ENABLED: false
OPENTELEMETRY_ENABLED: false
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_API_VERSION: ${{ secrets.AZURE_OPENAI_API_VERSION }}
AZURE_OPENAI_DEPLOYMENT: ${{ secrets.AZURE_OPENAI_DEPLOYMENT }}
AZURE_OPENAI_EMBED_DEPLOYMENT: ${{ secrets.AZURE_OPENAI_EMBED_DEPLOYMENT }}



1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies = [
"rich>=13.7.1",
"mirascope>=0.18.0",
"openai>=1.43.0",
"nanoid>=2.0.0",
]
[tool.uv]
dev-dependencies = [
Expand All @@ -33,6 +34,7 @@ dev-dependencies = [
"pytest-asyncio>=0.23.7",
"coverage>=7.6.0",
"interrogate>=1.7.0",
"py-spy>=0.3.14",
]

[tool.ruff.lint]
Expand All @@ -56,5 +58,6 @@ ignore = ["E501"]
[tool.ruff.flake8-bugbear]
extend-immutable-calls = ["fastapi.Depends"]

[tool.lpytest.ini_options]
[tool.pytest.ini_options]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "session"
46 changes: 15 additions & 31 deletions src/agent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import asyncio
import os
import uuid
from typing import Iterable, Set
from collections.abc import Iterable

from dotenv import load_dotenv
from mirascope.base import BaseConfig
from mirascope.openai import OpenAICall, OpenAICallParams, azure_client_wrapper
from mirascope.openai import OpenAICall, OpenAICallParams

from src import crud, schemas
from src.db import SessionLocal
Expand All @@ -15,7 +12,7 @@

class AsyncSet:
def __init__(self):
self._set: Set[str] = set()
self._set: set[str] = set()
self._lock = asyncio.Lock()

async def add(self, item: str):
Expand All @@ -26,7 +23,7 @@ async def update(self, items: Iterable[str]):
async with self._lock:
self._set.update(items)

def get_set(self) -> Set[str]:
def get_set(self) -> set[str]:
return self._set.copy()


Expand All @@ -44,23 +41,10 @@ class Dialectic(OpenAICall):
retrieved_facts: str
chat_history: list[str]

configuration = BaseConfig(
client_wrappers=[
azure_client_wrapper(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
)
]
)
call_params = OpenAICallParams(
model=os.getenv("AZURE_OPENAI_DEPLOYMENT"), temperature=1.2, top_p=0.5
)
call_params = OpenAICallParams(model="gpt-4o", temperature=1.2, top_p=0.5)


async def chat_history(
app_id: uuid.UUID, user_id: uuid.UUID, session_id: uuid.UUID
) -> list[str]:
async def chat_history(app_id: str, user_id: str, session_id: str) -> list[str]:
async with SessionLocal() as db:
stmt = await crud.get_messages(db, app_id, user_id, session_id)
results = await db.execute(stmt)
Expand All @@ -75,8 +59,8 @@ async def chat_history(


async def prep_inference(
app_id: uuid.UUID,
user_id: uuid.UUID,
app_id: str,
user_id: str,
query: str,
collection_name: str,
) -> None | list[str]:
Expand All @@ -101,8 +85,8 @@ async def prep_inference(


async def generate_facts(
app_id: uuid.UUID,
user_id: uuid.UUID,
app_id: str,
user_id: str,
fact_set: AsyncSet,
collection_name: str,
questions: list[str],
Expand All @@ -116,8 +100,8 @@ async def fetch_facts(query):


async def fact_generator(
app_id: uuid.UUID,
user_id: uuid.UUID,
app_id: str,
user_id: str,
collections: list[str],
questions: list[str],
):
Expand All @@ -134,9 +118,9 @@ async def fact_generator(


async def chat(
app_id: uuid.UUID,
user_id: uuid.UUID,
session_id: uuid.UUID,
app_id: str,
user_id: str,
session_id: str,
query: schemas.AgentQuery,
stream: bool = False,
):
Expand Down
Loading