Skip to content

Commit

Permalink
Found bug in mirascope that requires an empty OPENAI_API_KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
VVoruganti committed Sep 2, 2024
1 parent 6b21e33 commit 8f8be74
Show file tree
Hide file tree
Showing 7 changed files with 654 additions and 515 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV PYTHONFAULTHANDLER=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.4.1
POETRY_VERSION=1.8.3

RUN pip install "poetry==$POETRY_VERSION"

Expand All @@ -23,7 +23,7 @@ COPY poetry.lock pyproject.toml /app/

# Project initialization:
RUN poetry config virtualenvs.create false \
&& poetry install --no-root --no-interaction --no-ansi --without dev
&& poetry install --no-root --no-interaction --no-ansi

WORKDIR /app

Expand All @@ -36,5 +36,5 @@ COPY --chown=app:app src/ /app/src/
EXPOSE 8000

# https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker
CMD ["python", "-m", "fastapi", "run", "src/main.py"]
CMD ["fastapi", "run", "src/main.py"]

2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kill_timeout = '5s'
[build]

[processes]
api = 'python -m fastapi run src/main.py'
api = 'fastapi run src/main.py'
deriver = 'python -m src.deriver'

[http_service]
Expand Down
1,133 changes: 635 additions & 498 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.0.11"
description = "Honcho Server"
authors = ["Plastic Labs <[email protected]>"]
readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.9"
Expand All @@ -12,18 +13,18 @@ python-dotenv = "^1.0.0"
sqlalchemy = "^2.0.30"
fastapi-pagination = "^0.12.24"
pgvector = "^0.2.5"
openai = "^1.12.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"
mirascope = "^0.18.2"
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"
rich = "^13.7.1"
mirascope = "^0.18.0"
openai = "^1.43.0"

[tool.poetry.group.test.dependencies]
pytest = "^8.2.2"
Expand Down
18 changes: 8 additions & 10 deletions src/deriver/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ async def process_ai_message(
result = await db.execute(messages_stmt)
messages = result.scalars().all()[::-1]

chat_history_str = "\n".join(
[f"human: {m.content}" if m.is_user else f"ai: {m.content}" for m in messages]
)
chat_history_str = "\n".join([
f"human: {m.content}" if m.is_user else f"ai: {m.content}" for m in messages
])
# append current message to chat history
chat_history_str = f"{chat_history_str}\nai: {content}"

# user prediction thought
user_prediction_thought = UserPredictionThought(chat_history=chat_history_str)
user_prediction_thought_response = await user_prediction_thought.call_async()
user_prediction_thought_response = user_prediction_thought.call()

## query the collection to build the context
additional_data = re.findall(
Expand Down Expand Up @@ -132,9 +132,7 @@ async def process_ai_message(
retrieved_context=context_str,
chat_history=chat_history_str,
)
user_prediction_thought_revision_response = (
await user_prediction_thought_revision.call_async()
)
user_prediction_thought_revision_response = user_prediction_thought_revision.call()

if user_prediction_thought_revision_response.content == "None":
rprint("[blue]Model predicted no changes to the user prediction thought")
Expand Down Expand Up @@ -245,7 +243,7 @@ async def process_user_message(
voe_thought = VoeThought(
user_prediction_thought_revision=metamessage.content, actual=content
)
voe_thought_response = await voe_thought.call_async()
voe_thought_response = voe_thought.call()

# VoE derive facts
voe_derive_facts = VoeDeriveFacts(
Expand All @@ -254,7 +252,7 @@ async def process_user_message(
actual=content,
voe_thought=voe_thought_response.content,
)
voe_derive_facts_response = await voe_derive_facts.call_async()
voe_derive_facts_response = voe_derive_facts.call()

# debugging
rprint("[orange1]=================")
Expand Down Expand Up @@ -329,7 +327,7 @@ async def check_dups(

check_duplication.existing_facts = existing_facts
check_duplication.new_fact = fact
response = await check_duplication.call_async()
response = check_duplication.call()
rprint("[light_steel_blue]==================")
rprint(f"[light_steel_blue]Dedupe Responses: {response.content}")
rprint("[light_steel_blue]==================")
Expand Down
3 changes: 2 additions & 1 deletion src/deriver/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ async def schedule_session(
async with semaphore, SessionLocal() as db:
try:
available_slots = semaphore._value
print(available_slots)
new_sessions = await get_available_sessions(db, available_slots)

if new_sessions:
Expand Down Expand Up @@ -152,6 +153,6 @@ async def main():
AsyncioIntegration(),
],
)
semaphore = asyncio.Semaphore(5) # Limit to 5 concurrent dequeuing operations
semaphore = asyncio.Semaphore(6) # Limit to 5 concurrent dequeuing operations
queue_empty_flag = asyncio.Event() # Event to signal when the queue is empty
await polling_loop(semaphore, queue_empty_flag)
2 changes: 2 additions & 0 deletions src/deriver/voe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

from mirascope.base import BaseConfig
from mirascope.openai import OpenAICall, OpenAICallParams, azure_client_wrapper
from pydantic import ConfigDict


class HonchoCall(OpenAICall):
model_config = ConfigDict(arbitrary_types_allowed=True)
configuration = BaseConfig(
client_wrappers=[
azure_client_wrapper(
Expand Down

0 comments on commit 8f8be74

Please sign in to comment.