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

Add support for max_reponse_output_tokens in options #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/realtime_ai/aio/realtime_ai_service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ async def update_session(self, options: RealtimeAIOptions) -> dict:
"turn_detection": options.turn_detection,
"tools": options.tools,
"tool_choice": options.tool_choice,
"temperature": options.temperature
"temperature": options.temperature,
"max_response_output_tokens": options.max_output_tokens
}
}
await self.send_event(event)
Expand Down
13 changes: 7 additions & 6 deletions src/realtime_ai/audio_stream_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ def _start_stream(self):
logger.info("Audio streaming started.")

def stop_stream(self):
if self._is_streaming:
self._is_streaming = False
self._stop_event.set() # Signal to the thread to stop
if self._stream_thread:
self._stream_thread.join()
logger.info("Audio streaming stopped.")
with self._lock:
if self._is_streaming:
self._is_streaming = False
self._stop_event.set() # Signal to the thread to stop
if self._stream_thread:
self._stream_thread.join()
logger.info("Audio streaming stopped.")

def write_audio_buffer_sync(self, audio_data: bytes):
with self._lock:
Expand Down
4 changes: 2 additions & 2 deletions src/realtime_ai/models/realtime_ai_options.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import List, Optional, Dict, Any
from typing import List, Optional, Dict, Any, Union


@dataclass
Expand All @@ -26,7 +26,7 @@ class RealtimeAIOptions:
tools: List[Dict[str, Any]] = field(default_factory=list)
tool_choice: str = "auto"
temperature: float = 0.8
max_output_tokens: Optional[int] = None
max_output_tokens: Union[int, str] = "inf"
enable_auto_reconnect: bool = False

def __post_init__(self):
Expand Down
3 changes: 2 additions & 1 deletion src/realtime_ai/realtime_ai_service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def update_session(self, options: RealtimeAIOptions) -> dict:
"turn_detection": options.turn_detection,
"tools": options.tools,
"tool_choice": options.tool_choice,
"temperature": options.temperature
"temperature": options.temperature,
"max_response_output_tokens": options.max_output_tokens
}
}
self.send_event(event)
Expand Down