PrefectHQ / marvin

✨ Build AI interfaces that spark joy
https://askmarvin.ai
Apache License 2.0
5.34k stars 348 forks source link

AI Jupyter App #553

Closed ormwish closed 1 year ago

ormwish commented 1 year ago

AI Notebooks Writer (Jupyter)

Write what's important — we will conduct your thoughts with appropriate tracing. Want make the idea tested — make an experiment. You can't do all the stuff alone — our AIAPPS will help you focus on creativity — not on the routine. AI interfaces to everything with state and planners (optionally).

App Overview

This application allows users to interact with a Jupyter Notebook environment through a conversational AI assistant. It is powered by the marvin library and deployed as a Docker container.

Abstract

This project is an experiment built upon the Marvin AI — a framework aimed to help developers.

Main Components

README.md

The README provides an overview of the application and its capabilities. It mentions that it is built with marvin and serves as a FastAPI endpoint.

Dockerfile

The Dockerfile contains instructions for building the Docker image that will run the application.

docker-compose.yml

This file defines the Docker services required by the application, such as the FastAPI server and any databases or other dependencies.

requirements.txt

This lists the Python package dependencies needed by the application.

src/

This directory contains the Python source code for the application.

src/__init__.py

This initializes the Python package.

src/app.py

This file implements the core logic of the conversational assistant, including interpreting user requests, executing actions, and managing state.

src/main.py

This launches the FastAPI application and any required services.

src/models.py

This defines Pydantic models for the application state and any data storage.

tests/

This directory contains unit tests for the application.

tests/__init__.py

This initializes the test package.

tests/test_app.py

This contains test cases to validate the application logic and components.

Implementation Suggestions

Here is one way the application could be implemented based on the proposed structure:

Main Application File

The src/app.py file would contain the main FastAPI application and route handlers.

# src/app.py

from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse

from .models import ConversationState, NotebookSpec
from .notebook import NotebookManager

app = FastAPI()

state = ConversationState()
notebooks = NotebookManager()

@app.post("/converse")
async def converse(request: Request):
    """Handle conversation turn"""

    utterance = await request.json()

    # Update conversation state
    state.update(utterance)

    if state.wants_create_notebook():
        notebook = notebooks.create_notebook(state.notebook_spec)
        return JSONResponse({"create_notebook": notebook.id})

    # Additional handlers for other intents...

    return JSONResponse({"message": "OK"})

Pydantic Models

The Pydantic models could be defined as follows:

# src/models.py

from pydantic import BaseModel
from typing import Optional

class ConversationState(BaseModel):
    """State of conversation with user"""

    context: dict = {}
    intent: Optional[str] = None

    def update(self, utterance):
        """Update state based on the latest user utterance"""
        # NLU logic to extract intent and entities
        self.context["utterances"].append(utterance)

        if intent == "create_notebook":
            self.intent = intent
            self.notebook_spec = NotebookSpec(**entities)

class NotebookSpec(BaseModel):
    """Spec for notebook to create"""

    topic: str
    output_path: str

Base AI App implementation

Following the lead — make this robust implementation of AI Application.

ormwish commented 1 year ago

Sorry guys, wrong upstream. Not ready yet.