-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into fix-websurfer-tools-f…
…or-ollama
- Loading branch information
Showing
58 changed files
with
1,638 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,3 +190,5 @@ local_cache | |
notebook/result.png | ||
|
||
notebook/coding | ||
|
||
chroma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from typing import Any, Protocol, runtime_checkable\n", | ||
"\n", | ||
"from autogen import Agent\n", | ||
"\n", | ||
"\n", | ||
"class RunResponse:\n", | ||
" pass\n", | ||
"\n", | ||
"\n", | ||
"class Cost:\n", | ||
" def __init__(self, **kwargs: Any):\n", | ||
" self._cost: dict[str, Any] = kwargs.copy()\n", | ||
"\n", | ||
" @staticmethod\n", | ||
" def _add_elements(key: str, x: dict[str, Any], y: dict[str, Any]) -> Any:\n", | ||
" if key in x and key in y:\n", | ||
" return x[key] + y[key]\n", | ||
" elif key in x:\n", | ||
" return x[key]\n", | ||
" elif key in y:\n", | ||
" return y[key]\n", | ||
" else:\n", | ||
" raise KeyError(f\"Key {key} not found in either dictionary\")\n", | ||
"\n", | ||
" def __add__(self, other: \"Cost\") -> \"Cost\":\n", | ||
" keys = set(self._cost.keys()) | set(other._cost.keys())\n", | ||
" return Cost(**{key: self._add_elements(key, self._cost, other._cost) for key in keys})\n", | ||
"\n", | ||
"\n", | ||
"@runtime_checkable\n", | ||
"class EventProtocol(Protocol):\n", | ||
" @property\n", | ||
" def cost(self) -> Cost:\n", | ||
" return Cost()\n", | ||
"\n", | ||
"\n", | ||
"class RunResponse:\n", | ||
" @property\n", | ||
" def events(self) -> list[EventProtocol]:\n", | ||
" pass\n", | ||
"\n", | ||
"\n", | ||
"def run(\n", | ||
" *agents: Agent,\n", | ||
") -> RunResponse:\n", | ||
" return RunResponse" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"agents: list[Agent] = []\n", | ||
"\n", | ||
"response = run(*agents, message=\"What is the meaning of life?\")\n", | ||
"\n", | ||
"total_cost = Cost(0)\n", | ||
"for m in response.events:\n", | ||
" total_cost += m.cost\n", | ||
" if isinstance(m, InputRequest):\n", | ||
" s = input(m.prompt)\n", | ||
" m.respond(s)\n", | ||
" elif isinstance(m, OutputMessage):\n", | ||
" print(m.message)\n", | ||
" elif isinstance(m, ToolRequest):\n", | ||
" tool = m.tool" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv-3.10-core", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from typing import TYPE_CHECKING, Optional | ||
|
||
from ....doc_utils import export_module | ||
from .realtime_events import InputAudioBufferDelta, RealtimeEvent | ||
from .realtime_observer import RealtimeObserver | ||
|
||
if TYPE_CHECKING: | ||
from logging import Logger | ||
|
||
|
||
@export_module("autogen.agentchat.realtime.experimental") | ||
class AudioObserver(RealtimeObserver): | ||
"""Observer for user voice input""" | ||
|
||
def __init__(self, *, logger: Optional["Logger"] = None) -> None: | ||
"""Observer for user voice input""" | ||
super().__init__(logger=logger) | ||
|
||
async def on_event(self, event: RealtimeEvent) -> None: | ||
"""Observe voice input events from the Realtime. | ||
Args: | ||
event (dict[str, Any]): The event from the OpenAI Realtime API. | ||
""" | ||
if isinstance(event, InputAudioBufferDelta): | ||
self.logger.info("Received audio buffer delta") | ||
|
||
async def initialize_session(self) -> None: | ||
"""No need to initialize session from this observer""" | ||
pass | ||
|
||
async def run_loop(self) -> None: | ||
"""Run the observer loop.""" | ||
pass | ||
|
||
|
||
if TYPE_CHECKING: | ||
function_observer: RealtimeObserver = AudioObserver() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.