|
11 | 11 | Since Doubleword exposes an OpenAI-compatible API, you can use the built-in |
12 | 12 | OpenAIChatCompletionClient with a custom base URL. |
13 | 13 |
|
| 14 | +Three execution modes are demonstrated: |
| 15 | +- main() — realtime (priority tier) |
| 16 | +- main_async() — 1-hour async (flex tier, mid-tier cost) |
| 17 | +- main_batch() — 24-hour batch (deepest discount) |
| 18 | +
|
14 | 19 | Setup: |
15 | 20 | pip install agent-framework-openai |
16 | 21 | export DOUBLEWORD_API_KEY="your-api-key" |
@@ -40,9 +45,37 @@ async def main() -> None: |
40 | 45 | print(f"Assistant: {response}") |
41 | 46 |
|
42 | 47 |
|
| 48 | +async def main_async() -> None: |
| 49 | + """Run requests on the 1-hour async (flex) tier using autobatcher. |
| 50 | +
|
| 51 | + Mid-tier cost between realtime and 24-hour batch — use when next-day |
| 52 | + batch turnaround is too slow but realtime is too expensive. |
| 53 | +
|
| 54 | + Install: pip install autobatcher |
| 55 | + See: https://pypi.org/project/autobatcher/ |
| 56 | + """ |
| 57 | + from autobatcher import AsyncOpenAI |
| 58 | + |
| 59 | + client = OpenAIChatCompletionClient( |
| 60 | + model="Qwen/Qwen3.5-397B-A17B-FP8", |
| 61 | + async_client=AsyncOpenAI( |
| 62 | + api_key=os.environ["DOUBLEWORD_API_KEY"], |
| 63 | + base_url="https://api.doubleword.ai/v1", |
| 64 | + ), |
| 65 | + ) |
| 66 | + |
| 67 | + message = Message("user", contents=["Explain the benefits of an AI model gateway in one paragraph."]) |
| 68 | + print(f"User: {message.text}") |
| 69 | + |
| 70 | + response = await client.get_response([message], stream=False) |
| 71 | + print(f"Assistant: {response}") |
| 72 | + |
| 73 | + |
43 | 74 | async def main_batch() -> None: |
44 | 75 | """Run batch requests at reduced cost using autobatcher. |
45 | 76 |
|
| 77 | + 24-hour batch tier — deepest discount (up to ~90% off realtime). |
| 78 | +
|
46 | 79 | Install: pip install autobatcher |
47 | 80 | See: https://pypi.org/project/autobatcher/ |
48 | 81 | """ |
|
0 commit comments