MagnivOrg / prompt-layer-library

🍰 PromptLayer - Maintain a log of your prompts and OpenAI API requests. Track, debug, and replay old completions.
https://www.promptlayer.com
Apache License 2.0
485 stars 44 forks source link

Object of type coroutine is not JSON serializable #3

Closed jxnl closed 1 year ago

jxnl commented 1 year ago

when running an acreate with streaming=true ran into a serialization issue.

WARNING: While logging your request PromptLayer had the following error: Object of type coroutine is not JSON serializable
    async def call() -> AsyncGenerator[str, None]:
        response = await openai.Completion.acreate(
            engine=engine,
            prompt=prompt,
            stream=True,
        )
Jped commented 1 year ago

@jxnl What version of PromptLayer are you using?

I just ran this:

async def call():
    response = await openai.Completion.acreate(
        engine="davinci",
        prompt=prompt,
        stream=True,
    )
    return response

async def main():
    stream_response = await call()
    async for s in stream_response:
        print(s)

asyncio.run(main())

and it worked for me

jxnl commented 1 year ago

wow ok. i was in the wrong virtual env when i ran this.. lesson learned Sorry about that!