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

fix(py/core): introduced ai.run_main method that executes async fn … #2591

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 12 additions & 1 deletion py/packages/genkit-ai/src/genkit/ai/veneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async def foo(...):
from genkit.ai.plugin import Plugin
from genkit.ai.registry import GenkitRegistry
from genkit.aio import Channel
from genkit.aio.loop import create_loop
from genkit.aio.loop import create_loop, run_async
from genkit.blocks.document import Document
from genkit.blocks.embedding import EmbedRequest, EmbedResponse
from genkit.blocks.formats import built_in_formats
Expand Down Expand Up @@ -190,6 +190,17 @@ def join(self):
if self.thread and self.loop:
self.thread.join()

def run_main(self, main):
if self.loop:

async def run():
return await main

run_async(self.loop, run)
else:
asyncio.run(main)
self.join()

def start_server(self, spec: server.ServerSpec, loop: asyncio.AbstractEventLoop) -> None:
"""Start the HTTP server for handling requests.

Expand Down
7 changes: 1 addition & 6 deletions py/samples/hello-google-genai/src/hello_google_genai.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,4 @@ async def main() -> None:


if __name__ == '__main__':
asyncio.run(main())


# prevent app from exiting when genkit is running in dev mode
# TODO: Clean this up.
ai.join()
ai.run_main(main())
Loading