mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-09-11 12:31:28 +08:00
This commit is contained in:
+3
-8
@@ -1,17 +1,16 @@
|
|||||||
lockVersion: 2.0.0
|
lockVersion: 2.0.0
|
||||||
id: 232c6d4f-b0fd-4172-8f1b-e2421566e9b4
|
id: 232c6d4f-b0fd-4172-8f1b-e2421566e9b4
|
||||||
management:
|
management:
|
||||||
docChecksum: f7eafe8edffbaf9ef5bb835b345c5a9e
|
docChecksum: 15ebbb27870a24f8f19c47eecc775af8
|
||||||
docVersion: 1.0.0
|
docVersion: 1.0.0
|
||||||
speakeasyVersion: 1.611.1
|
speakeasyVersion: 1.611.1
|
||||||
generationVersion: 2.694.1
|
generationVersion: 2.694.1
|
||||||
releaseVersion: 0.4.1
|
releaseVersion: 0.5.1
|
||||||
configChecksum: 613707bdc6463db5dce971bc9cb430bb
|
configChecksum: 568679387340b2a17402ed3f9ffbf851
|
||||||
repoURL: https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
repoURL: https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
||||||
installationURL: https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
installationURL: https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
||||||
features:
|
features:
|
||||||
python:
|
python:
|
||||||
acceptHeaders: 3.0.0
|
|
||||||
additionalDependencies: 1.0.0
|
additionalDependencies: 1.0.0
|
||||||
constsAndDefaults: 1.0.5
|
constsAndDefaults: 1.0.5
|
||||||
core: 5.20.3
|
core: 5.20.3
|
||||||
@@ -58,7 +57,6 @@ generatedFiles:
|
|||||||
- docs/models/chatcompletionchunkchoicedeltatoolcalltype.md
|
- docs/models/chatcompletionchunkchoicedeltatoolcalltype.md
|
||||||
- docs/models/chatcompletionchunkchoicefinishreason.md
|
- docs/models/chatcompletionchunkchoicefinishreason.md
|
||||||
- docs/models/chatcompletionchunkobject.md
|
- docs/models/chatcompletionchunkobject.md
|
||||||
- docs/models/chatcompletionchunkwrapper.md
|
|
||||||
- docs/models/chatcompletioncontentpart.md
|
- docs/models/chatcompletioncontentpart.md
|
||||||
- docs/models/chatcompletioncontentpartaudio.md
|
- docs/models/chatcompletioncontentpartaudio.md
|
||||||
- docs/models/chatcompletioncontentpartaudioformat.md
|
- docs/models/chatcompletioncontentpartaudioformat.md
|
||||||
@@ -194,7 +192,6 @@ generatedFiles:
|
|||||||
- docs/models/contenttext.md
|
- docs/models/contenttext.md
|
||||||
- docs/models/contenttypeimageurl.md
|
- docs/models/contenttypeimageurl.md
|
||||||
- docs/models/contenttypetext.md
|
- docs/models/contenttypetext.md
|
||||||
- docs/models/createchatcompletionresponse.md
|
|
||||||
- docs/models/detail.md
|
- docs/models/detail.md
|
||||||
- docs/models/error.md
|
- docs/models/error.md
|
||||||
- docs/models/file.md
|
- docs/models/file.md
|
||||||
@@ -253,7 +250,6 @@ generatedFiles:
|
|||||||
- src/openrouter/models/chatcompletionchunkchoice.py
|
- src/openrouter/models/chatcompletionchunkchoice.py
|
||||||
- src/openrouter/models/chatcompletionchunkchoicedelta.py
|
- src/openrouter/models/chatcompletionchunkchoicedelta.py
|
||||||
- src/openrouter/models/chatcompletionchunkchoicedeltatoolcall.py
|
- src/openrouter/models/chatcompletionchunkchoicedeltatoolcall.py
|
||||||
- src/openrouter/models/chatcompletionchunkwrapper.py
|
|
||||||
- src/openrouter/models/chatcompletioncontentpart.py
|
- src/openrouter/models/chatcompletioncontentpart.py
|
||||||
- src/openrouter/models/chatcompletioncontentpartaudio.py
|
- src/openrouter/models/chatcompletioncontentpartaudio.py
|
||||||
- src/openrouter/models/chatcompletioncontentpartimage.py
|
- src/openrouter/models/chatcompletioncontentpartimage.py
|
||||||
@@ -273,7 +269,6 @@ generatedFiles:
|
|||||||
- src/openrouter/models/chatcompletionusermessageparam.py
|
- src/openrouter/models/chatcompletionusermessageparam.py
|
||||||
- src/openrouter/models/chatstreamcompletioncreateparams.py
|
- src/openrouter/models/chatstreamcompletioncreateparams.py
|
||||||
- src/openrouter/models/completionusage.py
|
- src/openrouter/models/completionusage.py
|
||||||
- src/openrouter/models/createchatcompletionop.py
|
|
||||||
- src/openrouter/models/fileannotationdetail.py
|
- src/openrouter/models/fileannotationdetail.py
|
||||||
- src/openrouter/models/reasoningdetail.py
|
- src/openrouter/models/reasoningdetail.py
|
||||||
- src/openrouter/models/reasoningdetailencrypted.py
|
- src/openrouter/models/reasoningdetailencrypted.py
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ generation:
|
|||||||
generateNewTests: true
|
generateNewTests: true
|
||||||
skipResponseBodyAssertions: false
|
skipResponseBodyAssertions: false
|
||||||
python:
|
python:
|
||||||
version: 0.4.1
|
version: 0.5.1
|
||||||
additionalDependencies:
|
additionalDependencies:
|
||||||
dev: {}
|
dev: {}
|
||||||
main: {}
|
main: {}
|
||||||
|
|||||||
@@ -1534,10 +1534,6 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/ChatCompletion"
|
$ref: "#/components/schemas/ChatCompletion"
|
||||||
description: Non-streaming response when stream=false
|
description: Non-streaming response when stream=false
|
||||||
text/event-stream:
|
|
||||||
x-speakeasy-sse-sentinel: "[DONE]"
|
|
||||||
schema:
|
|
||||||
$ref: "#/components/schemas/ChatCompletionChunkWrapper"
|
|
||||||
"400":
|
"400":
|
||||||
description: Bad request - invalid parameters
|
description: Bad request - invalid parameters
|
||||||
content:
|
content:
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ workflow:
|
|||||||
sources:
|
sources:
|
||||||
OpenRouter Chat Completions API:
|
OpenRouter Chat Completions API:
|
||||||
inputs:
|
inputs:
|
||||||
- location: .speakeasy/input.openapi.yaml
|
- location: .speakeasy/in.openapi.yaml
|
||||||
output: .speakeasy/out.openapi.yaml
|
output: .speakeasy/out.openapi.yaml
|
||||||
registry:
|
registry:
|
||||||
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api
|
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api
|
||||||
|
|||||||
+17
-33
@@ -140,10 +140,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
@@ -168,10 +166,8 @@ async def main():
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
async with res as event_stream:
|
# Handle response
|
||||||
async for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
```
|
```
|
||||||
@@ -205,10 +201,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
<!-- End Authentication [security] -->
|
<!-- End Authentication [security] -->
|
||||||
@@ -249,7 +243,7 @@ with OpenRouter(
|
|||||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||||
) as open_router:
|
) as open_router:
|
||||||
|
|
||||||
res = open_router.chat.complete(messages=[
|
res = open_router.chat.complete_stream(messages=[
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": "Hello, how are you?",
|
"content": "Hello, how are you?",
|
||||||
@@ -292,10 +286,8 @@ with OpenRouter(
|
|||||||
], stream=False, temperature=1, top_p=1,
|
], stream=False, temperature=1, top_p=1,
|
||||||
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
|
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -318,10 +310,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
<!-- End Retries [retries] -->
|
<!-- End Retries [retries] -->
|
||||||
@@ -359,10 +349,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
|
|
||||||
except errors.OpenRouterError as e:
|
except errors.OpenRouterError as e:
|
||||||
@@ -429,10 +417,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -456,10 +442,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
<!-- End Server Selection [server] -->
|
<!-- End Server Selection [server] -->
|
||||||
|
|||||||
@@ -140,10 +140,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
@@ -168,10 +166,8 @@ async def main():
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
async with res as event_stream:
|
# Handle response
|
||||||
async for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
```
|
```
|
||||||
@@ -205,10 +201,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
<!-- End Authentication [security] -->
|
<!-- End Authentication [security] -->
|
||||||
@@ -249,7 +243,7 @@ with OpenRouter(
|
|||||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||||
) as open_router:
|
) as open_router:
|
||||||
|
|
||||||
res = open_router.chat.complete(messages=[
|
res = open_router.chat.complete_stream(messages=[
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": "Hello, how are you?",
|
"content": "Hello, how are you?",
|
||||||
@@ -292,10 +286,8 @@ with OpenRouter(
|
|||||||
], stream=False, temperature=1, top_p=1,
|
], stream=False, temperature=1, top_p=1,
|
||||||
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
|
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -318,10 +310,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
<!-- End Retries [retries] -->
|
<!-- End Retries [retries] -->
|
||||||
@@ -359,10 +349,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
|
|
||||||
except errors.OpenRouterError as e:
|
except errors.OpenRouterError as e:
|
||||||
@@ -429,10 +417,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -456,10 +442,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
<!-- End Server Selection [server] -->
|
<!-- End Server Selection [server] -->
|
||||||
|
|||||||
@@ -16,10 +16,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
@@ -44,10 +42,8 @@ async def main():
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
async with res as event_stream:
|
# Handle response
|
||||||
async for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
# ChatCompletionChunkWrapper
|
|
||||||
|
|
||||||
|
|
||||||
## Fields
|
|
||||||
|
|
||||||
| Field | Type | Required | Description |
|
|
||||||
| -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- |
|
|
||||||
| `data` | [models.ChatCompletionChunk](../models/chatcompletionchunk.md) | :heavy_check_mark: | Streaming chat completion chunk |
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
# CreateChatCompletionResponse
|
|
||||||
|
|
||||||
|
|
||||||
## Supported Types
|
|
||||||
|
|
||||||
### `models.ChatCompletion`
|
|
||||||
|
|
||||||
```python
|
|
||||||
value: models.ChatCompletion = /* values here */
|
|
||||||
```
|
|
||||||
|
|
||||||
### `Union[eventstreaming.EventStream[models.ChatCompletionChunkWrapper], eventstreaming.EventStreamAsync[models.ChatCompletionChunkWrapper]]`
|
|
||||||
|
|
||||||
```python
|
|
||||||
value: Union[eventstreaming.EventStream[models.ChatCompletionChunkWrapper], eventstreaming.EventStreamAsync[models.ChatCompletionChunkWrapper]] = /* values here */
|
|
||||||
```
|
|
||||||
|
|
||||||
@@ -33,10 +33,8 @@ with OpenRouter(
|
|||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], stream=False, temperature=1, top_p=1)
|
||||||
|
|
||||||
with res as event_stream:
|
# Handle response
|
||||||
for event in event_stream:
|
print(res)
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -73,7 +71,7 @@ with OpenRouter(
|
|||||||
|
|
||||||
### Response
|
### Response
|
||||||
|
|
||||||
**[models.CreateChatCompletionResponse](../../models/createchatcompletionresponse.md)**
|
**[models.ChatCompletion](../../models/chatcompletion.md)**
|
||||||
|
|
||||||
### Errors
|
### Errors
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "openrouter"
|
name = "openrouter"
|
||||||
version = "0.4.1"
|
version = "0.5.1"
|
||||||
description = "Python Client SDK Generated by Speakeasy."
|
description = "Python Client SDK Generated by Speakeasy."
|
||||||
authors = [{ name = "Speakeasy" },]
|
authors = [{ name = "Speakeasy" },]
|
||||||
readme = "README-PYPI.md"
|
readme = "README-PYPI.md"
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
import importlib.metadata
|
import importlib.metadata
|
||||||
|
|
||||||
__title__: str = "openrouter"
|
__title__: str = "openrouter"
|
||||||
__version__: str = "0.4.1"
|
__version__: str = "0.5.1"
|
||||||
__openapi_doc_version__: str = "1.0.0"
|
__openapi_doc_version__: str = "1.0.0"
|
||||||
__gen_version__: str = "2.694.1"
|
__gen_version__: str = "2.694.1"
|
||||||
__user_agent__: str = "speakeasy-sdk/python 0.4.1 2.694.1 1.0.0 openrouter"
|
__user_agent__: str = "speakeasy-sdk/python 0.5.1 2.694.1 1.0.0 openrouter"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if __package__ is not None:
|
if __package__ is not None:
|
||||||
|
|||||||
+16
-71
@@ -1,7 +1,6 @@
|
|||||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
||||||
|
|
||||||
from .basesdk import BaseSDK
|
from .basesdk import BaseSDK
|
||||||
from enum import Enum
|
|
||||||
from openrouter import errors, models, utils
|
from openrouter import errors, models, utils
|
||||||
from openrouter._hooks import HookContext
|
from openrouter._hooks import HookContext
|
||||||
from openrouter.types import OptionalNullable, UNSET
|
from openrouter.types import OptionalNullable, UNSET
|
||||||
@@ -9,16 +8,6 @@ from openrouter.utils import eventstreaming, get_security_from_env
|
|||||||
from openrouter.utils.unmarshal_json_response import unmarshal_json_response
|
from openrouter.utils.unmarshal_json_response import unmarshal_json_response
|
||||||
from typing import Any, Dict, List, Mapping, Optional, Union
|
from typing import Any, Dict, List, Mapping, Optional, Union
|
||||||
|
|
||||||
# region imports
|
|
||||||
from typing import overload
|
|
||||||
from typing_extensions import Literal
|
|
||||||
# endregion imports
|
|
||||||
|
|
||||||
|
|
||||||
class CompleteAcceptEnum(str, Enum):
|
|
||||||
APPLICATION_JSON = "application/json"
|
|
||||||
TEXT_EVENT_STREAM = "text/event-stream"
|
|
||||||
|
|
||||||
|
|
||||||
class Chat(BaseSDK):
|
class Chat(BaseSDK):
|
||||||
r"""Chat completion operations"""
|
r"""Chat completion operations"""
|
||||||
@@ -99,9 +88,8 @@ class Chat(BaseSDK):
|
|||||||
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
||||||
server_url: Optional[str] = None,
|
server_url: Optional[str] = None,
|
||||||
timeout_ms: Optional[int] = None,
|
timeout_ms: Optional[int] = None,
|
||||||
accept_header_override: Optional[CompleteAcceptEnum] = None,
|
|
||||||
http_headers: Optional[Mapping[str, str]] = None,
|
http_headers: Optional[Mapping[str, str]] = None,
|
||||||
) -> models.CreateChatCompletionResponse:
|
) -> models.ChatCompletion:
|
||||||
r"""Create a chat completion
|
r"""Create a chat completion
|
||||||
|
|
||||||
Creates a model response for the given chat conversation. Supports both streaming and non-streaming modes.
|
Creates a model response for the given chat conversation. Supports both streaming and non-streaming modes.
|
||||||
@@ -134,7 +122,6 @@ class Chat(BaseSDK):
|
|||||||
:param retries: Override the default retry configuration for this method
|
:param retries: Override the default retry configuration for this method
|
||||||
:param server_url: Override the default server URL for this method
|
:param server_url: Override the default server URL for this method
|
||||||
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
||||||
:param accept_header_override: Override the default accept header for this method
|
|
||||||
:param http_headers: Additional headers to set or replace on requests.
|
:param http_headers: Additional headers to set or replace on requests.
|
||||||
"""
|
"""
|
||||||
base_url = None
|
base_url = None
|
||||||
@@ -203,9 +190,7 @@ class Chat(BaseSDK):
|
|||||||
request_has_path_params=False,
|
request_has_path_params=False,
|
||||||
request_has_query_params=True,
|
request_has_query_params=True,
|
||||||
user_agent_header="user-agent",
|
user_agent_header="user-agent",
|
||||||
accept_header_value=accept_header_override.value
|
accept_header_value="application/json",
|
||||||
if accept_header_override is not None
|
|
||||||
else "application/json;q=1, text/event-stream;q=0",
|
|
||||||
http_headers=http_headers,
|
http_headers=http_headers,
|
||||||
security=self.sdk_configuration.security,
|
security=self.sdk_configuration.security,
|
||||||
get_serialized_body=lambda: utils.serialize_request_body(
|
get_serialized_body=lambda: utils.serialize_request_body(
|
||||||
@@ -234,37 +219,22 @@ class Chat(BaseSDK):
|
|||||||
),
|
),
|
||||||
request=req,
|
request=req,
|
||||||
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
|
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
|
||||||
stream=True,
|
|
||||||
retry_config=retry_config,
|
retry_config=retry_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
response_data: Any = None
|
response_data: Any = None
|
||||||
if utils.match_response(http_res, "200", "application/json"):
|
if utils.match_response(http_res, "200", "application/json"):
|
||||||
http_res_text = utils.stream_to_text(http_res)
|
return unmarshal_json_response(models.ChatCompletion, http_res)
|
||||||
return unmarshal_json_response(
|
|
||||||
models.ChatCompletion, http_res, http_res_text
|
|
||||||
)
|
|
||||||
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
||||||
return eventstreaming.EventStream(
|
|
||||||
http_res,
|
|
||||||
lambda raw: utils.unmarshal_json(
|
|
||||||
raw, models.ChatCompletionChunkWrapper
|
|
||||||
),
|
|
||||||
sentinel="[DONE]",
|
|
||||||
client_ref=self,
|
|
||||||
)
|
|
||||||
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
|
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
|
||||||
http_res_text = utils.stream_to_text(http_res)
|
|
||||||
response_data = unmarshal_json_response(
|
response_data = unmarshal_json_response(
|
||||||
errors.ChatCompletionErrorData, http_res, http_res_text
|
errors.ChatCompletionErrorData, http_res
|
||||||
)
|
)
|
||||||
raise errors.ChatCompletionError(response_data, http_res, http_res_text)
|
raise errors.ChatCompletionError(response_data, http_res)
|
||||||
if utils.match_response(http_res, "500", "application/json"):
|
if utils.match_response(http_res, "500", "application/json"):
|
||||||
http_res_text = utils.stream_to_text(http_res)
|
|
||||||
response_data = unmarshal_json_response(
|
response_data = unmarshal_json_response(
|
||||||
errors.ChatCompletionErrorData, http_res, http_res_text
|
errors.ChatCompletionErrorData, http_res
|
||||||
)
|
)
|
||||||
raise errors.ChatCompletionError(response_data, http_res, http_res_text)
|
raise errors.ChatCompletionError(response_data, http_res)
|
||||||
if utils.match_response(http_res, "4XX", "*"):
|
if utils.match_response(http_res, "4XX", "*"):
|
||||||
http_res_text = utils.stream_to_text(http_res)
|
http_res_text = utils.stream_to_text(http_res)
|
||||||
raise errors.OpenRouterDefaultError(
|
raise errors.OpenRouterDefaultError(
|
||||||
@@ -276,10 +246,7 @@ class Chat(BaseSDK):
|
|||||||
"API error occurred", http_res, http_res_text
|
"API error occurred", http_res, http_res_text
|
||||||
)
|
)
|
||||||
|
|
||||||
http_res_text = utils.stream_to_text(http_res)
|
raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
|
||||||
raise errors.OpenRouterDefaultError(
|
|
||||||
"Unexpected response received", http_res, http_res_text
|
|
||||||
)
|
|
||||||
|
|
||||||
async def complete_async(
|
async def complete_async(
|
||||||
self,
|
self,
|
||||||
@@ -357,9 +324,8 @@ class Chat(BaseSDK):
|
|||||||
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
||||||
server_url: Optional[str] = None,
|
server_url: Optional[str] = None,
|
||||||
timeout_ms: Optional[int] = None,
|
timeout_ms: Optional[int] = None,
|
||||||
accept_header_override: Optional[CompleteAcceptEnum] = None,
|
|
||||||
http_headers: Optional[Mapping[str, str]] = None,
|
http_headers: Optional[Mapping[str, str]] = None,
|
||||||
) -> models.CreateChatCompletionResponse:
|
) -> models.ChatCompletion:
|
||||||
r"""Create a chat completion
|
r"""Create a chat completion
|
||||||
|
|
||||||
Creates a model response for the given chat conversation. Supports both streaming and non-streaming modes.
|
Creates a model response for the given chat conversation. Supports both streaming and non-streaming modes.
|
||||||
@@ -392,7 +358,6 @@ class Chat(BaseSDK):
|
|||||||
:param retries: Override the default retry configuration for this method
|
:param retries: Override the default retry configuration for this method
|
||||||
:param server_url: Override the default server URL for this method
|
:param server_url: Override the default server URL for this method
|
||||||
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
||||||
:param accept_header_override: Override the default accept header for this method
|
|
||||||
:param http_headers: Additional headers to set or replace on requests.
|
:param http_headers: Additional headers to set or replace on requests.
|
||||||
"""
|
"""
|
||||||
base_url = None
|
base_url = None
|
||||||
@@ -461,9 +426,7 @@ class Chat(BaseSDK):
|
|||||||
request_has_path_params=False,
|
request_has_path_params=False,
|
||||||
request_has_query_params=True,
|
request_has_query_params=True,
|
||||||
user_agent_header="user-agent",
|
user_agent_header="user-agent",
|
||||||
accept_header_value=accept_header_override.value
|
accept_header_value="application/json",
|
||||||
if accept_header_override is not None
|
|
||||||
else "application/json;q=1, text/event-stream;q=0",
|
|
||||||
http_headers=http_headers,
|
http_headers=http_headers,
|
||||||
security=self.sdk_configuration.security,
|
security=self.sdk_configuration.security,
|
||||||
get_serialized_body=lambda: utils.serialize_request_body(
|
get_serialized_body=lambda: utils.serialize_request_body(
|
||||||
@@ -492,37 +455,22 @@ class Chat(BaseSDK):
|
|||||||
),
|
),
|
||||||
request=req,
|
request=req,
|
||||||
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
|
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
|
||||||
stream=True,
|
|
||||||
retry_config=retry_config,
|
retry_config=retry_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
response_data: Any = None
|
response_data: Any = None
|
||||||
if utils.match_response(http_res, "200", "application/json"):
|
if utils.match_response(http_res, "200", "application/json"):
|
||||||
http_res_text = await utils.stream_to_text_async(http_res)
|
return unmarshal_json_response(models.ChatCompletion, http_res)
|
||||||
return unmarshal_json_response(
|
|
||||||
models.ChatCompletion, http_res, http_res_text
|
|
||||||
)
|
|
||||||
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
||||||
return eventstreaming.EventStreamAsync(
|
|
||||||
http_res,
|
|
||||||
lambda raw: utils.unmarshal_json(
|
|
||||||
raw, models.ChatCompletionChunkWrapper
|
|
||||||
),
|
|
||||||
sentinel="[DONE]",
|
|
||||||
client_ref=self,
|
|
||||||
)
|
|
||||||
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
|
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
|
||||||
http_res_text = await utils.stream_to_text_async(http_res)
|
|
||||||
response_data = unmarshal_json_response(
|
response_data = unmarshal_json_response(
|
||||||
errors.ChatCompletionErrorData, http_res, http_res_text
|
errors.ChatCompletionErrorData, http_res
|
||||||
)
|
)
|
||||||
raise errors.ChatCompletionError(response_data, http_res, http_res_text)
|
raise errors.ChatCompletionError(response_data, http_res)
|
||||||
if utils.match_response(http_res, "500", "application/json"):
|
if utils.match_response(http_res, "500", "application/json"):
|
||||||
http_res_text = await utils.stream_to_text_async(http_res)
|
|
||||||
response_data = unmarshal_json_response(
|
response_data = unmarshal_json_response(
|
||||||
errors.ChatCompletionErrorData, http_res, http_res_text
|
errors.ChatCompletionErrorData, http_res
|
||||||
)
|
)
|
||||||
raise errors.ChatCompletionError(response_data, http_res, http_res_text)
|
raise errors.ChatCompletionError(response_data, http_res)
|
||||||
if utils.match_response(http_res, "4XX", "*"):
|
if utils.match_response(http_res, "4XX", "*"):
|
||||||
http_res_text = await utils.stream_to_text_async(http_res)
|
http_res_text = await utils.stream_to_text_async(http_res)
|
||||||
raise errors.OpenRouterDefaultError(
|
raise errors.OpenRouterDefaultError(
|
||||||
@@ -534,10 +482,7 @@ class Chat(BaseSDK):
|
|||||||
"API error occurred", http_res, http_res_text
|
"API error occurred", http_res, http_res_text
|
||||||
)
|
)
|
||||||
|
|
||||||
http_res_text = await utils.stream_to_text_async(http_res)
|
raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
|
||||||
raise errors.OpenRouterDefaultError(
|
|
||||||
"Unexpected response received", http_res, http_res_text
|
|
||||||
)
|
|
||||||
|
|
||||||
def complete_stream(
|
def complete_stream(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -46,10 +46,6 @@ if TYPE_CHECKING:
|
|||||||
ChatCompletionChunkChoiceDeltaToolCallType,
|
ChatCompletionChunkChoiceDeltaToolCallType,
|
||||||
ChatCompletionChunkChoiceDeltaToolCallTypedDict,
|
ChatCompletionChunkChoiceDeltaToolCallTypedDict,
|
||||||
)
|
)
|
||||||
from .chatcompletionchunkwrapper import (
|
|
||||||
ChatCompletionChunkWrapper,
|
|
||||||
ChatCompletionChunkWrapperTypedDict,
|
|
||||||
)
|
|
||||||
from .chatcompletioncontentpart import (
|
from .chatcompletioncontentpart import (
|
||||||
ChatCompletionContentPart,
|
ChatCompletionContentPart,
|
||||||
ChatCompletionContentPartTypedDict,
|
ChatCompletionContentPartTypedDict,
|
||||||
@@ -304,10 +300,6 @@ if TYPE_CHECKING:
|
|||||||
PromptTokensDetails,
|
PromptTokensDetails,
|
||||||
PromptTokensDetailsTypedDict,
|
PromptTokensDetailsTypedDict,
|
||||||
)
|
)
|
||||||
from .createchatcompletionop import (
|
|
||||||
CreateChatCompletionResponse,
|
|
||||||
CreateChatCompletionResponseTypedDict,
|
|
||||||
)
|
|
||||||
from .fileannotationdetail import (
|
from .fileannotationdetail import (
|
||||||
ContentImageURL,
|
ContentImageURL,
|
||||||
ContentImageURLTypedDict,
|
ContentImageURLTypedDict,
|
||||||
@@ -387,8 +379,6 @@ __all__ = [
|
|||||||
"ChatCompletionChunkChoiceTypedDict",
|
"ChatCompletionChunkChoiceTypedDict",
|
||||||
"ChatCompletionChunkObject",
|
"ChatCompletionChunkObject",
|
||||||
"ChatCompletionChunkTypedDict",
|
"ChatCompletionChunkTypedDict",
|
||||||
"ChatCompletionChunkWrapper",
|
|
||||||
"ChatCompletionChunkWrapperTypedDict",
|
|
||||||
"ChatCompletionContentPart",
|
"ChatCompletionContentPart",
|
||||||
"ChatCompletionContentPartAudio",
|
"ChatCompletionContentPartAudio",
|
||||||
"ChatCompletionContentPartAudioFormat",
|
"ChatCompletionContentPartAudioFormat",
|
||||||
@@ -605,8 +595,6 @@ __all__ = [
|
|||||||
"ContentTextTypedDict",
|
"ContentTextTypedDict",
|
||||||
"ContentTypeImageURL",
|
"ContentTypeImageURL",
|
||||||
"ContentTypeText",
|
"ContentTypeText",
|
||||||
"CreateChatCompletionResponse",
|
|
||||||
"CreateChatCompletionResponseTypedDict",
|
|
||||||
"Detail",
|
"Detail",
|
||||||
"Error",
|
"Error",
|
||||||
"ErrorTypedDict",
|
"ErrorTypedDict",
|
||||||
@@ -682,8 +670,6 @@ _dynamic_imports: dict[str, str] = {
|
|||||||
"ChatCompletionChunkChoiceDeltaToolCallFunctionTypedDict": ".chatcompletionchunkchoicedeltatoolcall",
|
"ChatCompletionChunkChoiceDeltaToolCallFunctionTypedDict": ".chatcompletionchunkchoicedeltatoolcall",
|
||||||
"ChatCompletionChunkChoiceDeltaToolCallType": ".chatcompletionchunkchoicedeltatoolcall",
|
"ChatCompletionChunkChoiceDeltaToolCallType": ".chatcompletionchunkchoicedeltatoolcall",
|
||||||
"ChatCompletionChunkChoiceDeltaToolCallTypedDict": ".chatcompletionchunkchoicedeltatoolcall",
|
"ChatCompletionChunkChoiceDeltaToolCallTypedDict": ".chatcompletionchunkchoicedeltatoolcall",
|
||||||
"ChatCompletionChunkWrapper": ".chatcompletionchunkwrapper",
|
|
||||||
"ChatCompletionChunkWrapperTypedDict": ".chatcompletionchunkwrapper",
|
|
||||||
"ChatCompletionContentPart": ".chatcompletioncontentpart",
|
"ChatCompletionContentPart": ".chatcompletioncontentpart",
|
||||||
"ChatCompletionContentPartTypedDict": ".chatcompletioncontentpart",
|
"ChatCompletionContentPartTypedDict": ".chatcompletioncontentpart",
|
||||||
"ChatCompletionContentPartAudio": ".chatcompletioncontentpartaudio",
|
"ChatCompletionContentPartAudio": ".chatcompletioncontentpartaudio",
|
||||||
@@ -903,8 +889,6 @@ _dynamic_imports: dict[str, str] = {
|
|||||||
"CompletionUsageTypedDict": ".completionusage",
|
"CompletionUsageTypedDict": ".completionusage",
|
||||||
"PromptTokensDetails": ".completionusage",
|
"PromptTokensDetails": ".completionusage",
|
||||||
"PromptTokensDetailsTypedDict": ".completionusage",
|
"PromptTokensDetailsTypedDict": ".completionusage",
|
||||||
"CreateChatCompletionResponse": ".createchatcompletionop",
|
|
||||||
"CreateChatCompletionResponseTypedDict": ".createchatcompletionop",
|
|
||||||
"ContentImageURL": ".fileannotationdetail",
|
"ContentImageURL": ".fileannotationdetail",
|
||||||
"ContentImageURLTypedDict": ".fileannotationdetail",
|
"ContentImageURLTypedDict": ".fileannotationdetail",
|
||||||
"ContentText": ".fileannotationdetail",
|
"ContentText": ".fileannotationdetail",
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
from .chatcompletionchunk import ChatCompletionChunk, ChatCompletionChunkTypedDict
|
|
||||||
from openrouter.types import BaseModel
|
|
||||||
from typing_extensions import TypedDict
|
|
||||||
|
|
||||||
|
|
||||||
class ChatCompletionChunkWrapperTypedDict(TypedDict):
|
|
||||||
data: ChatCompletionChunkTypedDict
|
|
||||||
r"""Streaming chat completion chunk"""
|
|
||||||
|
|
||||||
|
|
||||||
class ChatCompletionChunkWrapper(BaseModel):
|
|
||||||
data: ChatCompletionChunk
|
|
||||||
r"""Streaming chat completion chunk"""
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
from .chatcompletion import ChatCompletion, ChatCompletionTypedDict
|
|
||||||
from .chatcompletionchunkwrapper import (
|
|
||||||
ChatCompletionChunkWrapper,
|
|
||||||
ChatCompletionChunkWrapperTypedDict,
|
|
||||||
)
|
|
||||||
from openrouter.utils import eventstreaming
|
|
||||||
from typing import Union
|
|
||||||
from typing_extensions import TypeAliasType
|
|
||||||
|
|
||||||
|
|
||||||
CreateChatCompletionResponseTypedDict = TypeAliasType(
|
|
||||||
"CreateChatCompletionResponseTypedDict",
|
|
||||||
Union[
|
|
||||||
ChatCompletionTypedDict,
|
|
||||||
Union[
|
|
||||||
eventstreaming.EventStream[ChatCompletionChunkWrapperTypedDict],
|
|
||||||
eventstreaming.EventStreamAsync[ChatCompletionChunkWrapperTypedDict],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
CreateChatCompletionResponse = TypeAliasType(
|
|
||||||
"CreateChatCompletionResponse",
|
|
||||||
Union[
|
|
||||||
ChatCompletion,
|
|
||||||
Union[
|
|
||||||
eventstreaming.EventStream[ChatCompletionChunkWrapper],
|
|
||||||
eventstreaming.EventStreamAsync[ChatCompletionChunkWrapper],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
)
|
|
||||||
@@ -201,7 +201,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openrouter"
|
name = "openrouter"
|
||||||
version = "0.4.1"
|
version = "0.5.1"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "httpcore" },
|
{ name = "httpcore" },
|
||||||
|
|||||||
Reference in New Issue
Block a user