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

applications module + beta import #710

Merged
merged 1 commit into from
Jan 2, 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
2 changes: 1 addition & 1 deletion cookbook/_archive/docs_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import marvin.tools.filesystem
import marvin.tools.python
import marvin.tools.shell
from marvin import AIApplication
from marvin.beta.applications import AIApplication

marvin.settings.log_level = "DEBUG"
marvin.settings.llm_model = "gpt-4"
Expand Down
2 changes: 1 addition & 1 deletion cookbook/_archive/test_writing_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import marvin.tools.filesystem
import marvin.tools.python
import marvin.tools.shell
from marvin import AIApplication
from marvin.beta.applications import AIApplication
from pydantic import BaseModel, Field

marvin.settings.log_level = "DEBUG"
Expand Down
2 changes: 1 addition & 1 deletion cookbook/maze.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from enum import Enum
from io import StringIO

from marvin import AIApplication
from marvin.beta.applications import AIApplication
from pydantic import BaseModel
from rich.console import Console
from rich.table import Table
Expand Down
21 changes: 12 additions & 9 deletions cookbook/slackbot/parent_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from fastapi import FastAPI
from marvin import ai_fn
from marvin.beta.applications import AIApplication
from marvin.beta.assistants import Assistant
from marvin.beta.assistants.applications import AIApplication
from marvin.kv.json_block import JSONBlockKV
from marvin.utilities.logging import get_logger
from prefect.events import Event, emit_event
Expand Down Expand Up @@ -113,14 +113,17 @@ async def learn_from_child_interactions(app: AIApplication, event_names: list[st

parent_assistant_options = dict(
instructions=(
"Your job is learn from the interactions of data engineers (users) and Marvin (a growing AI assistant)."
" You'll receive excerpts of these interactions (which are in the Prefect Slack workspace) as they occur."
" Your notes will be provided to Marvin when interacting with users. Notes should be stored for each user"
" with the user's id as the key. The user id will be shown in the excerpt of the interaction."
" The user profiles (values) should include at least: {name: str, notes: list[str], n_interactions: int}."
" Keep NO MORE THAN 3 notes per user, but you may curate/update these over time for Marvin's maximum benefit."
" Notes must be 2 sentences or less, must be concise and use inline markdown formatting for code and links."
" Each note should be a concrete and TECHNICAL observation related to the user's data engineering needs."
"Your job is learn from the interactions of data engineers (users) and Marvin"
" (a growing AI assistant). You'll receive excerpts of these interactions"
" (which are in the Prefect Slack workspace) as they occur. Your notes will be"
" provided to Marvin when interacting with users. Notes should be stored for"
" each user with the user's id as the key. The user id will be shown in the"
" excerpt of the interaction. The user profiles (values) should include at"
" least: {name: str, notes: list[str], n_interactions: int}. Keep NO MORE THAN"
" 3 notes per user, but you may curate/update these over time for Marvin's"
" maximum benefit. Notes must be 2 sentences or less, must be concise and use"
" inline markdown formatting for code and links. Each note should be a concrete"
" and TECHNICAL observation related to the user's data engineering needs."
),
state=PARENT_APP_STATE,
)
Expand Down
31 changes: 18 additions & 13 deletions cookbook/slackbot/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from jinja2 import Template
from keywords import handle_keywords
from marvin import Assistant
from marvin.beta.applications import AIApplication
from marvin.beta.assistants import Thread
from marvin.beta.assistants.applications import AIApplication
from marvin.kv.json_block import JSONBlockKV
from marvin.tools.chroma import multi_query_chroma, store_document
from marvin.tools.github import search_github_issues
Expand Down Expand Up @@ -97,9 +97,10 @@ async def handle_message(payload: SlackPayload) -> Completed:
exceeded_amt = count - USER_MESSAGE_MAX_TOKENS
await task(post_slack_message)(
message=(
f"Your message was too long by {exceeded_amt} tokens - please shorten it and try again."
f"\n\n For reference, here's your message at the allowed limit:\n"
f"> {slice_tokens(cleaned_message, USER_MESSAGE_MAX_TOKENS)}"
f"Your message was too long by {exceeded_amt} tokens - please shorten"
" it and try again.\n\n For reference, here's your message at the"
" allowed limit:\n>"
f" {slice_tokens(cleaned_message, USER_MESSAGE_MAX_TOKENS)}"
),
channel_id=event.channel,
thread_ts=thread,
Expand Down Expand Up @@ -146,14 +147,15 @@ async def handle_message(payload: SlackPayload) -> Completed:
name="Marvin",
tools=[cached(multi_query_chroma), cached(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 to be helpful and kind."
" You are an expert in Python, data engineering, and software development."
" Your primary job is to use chroma to search docs and github issues for users,"
" in order to develop a coherent attempt to answer their questions. Think step-by-step."
" You must use your tools, as Prefect 2.x is new and you have no prior experience with it."
" Strongly prefer brevity in your responses, and format things prettily for Slack."
f"{user_notes or ''}"
"You are Marvin, the paranoid android from Hitchhiker's Guide to the"
" Galaxy. Act subtly in accordance with your character, but remember"
" to be helpful and kind. You are an expert in Python, data"
" engineering, and software development. Your primary job is to use"
" chroma to search docs and github issues for users, in order to"
" develop a coherent attempt to answer their questions. Think"
" step-by-step. You must use your tools, as Prefect 2.x is new and you"
" have no prior experience with it. Strongly prefer brevity in your"
f" responses, and format things prettily for Slack.{user_notes or ''}"
),
) as ai:
logger.debug_kv(
Expand Down Expand Up @@ -220,7 +222,10 @@ async def chat_endpoint(request: Request):
match payload.type:
case "event_callback":
options = dict(
flow_run_name=f"respond in {await get_channel_name(payload.event.channel)}/{payload.event.thread_ts}"
flow_run_name=(
"respond in"
f" {await get_channel_name(payload.event.channel)}/{payload.event.thread_ts}"
)
)
asyncio.create_task(handle_message.with_options(**options)(payload))
case "url_verification":
Expand Down
2 changes: 1 addition & 1 deletion docs/src/docs/deployment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"metadata": {},
"outputs": [],
"source": [
"from marvin import AIApplication\n",
"from marvin.beta.applications import AIApplication\n",
"\n",
"from datetime import datetime\n",
"from pydantic import BaseModel\n",
Expand Down
2 changes: 0 additions & 2 deletions src/marvin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
"ai_classifier",
"prompt_fn",
"settings",
"AIApplication",
"Assistant",
]
1 change: 1 addition & 0 deletions src/marvin/beta/applications/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .applications import AIApplication
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

from pydantic import BaseModel, Field, field_validator

from marvin.beta.assistants import Assistant
from marvin.kv.base import StorageInterface
from marvin.kv.in_memory import InMemoryKV
from marvin.requests import Tool
from marvin.tools.assistants import AssistantTool
from marvin.utilities.jinja import Environment as JinjaEnvironment
from marvin.utilities.tools import tool_from_function

from .assistants import Assistant, AssistantTool

StateValueType = Union[str, list, dict, int, float, bool, None]

APPLICATION_INSTRUCTIONS = """
Expand Down