Skip to content

Commit

Permalink
fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkParker5 committed Sep 20, 2023
1 parent 8bd6d49 commit 7a2e6a0
Show file tree
Hide file tree
Showing 30 changed files with 93 additions and 97 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ downloads/
site/

.DS_Store
test.py
5 changes: 3 additions & 2 deletions docs/advanced/custom-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ To kickstart your customization, replicate the default run function as your foun
import asyncer
from stark import CommandsContext, CommandsManager, Response
from stark.interfaces.protocols import SpeechRecognizer, SpeechSynthesizer
from stark.interfaces import VoskSpeechRecognizer, SileroSpeechSynthesizer
from stark.interfaces.vosk import VoskSpeechRecognizer
from stark.interfaces.silero import SileroSpeechSynthesizer
from stark.voice_assistant import VoiceAssistant
from stark.general.blockage_detector import BlockageDetector

Expand Down Expand Up @@ -170,5 +171,5 @@ async def main():
await run(manager, recognizer, synthesizer)

if __name__ == '__main__':
asyncer.runnify(main)() # or anyio.run(main()), same thing
asyncer.runnify(main)() # or anyio.run(main), same thing
```
2 changes: 1 addition & 1 deletion docs/advanced/fallback-command-llm-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CommandsContext.fallback_command: Command
Here's a practical example:

```python
from stark.types import String
from stark.core.types import String
...

@manager.new('$string:String', hidden=True)
Expand Down
5 changes: 3 additions & 2 deletions docs/first-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ At the heart of STARK is the `CommandsManager`, a component dedicated to managin
```py
import anyio
from stark import run, CommandsManager, Response
from stark.interfaces import VoskSpeechRecognizer, SileroSpeechSynthesizer
from stark.interfaces.vosk import VoskSpeechRecognizer
from stark.interfaces.silero import SileroSpeechSynthesizer


VOSK_MODEL_URL = "YOUR_CHOSEN_VOSK_MODEL_URL"
Expand All @@ -36,7 +37,7 @@ async def main():
await run(manager, recognizer, synthesizer)

if __name__ == '__main__':
anyio.run(main())
anyio.run(main)
```

In this code snippet, we defined a new command for the voice assistant. When the word "hello" is spoken, the `hello_command` function is triggered, which then issues a greeting in response.
Expand Down
2 changes: 1 addition & 1 deletion docs/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ However, ensure that the function declaration tied to a command pattern includes
Here's an example:

```python
from stark.types import Word
from stark.core.types import Word

@manager.new('Hello $name:Word')
async def example_function(name: Word) -> Response:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
pythonpath = ["stark",]
# asyncio_mode = "auto"
trio_mode = "true"
filterwarnings = [
Expand Down
21 changes: 18 additions & 3 deletions stark/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import asyncer

from stark.interfaces.protocols import SpeechRecognizer, SpeechSynthesizer
from stark.core import CommandsContext, CommandsManager
from stark.voice_assistant import VoiceAssistant
from stark.interfaces.protocols import (
SpeechRecognizer,
SpeechRecognizerDelegate,
SpeechSynthesizer,
SpeechSynthesizerResult
)
from stark.core import (
Command,
Pattern,
Response,
ResponseStatus,
CommandsContext,
CommandsManager
)
from stark.voice_assistant import (
VoiceAssistant,
Mode
)
from stark.general.blockage_detector import BlockageDetector


Expand Down
15 changes: 3 additions & 12 deletions stark/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
from .patterns import Pattern, expressions
from .types import (
ParseError,
ParseResult,
Object,
String,
Word,
# Number,
# TimeInterval
# Time,
)
from . import types
from .command import (
Command,
Response,
Expand All @@ -26,5 +17,5 @@
)


Pattern.add_parameter_type(String)
Pattern.add_parameter_type(Word)
Pattern.add_parameter_type(types.String)
Pattern.add_parameter_type(types.Word)
2 changes: 1 addition & 1 deletion stark/core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydantic import BaseModel, Field
import asyncer

from general.classproperty import classproperty
from ..general.classproperty import classproperty
from .patterns import Pattern


Expand Down
3 changes: 2 additions & 1 deletion stark/core/commands_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from typing import Any, Protocol, runtime_checkable
from dataclasses import dataclass
import warnings

import anyio
from asyncer import syncify
from asyncer._main import TaskGroup

from general.dependencies import DependencyManager, default_dependency_manager
from ..general.dependencies import DependencyManager, default_dependency_manager
from .commands_manager import CommandsManager, SearchResult
from .command import Command, Response, ResponseHandler, AsyncResponseHandler, CommandRunner, ResponseOptions

Expand Down
2 changes: 1 addition & 1 deletion stark/core/patterns/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .expressions import dictionary
if TYPE_CHECKING:
from core import Object, ParseResult
from ..types import Object, ParseResult
ObjectType: TypeAlias = Type[Object]


Expand Down
2 changes: 1 addition & 1 deletion stark/core/types/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from abc import ABC
import copy

from general.classproperty import classproperty
from stark.general.classproperty import classproperty
from .. import Pattern


Expand Down
32 changes: 0 additions & 32 deletions stark/examples/keyboard_hotkey.py

This file was deleted.

2 changes: 1 addition & 1 deletion stark/voice_assistant/mode.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations
from typing import Optional, Callable
from pydantic import BaseModel
from general.classproperty import classproperty
from ..general.classproperty import classproperty


class Mode(BaseModel):
Expand Down
13 changes: 9 additions & 4 deletions stark/voice_assistant/voice_assistant.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from typing import cast
from datetime import datetime

from core import (
from ..core import (
CommandsContext,
CommandsContextLayer,
CommandsContextDelegate,
Response,
ResponseStatus,
Pattern
)
from interfaces.protocols import SpeechRecognizer, SpeechRecognizerDelegate, SpeechSynthesizer
from ..interfaces.protocols import SpeechRecognizer, SpeechRecognizerDelegate, SpeechSynthesizer
from .mode import Mode


Expand All @@ -29,6 +30,10 @@ class VoiceAssistant(SpeechRecognizerDelegate, CommandsContextDelegate):
_last_interaction_time: datetime

def __init__(self, speech_recognizer: SpeechRecognizer, speech_synthesizer: SpeechSynthesizer, commands_context: CommandsContext):
assert isinstance(speech_recognizer, SpeechRecognizer)
assert isinstance(speech_synthesizer, SpeechSynthesizer)
assert isinstance(commands_context, CommandsContext)

self.speech_recognizer = speech_recognizer
self.speech_synthesizer = speech_synthesizer
self.commands_context = commands_context
Expand Down Expand Up @@ -110,11 +115,11 @@ async def commands_context_did_receive_response(self, response: Response):
break
else:
if self.mode.stop_after_interaction:
self.stop()
self.speech_recognizer.stop_listening()

def remove_response(self, response: Response):
if response in self._responses:
self._responses.remove(response)
self._responses.remove(cast(ResponseCache, response))

# Private

Expand Down
15 changes: 10 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
import pytest
import asyncer
import anyio
from general.dependencies import DependencyManager
from core import (
from stark.general.dependencies import DependencyManager
from stark.core import (
CommandsManager,
CommandsContext,
CommandsContextDelegate,
Response,
ResponseHandler,
AsyncResponseHandler
)
from core.types import Word
from voice_assistant import VoiceAssistant
from stark.core.types import Word
from stark.interfaces.protocols import SpeechRecognizerDelegate
from stark.voice_assistant import VoiceAssistant


class CommandsContextDelegateMock(CommandsContextDelegate):
Expand All @@ -27,10 +28,14 @@ def __init__(self):
async def commands_context_did_receive_response(self, response: Response):
self.responses.append(response)

async def remove_response(self, response: Response):
self.responses.remove(response)

class SpeechRecognizerMock:
is_recognizing: bool = False
delegate: SpeechRecognizerDelegate | None = None

def start_listening(self): pass
async def start_listening(self): pass
def stop_listening(self): pass

class SpeechSynthesizerResultMock:
Expand Down
7 changes: 4 additions & 3 deletions tests/test_commands/test_async_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import AsyncGenerator
import pytest
from core import CommandsManager, Response, ResponseHandler, AsyncResponseHandler
from stark.core import CommandsManager, Response, ResponseHandler, AsyncResponseHandler


async def test_create_run_async_command():
Expand Down Expand Up @@ -43,7 +44,7 @@ async def test_async_command_generator_yielding_response():
manager = CommandsManager()

@manager.new('foo')
async def foo() -> Response:
async def foo() -> AsyncGenerator[Response, None]:
yield Response(text = 'foo!')

i = 0
Expand All @@ -56,7 +57,7 @@ async def test_async_command_generator_multiple_yielding_response():
manager = CommandsManager()

@manager.new('foo')
async def foo() -> Response:
async def foo() -> AsyncGenerator[Response, None]:
yield Response(text = 'foo!')
yield Response(text = 'bar!')
yield Response(text = 'baz!')
Expand Down
7 changes: 4 additions & 3 deletions tests/test_commands/test_sync_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Generator
import warnings
import pytest
from asyncer import syncify
from core import CommandsManager, Response, ResponseHandler, AsyncResponseHandler
from stark.core import CommandsManager, Response, ResponseHandler, AsyncResponseHandler


async def test_create_await_run_sync_command():
Expand Down Expand Up @@ -80,7 +81,7 @@ async def test_sync_command_generator_yielding_response():

with warnings.catch_warnings(record = True) as warnings_list:
@manager.new('foo')
def foo() -> Response:
def foo() -> Generator[Response, None, None]:
yield Response(text = 'foo!')

assert next(await foo()).text == 'foo!'
Expand All @@ -94,7 +95,7 @@ async def test_sync_command_generator_multiple_yielding_response():

with warnings.catch_warnings(record = True) as warnings_list:
@manager.new('foo')
def foo() -> Response:
def foo() -> Generator[Response, None, None]:
yield Response(text = 'foo!')
yield Response(text = 'bar!')
yield Response(text = 'baz!')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings
import pytest
import anyio
from core import Response
from stark.core import Response


async def test_commands_context_handle_async_generator(commands_context_flow, autojump_clock):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import anyio
from core import AsyncResponseHandler, Response
from stark.core import AsyncResponseHandler, Response


async def test_commands_context_inject_dependencies(commands_context_flow, autojump_clock):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_commands_flow/test_commands_context_respond.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import warnings
import anyio
from core import Response, ResponseHandler, AsyncResponseHandler
from stark.core import Response, ResponseHandler, AsyncResponseHandler


async def test_command_return_response(commands_context_flow, autojump_clock):
Expand Down Expand Up @@ -51,7 +51,7 @@ async def test_sync_command_call_async_respond(commands_context_flow, autojump_c
def foo(handler: AsyncResponseHandler):
with warnings.catch_warnings(record = True) as warnings_list:
assert len(warnings_list) == 0
handler.respond(Response(text = 'foo!'))
handler.respond(Response(text = 'foo!')) # type: ignore
assert len(warnings_list) == 1
assert issubclass(warnings_list[0].category, RuntimeWarning)
assert 'was never awaited' in str(warnings_list[0].message)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_commands_flow/test_commands_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import pytest
from core import CommandsManager, Word
from stark.core import CommandsManager
from stark.core.types import Word


def test_new():
Expand Down
5 changes: 3 additions & 2 deletions tests/test_commands_flow/test_multiple_commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
import anyio
from core import Object, Pattern, Response, CommandsManager
from general.classproperty import classproperty
from stark.core import Pattern, Response, CommandsManager
from stark.core.types import Object
from stark.general.classproperty import classproperty
import random


Expand Down
Loading

0 comments on commit 7a2e6a0

Please sign in to comment.