This commit is contained in:
David Alberto Adler
2025-09-07 21:23:12 +01:00
parent da48e8c4ea
commit 03054b21e4
9 changed files with 66 additions and 7 deletions
+24
View File
@@ -0,0 +1,24 @@
dependencies = [
"openrouter",
"os",
"asyncio",
]
import os
import asyncio
from openrouter import OpenRouter
async def main():
sdk = OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY"),
)
result = await sdk.chat.complete_async(
messages=[
{"role": "user", "content": "Hello, world!"},
],
model="openai/gpt-3.5-turbo",
)
print("Basic async completion:", result)
if __name__ == "__main__":
asyncio.run(main())
+32
View File
@@ -0,0 +1,32 @@
dependencies = [
"openrouter",
"os",
"asyncio",
]
import os
import asyncio
from openrouter import OpenRouter
async def main():
open_router = OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
)
res = await open_router.chat.complete_async(
messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
],
model="openai/gpt-3.5-turbo",
stream=True
)
async for event in res: # type: ignore
if event.data.choices and event.data.choices[0].delta.content:
print(event.data.choices[0].delta.content, end='', flush=True)
print()
if __name__ == "__main__":
asyncio.run(main())