Skip to content

Commit

Permalink
relax numpy versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ProKil committed Oct 4, 2024
1 parent 08cc671 commit ea21c22
Show file tree
Hide file tree
Showing 9 changed files with 1,331 additions and 4 deletions.
17 changes: 17 additions & 0 deletions examples/audio_examples/speaker_listener.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
redis_url = "redis://localhost:6379/0"

[[nodes]]
node_name = "speaker"
node_class = "speaker"


[nodes.node_args]
input_channel = "audio_input"

[[nodes]]
node_name = "listener"
node_class = "listener"


[nodes.node_args]
output_channel = "audio_input"
61 changes: 61 additions & 0 deletions examples/chatbot_examples/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
from datetime import datetime
from typing import List, Tuple
from uuid import uuid4

from nicegui import ui

messages: List[Tuple[str, str, str, str]] = []


@ui.refreshable
def chat_messages(own_id: str) -> None:
if messages:
for user_id, avatar, text, stamp in messages:
ui.chat_message(
text=text, stamp=stamp, avatar=avatar, sent=own_id == user_id
)
else:
ui.label("No messages yet").classes("mx-auto my-36")
ui.run_javascript("window.scrollTo(0, document.body.scrollHeight)")


@ui.page("/")
async def main():
def send() -> None:
stamp = datetime.utcnow().strftime("%X")
messages.append((user_id, avatar, text.value, stamp))
text.value = ""
chat_messages.refresh()

user_id = str(uuid4())
avatar = f"https://robohash.org/{user_id}?bgset=bg2"

ui.add_css(
r"a:link, a:visited {color: inherit !important; text-decoration: none; font-weight: 500}"
)
with ui.footer().classes("bg-white"), ui.column().classes(
"w-full max-w-3xl mx-auto my-6"
):
with ui.row().classes("w-full no-wrap items-center"):
with ui.avatar().on("click", lambda: ui.navigate.to(main)):
ui.image(avatar)
text = (
ui.input(placeholder="message")
.on("keydown.enter", send)
.props("rounded outlined input-class=mx-3")
.classes("flex-grow")
)
ui.markdown("simple chat app built with [NiceGUI](https://nicegui.io)").classes(
"text-xs self-end mr-8 m-[-1em] text-primary"
)

await (
ui.context.client.connected()
) # chat_messages(...) uses run_javascript which is only possible after connecting
with ui.column().classes("w-full max-w-2xl mx-auto items-stretch"):
chat_messages(user_id)


if __name__ in {"__main__", "__mp_main__"}:
ui.run(native=True)
37 changes: 37 additions & 0 deletions examples/chatbot_examples/nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import AsyncIterator
from aact import Node, NodeFactory
from aact.messages import Message, Text

from openai import OpenAI


@NodeFactory.register("gpt4_text_chatbot_node")
class GPT4TextChatbotNode(Node[Text, Text]):
def __init__(self, input_channel: str, output_channel: str, redis_url: str):
super().__init__(
input_channel_types=[(input_channel, Text)],
output_channel_types=[(output_channel, Text)],
redis_url=redis_url,
)
self.input_channel = input_channel
self.output_channel = output_channel
self.client = OpenAI()

async def event_handler(
self, channel: str, message: Message[Text]
) -> AsyncIterator[tuple[str, Message[Text]]]:
match channel:
case self.input_channel:
response = self.client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": message.data.text},
],
)
yield (
self.output_channel,
Message[Text](data=Text(text=response.choices[0].message.content)),
)
case _:
raise ValueError(f"Unexpected channel: {channel}")
12 changes: 12 additions & 0 deletions examples/minimal_example/example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
redis_url = "redis://localhost:6379/0" # required

[[nodes]]
node_name = "print"
node_class = "print"

[nodes.node_args.print_channel_types]
"tick/secs/1" = "tick"

[[nodes]]
node_name = "tick"
node_class = "tick"
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies = [
"aiostream>=0.6.2",
"rq>=1.16.2",
"typer>=0.12.5",
"numpy>=2.1.0",
"numpy>=1.24.0",
"tomlkit>=0.13.0; python_version <= '3.10'",
]
dynamic = ["version"]
Expand All @@ -36,6 +36,13 @@ google = [
"google-cloud-speech>=2.27.0",
"google-cloud-texttospeech>=2.17.2",
]
gui = [
"nicegui",
"pywebview>=3.4.0",
]
ai = [
"openai"
]

[build-system]
requires = ["hatchling"]
Expand Down
2 changes: 1 addition & 1 deletion src/aact/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.3"
__version__ = "0.0.4"
3 changes: 2 additions & 1 deletion src/aact/messages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .base import Message, DataModel
from .commons import Zero, Tick, Image, Float, Audio
from .commons import Zero, Tick, Image, Float, Audio, Text
from .registry import DataModelFactory

__all__ = [
Expand All @@ -11,4 +11,5 @@
"DataModelFactory",
"DataModel",
"Audio",
"Text",
]
Empty file added src/aact/utils/__init__.py
Empty file.
Loading

0 comments on commit ea21c22

Please sign in to comment.