Skip to content

Commit

Permalink
Adds notebook to typed state prototpye
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahbenizzy committed Sep 12, 2024
1 parent 43a290b commit 74cee32
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 654 deletions.
Empty file.
29 changes: 0 additions & 29 deletions examples/typed-state/application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import textwrap
from typing import AsyncGenerator, Generator, Optional, Tuple, Union

import instructor
Expand All @@ -22,10 +21,6 @@ class Concept(BaseModel):
definition: str = Field(description="A brief definition or explanation of the term.")
timestamp: float = Field(description="Timestamp when the concept is explained.")

def display(self):
minutes, seconds = divmod(self.timestamp, 60)
return f"{int(minutes)}:{int(seconds)} - {self.term}: {self.definition}"


class SocialMediaPost(BaseModel):
"""A social media post about a YouTube video generated its transcript"""
Expand All @@ -51,28 +46,6 @@ class SocialMediaPost(BaseModel):
)
youtube_url: SkipJsonSchema[Union[str, None]] = None

def display(self) -> str:
formatted_takeways = " ".join([t for t in self.key_takeaways])
formatted_concepts = "CONCEPTS\n" + "\n".join([c.display() for c in self.concepts])
link = f"link: {self.youtube_url}\n\n" if self.youtube_url else ""

return (
textwrap.dedent(
f"""\
TOPIC: {self.topic}
{self.hook}
{self.body}
{formatted_takeways}
"""
)
+ link
+ formatted_concepts
)


class ApplicationState(BaseModel):
# Make these have defaults as they are only set in actions
Expand All @@ -93,8 +66,6 @@ def get_youtube_transcript(state: ApplicationState, youtube_url: str) -> Applica
state.transcript = " ".join([f"ts={entry['start']} - {entry['text']}" for entry in transcript])
return state

# store the transcript in state


@action.pydantic(reads=["transcript"], writes=["post"])
def generate_post(state: ApplicationState, llm_client) -> ApplicationState:
Expand Down
Loading

0 comments on commit 74cee32

Please sign in to comment.