-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fbd400
commit 3c92a85
Showing
3 changed files
with
71 additions
and
0 deletions.
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,25 @@ | ||
import asyncio | ||
|
||
import openai | ||
from magentic import AsyncStreamedStr, prompt | ||
|
||
from log10.load import log10, log10_session | ||
|
||
|
||
log10(openai) | ||
|
||
|
||
@prompt("Tell me a 200-word story about {topic}") | ||
async def tell_story(topic: str) -> AsyncStreamedStr: | ||
... | ||
|
||
|
||
async def main(): | ||
with log10_session(tags=["async_tag"]): | ||
output = await tell_story("Europe.") | ||
async for chunk in output: | ||
print(chunk, end="", flush=True) | ||
|
||
|
||
# Python 3.7+ | ||
asyncio.run(main()) |
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,22 @@ | ||
import asyncio | ||
|
||
import openai | ||
from openai import AsyncOpenAI | ||
|
||
from log10.load import log10 | ||
|
||
|
||
log10(openai) | ||
|
||
client = AsyncOpenAI() | ||
|
||
|
||
async def main(): | ||
completion = await client.chat.completions.create( | ||
model="gpt-4", | ||
messages=[{"role": "user", "content": "Say this is a test"}], | ||
) | ||
print(completion.choices[0].message.content) | ||
|
||
|
||
asyncio.run(main()) |
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,24 @@ | ||
import asyncio | ||
|
||
import openai | ||
from openai import AsyncOpenAI | ||
|
||
from log10.load import log10 | ||
|
||
|
||
log10(openai) | ||
|
||
client = AsyncOpenAI() | ||
|
||
|
||
async def main(): | ||
stream = await client.chat.completions.create( | ||
model="gpt-4", | ||
messages=[{"role": "user", "content": "Count to 50."}], | ||
stream=True, | ||
) | ||
async for chunk in stream: | ||
print(chunk.choices[0].delta.content or "", end="", flush=True) | ||
|
||
|
||
asyncio.run(main()) |