edgedb / edgedb-python

The official Python client library for EdgeDB
https://edgedb.com
Apache License 2.0
368 stars 44 forks source link

Create edgedb.ai package #489

Closed fantix closed 5 months ago

fantix commented 5 months ago

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())