edgedb-python icon indicating copy to clipboard operation
edgedb-python copied to clipboard

Create edgedb_ai package

Open fantix opened this issue 1 year ago • 0 comments

Blocking client:

import edgedb
import edgedb.ai

c = edgedb.create_client()
gpt4ai = edgedb.ai.create_AI(c, model="gpt-4-turbo-preview")
blog_ai = gpt4ai.with_context(query="select BlogPost")
print(blog_ai.query_rag("what's that?"))

# or use event-stream:
for data in blog_ai.stream_rag("what's that?"):
    print(data)

Async client:

import asyncio
import edgedb
import edgedb.ai

c = edgedb.create_async_client()

async def main():
    gpt4ai = await edgedb.ai.create_async_AI(c, model="gpt-4-turbo-preview")
    blog_ai = gpt4ai.with_context(query="select BlogPost")
    print(await blog_ai.query_rag("what's that?"))

    # or use event-stream:
    async for data in blog_ai.stream_rag("what's that?"):
        print(data)


asyncio.run(main())

fantix avatar Apr 26 '24 22:04 fantix