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

rm caching for now, more sane token scoop #729

Merged
merged 1 commit into from
Jan 9, 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
9 changes: 1 addition & 8 deletions cookbook/slackbot/start.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import asyncio
import re
from datetime import timedelta
from typing import Callable

import uvicorn
from fastapi import FastAPI, HTTPException, Request
Expand All @@ -28,17 +26,12 @@
)
from prefect import flow, task
from prefect.states import Completed
from prefect.tasks import task_input_hash

BOT_MENTION = r"<@(\w+)>"
CACHE = JSONBlockState(block_name="marvin-thread-cache")
USER_MESSAGE_MAX_TOKENS = 300


def cached(func: Callable) -> Callable:
return task(cache_key_fn=task_input_hash, cache_expiration=timedelta(days=1))(func)


async def get_notes_for_user(
user_id: str, max_tokens: int = 100
) -> dict[str, str | None]:
Expand Down Expand Up @@ -145,7 +138,7 @@ async def handle_message(payload: SlackPayload) -> Completed:

with Assistant(
name="Marvin",
tools=[cached(multi_query_chroma), cached(search_github_issues)],
tools=[multi_query_chroma, search_github_issues],
instructions=(
"You are Marvin, the paranoid android from Hitchhiker's Guide to the"
" Galaxy. Act subtly in accordance with your character, but remember"
Expand Down
12 changes: 6 additions & 6 deletions src/marvin/utilities/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ async def get_token() -> str:
marvin.settings.slack_api_token
) # set `MARVIN_SLACK_API_TOKEN` in `~/.marvin/.env
except AttributeError:
if token := os.getenv("MARVIN_SLACK_API_TOKEN"):
return token
try: # TODO: clean this up
from prefect.blocks.system import Secret

return (await Secret.load("slack-api-token")).get()
except ImportError:
pass
token = os.getenv("MARVIN_SLACK_API_TOKEN")
if not token:
raise ValueError(
"`MARVIN_SLACK_API_TOKEN` not found in environment."
" Please set it in `~/.marvin/.env` or as an environment variable."
)
raise ValueError(
"`MARVIN_SLACK_API_TOKEN` not found in environment."
" Please set it in `~/.marvin/.env` or as an environment variable."
)
return token


Expand Down