-
Notifications
You must be signed in to change notification settings - Fork 51
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
Simplify entry file heuristics #9
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-FileCopyrightText: 2024 LiveKit, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import type { JobContext } from './job_context.js'; | ||
|
||
type entryFunction = (job: JobContext) => Promise<void>; | ||
|
||
export interface Agent { | ||
entry: entryFunction; | ||
} | ||
|
||
/** | ||
* Helper to define an agent according to the required interface. | ||
* @example `export default defineAgent(myAgent);` | ||
*/ | ||
export function defineAgent(entry: entryFunction): Agent { | ||
return { entry }; | ||
} |
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
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
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 |
---|---|---|
@@ -1,23 +1,22 @@ | ||
// SPDX-FileCopyrightText: 2024 LiveKit, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { type JobContext, type JobRequest, WorkerOptions, cli } from '@livekit/agents'; | ||
import { type JobContext, type JobRequest, WorkerOptions, cli, defineAgent } from '@livekit/agents'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
// your entry file *has* to include an exported function [entry]. | ||
// this file will be imported from inside the library, and this function | ||
// will be called. | ||
export const entry = async (job: JobContext) => { | ||
console.log('starting voice assistant...'); | ||
job; | ||
// etc | ||
}; | ||
|
||
const requestFunc = async (req: JobRequest) => { | ||
console.log('received request', req); | ||
await req.accept(__filename); | ||
await req.accept(import.meta.filename); | ||
}; | ||
|
||
if (process.argv[1] === fileURLToPath(import.meta.url)) { | ||
cli.runApp(new WorkerOptions({ requestFunc })); | ||
} | ||
|
||
// your entry file has to provide a default export of type Agent. | ||
// use the defineAgent() helper function to generate your agent. | ||
export default defineAgent(async (job: JobContext) => { | ||
console.log('starting voice assistant...'); | ||
job; | ||
// etc | ||
}); |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it return
Promise<void | () => void>
to reflect that it could return a function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it return anything? all of the examples on Python's agents return void, and regardless we don't do anything with the potential return value of this function, we just run it.
there's no reason to return anything because there's nowhere to return it to
if we really want to allow returning things for whatever reason we should replace void with
unknown
to prevent type errorsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the confusion is my fault, I thought it'd be nice to provide some sort of resource cleanup functionality, but I thought about it just in terms of API and not in terms of what's already implemented... I guess that we should just remove the comment that mentions the return cleanup function and leave the return type as
Promise<void>
.