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

Support OpenAI Assistants API #601

Merged
merged 20 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
16 changes: 8 additions & 8 deletions examples/voice-assistant/minimal_assistant.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to review this file. It won't be included in the PR. Just using it for testing

Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@


async def entrypoint(ctx: JobContext):
initial_ctx = llm.ChatContext().append(
role="system",
text=(
"You are a voice assistant created by LiveKit. Your interface with users will be voice. "
"You should use short and concise responses, and avoiding usage of unpronouncable punctuation."
),
)
initial_ctx = llm.ChatContext()

await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)

assistant = VoiceAssistant(
vad=silero.VAD.load(),
stt=deepgram.STT(),
llm=openai.LLM(),
llm=openai.AssistantLLM(
assistant_opts=openai.AssistantCreateOptions(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I'm already using assistant API today.. is there a one to one mapping for the options?

model="gpt-4o",
instructions="You are a voice assistant created by LiveKit. Your interface with users will be voice.",
name="KITT",
)
),
tts=openai.TTS(),
chat_ctx=initial_ctx,
)
Expand Down
2 changes: 2 additions & 0 deletions livekit-agents/livekit/agents/llm/chat_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ChatMessage:
content: str | list[str | ChatImage] | None = None
tool_calls: list[function_context.FunctionCallInfo] | None = None
tool_call_id: str | None = None
_metadata: dict[str, Any] = field(default_factory=dict, repr=False, init=False)

@staticmethod
def create_tool_from_called_function(
Expand Down Expand Up @@ -104,6 +105,7 @@ def copy(self):
@dataclass
class ChatContext:
messages: list[ChatMessage] = field(default_factory=list)
_metadata: dict[str, Any] = field(default_factory=dict, repr=False, init=False)

def append(
self, *, text: str = "", images: list[ChatImage] = [], role: ChatRole = "system"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .assistant_llm import (
AssistantCreateOptions,
AssistantLLM,
AssistantLLMStream,
AssistantLoadOptions,
AssistantOptions,
)
from .embeddings import EmbeddingData, create_embeddings
from .llm import LLM, LLMStream
from .models import TTSModels, TTSVoices, WhisperModels
Expand All @@ -24,6 +31,11 @@
"TTS",
"LLM",
"LLMStream",
"AssistantOptions",
"AssistantCreateOptions",
"AssistantLoadOptions",
"AssistantLLM",
"AssistantLLMStream",
"WhisperModels",
"TTSModels",
"TTSVoices",
Expand Down
Loading
Loading