Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7537ccd

Browse files
feat: add exception ContextWindowExceededError (opper-ai#63)
1 parent d93040e commit 7537ccd

56 files changed

Lines changed: 1423 additions & 1878 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "opperai"
3-
version = "0.17.0"
3+
version = "0.18.0"
44
description = "Opper Python client"
55
authors = ["Opper <[email protected]>"]
66
readme = "README.md"

src/opperai/core/_http_clients.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
import httpx
55
from httpx_sse import aconnect_sse, connect_sse
6+
67
from opperai.__version__ import __version__
78
from opperai.types import Errors
89
from opperai.types.exceptions import (
910
ContentPolicyViolationError,
11+
ContextWindowExceededError,
1012
OpperTimeoutError,
1113
RateLimitError,
1214
RequestValidationError,
@@ -24,6 +26,8 @@ def _prepare_error(response):
2426
raise StructuredGenerationError(error.message, error.detail)
2527
if error.type == "ContentPolicyViolationError":
2628
raise ContentPolicyViolationError(error.message, error.detail)
29+
if error.type == "ContextWindowExceededError":
30+
raise ContextWindowExceededError(error.message, error.detail)
2731
if status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
2832
if error.type == "RequestValidationError":
2933
raise RequestValidationError(error.message, error.detail)

src/opperai/types/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class RateLimitError(OpperBaseException):
4040
type: str = "RateLimitError"
4141

4242

43+
class ContextWindowExceededError(OpperBaseException):
44+
"""Raised when the context window is exceeded."""
45+
46+
type: str = "ContextWindowExceededError"
47+
48+
4349
class StructuredGenerationError(OpperBaseException):
4450
"""Raised when the structured generation fails."""
4551

tests/fixtures/vcr_cassettes/test_async_functions/test_async_chat.yaml

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ interactions:
77
connection:
88
- keep-alive
99
method: GET
10-
uri: https://api.opper.ai/v1/functions/by_path/test/sdk/test_async_chat
10+
uri: http://localhost:8000/v1/functions/by_path/test/sdk/test_async_chat
1111
response:
1212
body:
1313
string: '{"errors":[{"type":"HTTPException","message":"Function not found","detail":"Function
1414
not found"}]}'
1515
headers:
16-
Connection:
17-
- keep-alive
18-
Content-Length:
16+
content-length:
1917
- '98'
20-
Content-Type:
18+
content-type:
2119
- application/json
22-
Date:
23-
- Thu, 22 Aug 2024 14:02:19 GMT
20+
date:
21+
- Tue, 15 Oct 2024 14:17:47 GMT
2422
server:
2523
- uvicorn
2624
status:
@@ -41,21 +39,19 @@ interactions:
4139
content-type:
4240
- application/json
4341
method: POST
44-
uri: https://api.opper.ai/v1/functions
42+
uri: http://localhost:8000/v1/functions
4543
response:
4644
body:
47-
string: '{"id":7137,"uuid":"a3c0000e-229b-4211-8863-dd8d5ea6bfe7","dataset_uuid":"28213887-c807-4bfa-9d9f-5cd12671ce7b","description":"Translate
45+
string: '{"id":41,"uuid":"ac63328e-48e5-4f84-960b-fb7765a3ab6e","dataset_uuid":"ef965feb-a8e4-4ec7-89fe-6869bef7d1a0","description":"Translate
4846
to French","few_shot_count":2,"few_shot":false,"index_ids":[],"input_schema":null,"instructions":"Translate
49-
to French","language_model_id":null,"model":"azure/gpt4-eu","out_schema":null,"path":"test/sdk/test_async_chat","project":{"uuid":"1e29233e-9569-4fa3-a40c-edfd42d65e8d","name":"jctestsql"},"revision":1,"use_semantic_search":false}'
47+
to French","language_model_id":null,"model":"azure/gpt4-eu","out_schema":null,"path":"test/sdk/test_async_chat","project":{"uuid":"e64848ae-df03-4c0b-9a6f-4c498bf3dc8b","name":"asdfasdf"},"revision":1,"use_semantic_search":false}'
5048
headers:
51-
Connection:
52-
- keep-alive
53-
Content-Length:
54-
- '474'
55-
Content-Type:
49+
content-length:
50+
- '471'
51+
content-type:
5652
- application/json
57-
Date:
58-
- Thu, 22 Aug 2024 14:02:19 GMT
53+
date:
54+
- Tue, 15 Oct 2024 14:17:47 GMT
5955
server:
6056
- uvicorn
6157
status:
@@ -73,19 +69,17 @@ interactions:
7369
content-type:
7470
- application/json
7571
method: POST
76-
uri: https://api.opper.ai/v1/chat/test/sdk/test_async_chat
72+
uri: http://localhost:8000/v1/chat/test/sdk/test_async_chat
7773
response:
7874
body:
79-
string: '{"span_id":"7cc5bf1f-2835-468c-90cc-ae1c12b21ad5","message":"Bonjour","json_payload":null,"context":null,"cached":false}'
75+
string: '{"span_id":"2e54bd7d-03d2-4913-b4d7-581700313853","message":"Bonjour","json_payload":null,"context":null,"cached":false}'
8076
headers:
81-
Connection:
82-
- keep-alive
83-
Content-Length:
77+
content-length:
8478
- '120'
85-
Content-Type:
79+
content-type:
8680
- application/json
87-
Date:
88-
- Thu, 22 Aug 2024 14:02:21 GMT
81+
date:
82+
- Tue, 15 Oct 2024 14:17:47 GMT
8983
server:
9084
- uvicorn
9185
status:
@@ -99,17 +93,15 @@ interactions:
9993
connection:
10094
- keep-alive
10195
method: DELETE
102-
uri: https://api.opper.ai/v1/functions/a3c0000e-229b-4211-8863-dd8d5ea6bfe7
96+
uri: http://localhost:8000/v1/functions/ac63328e-48e5-4f84-960b-fb7765a3ab6e
10397
response:
10498
body:
10599
string: ''
106100
headers:
107-
Connection:
108-
- keep-alive
109-
Content-Type:
101+
content-type:
110102
- application/json
111-
Date:
112-
- Thu, 22 Aug 2024 14:02:21 GMT
103+
date:
104+
- Tue, 15 Oct 2024 14:17:48 GMT
113105
server:
114106
- uvicorn
115107
status:

tests/fixtures/vcr_cassettes/test_async_functions/test_async_chat_stream.yaml

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ interactions:
77
connection:
88
- keep-alive
99
method: GET
10-
uri: https://api.opper.ai/v1/functions/by_path/test/sdk/test_async_chat_stream
10+
uri: http://localhost:8000/v1/functions/by_path/test/sdk/test_async_chat_stream
1111
response:
1212
body:
1313
string: '{"errors":[{"type":"HTTPException","message":"Function not found","detail":"Function
1414
not found"}]}'
1515
headers:
16-
Connection:
17-
- keep-alive
18-
Content-Length:
16+
content-length:
1917
- '98'
20-
Content-Type:
18+
content-type:
2119
- application/json
22-
Date:
23-
- Thu, 22 Aug 2024 14:02:21 GMT
20+
date:
21+
- Tue, 15 Oct 2024 14:17:48 GMT
2422
server:
2523
- uvicorn
2624
status:
@@ -42,21 +40,19 @@ interactions:
4240
content-type:
4341
- application/json
4442
method: POST
45-
uri: https://api.opper.ai/v1/functions
43+
uri: http://localhost:8000/v1/functions
4644
response:
4745
body:
48-
string: '{"id":7138,"uuid":"32ff6adc-614e-463b-890a-bb87d117cac3","dataset_uuid":"f806b45a-c425-41fa-8aac-a4b2177770ce","description":"Translate
46+
string: '{"id":42,"uuid":"9dd227ae-5c87-4eaa-9edd-eb28a1eb8b2a","dataset_uuid":"02bca857-918a-43c2-8575-b541e5321265","description":"Translate
4947
to French","few_shot_count":2,"few_shot":false,"index_ids":[],"input_schema":null,"instructions":"Translate
50-
to French","language_model_id":null,"model":"azure/gpt4-eu","out_schema":null,"path":"test/sdk/test_async_chat_stream","project":{"uuid":"1e29233e-9569-4fa3-a40c-edfd42d65e8d","name":"jctestsql"},"revision":1,"use_semantic_search":false}'
48+
to French","language_model_id":null,"model":"azure/gpt4-eu","out_schema":null,"path":"test/sdk/test_async_chat_stream","project":{"uuid":"e64848ae-df03-4c0b-9a6f-4c498bf3dc8b","name":"asdfasdf"},"revision":1,"use_semantic_search":false}'
5149
headers:
52-
Connection:
53-
- keep-alive
54-
Content-Length:
55-
- '481'
56-
Content-Type:
50+
content-length:
51+
- '478'
52+
content-type:
5753
- application/json
58-
Date:
59-
- Thu, 22 Aug 2024 14:02:22 GMT
54+
date:
55+
- Tue, 15 Oct 2024 14:17:48 GMT
6056
server:
6157
- uvicorn
6258
status:
@@ -76,24 +72,24 @@ interactions:
7672
content-type:
7773
- application/json
7874
method: POST
79-
uri: https://api.opper.ai/v1/chat/test/sdk/test_async_chat_stream?stream=True
75+
uri: http://localhost:8000/v1/chat/test/sdk/test_async_chat_stream?stream=True
8076
response:
8177
body:
82-
string: "data: {\"span_id\": \"6302d582-21b0-45bd-bd96-267f152817c2\"}\r\n\r\ndata:
78+
string: "data: {\"span_id\": \"25792d86-1bbe-46a6-9d25-c5d934642cbf\"}\r\n\r\ndata:
8379
{\"delta\": \"Bonjour\"}\r\n\r\n"
8480
headers:
85-
Connection:
86-
- keep-alive
87-
Content-Type:
88-
- text/event-stream; charset=utf-8
89-
Date:
90-
- Thu, 22 Aug 2024 14:02:22 GMT
91-
Transfer-Encoding:
92-
- chunked
9381
cache-control:
9482
- no-store
83+
connection:
84+
- keep-alive
85+
content-type:
86+
- text/event-stream; charset=utf-8
87+
date:
88+
- Tue, 15 Oct 2024 14:17:48 GMT
9589
server:
9690
- uvicorn
91+
transfer-encoding:
92+
- chunked
9793
x-accel-buffering:
9894
- 'no'
9995
status:
@@ -107,17 +103,15 @@ interactions:
107103
connection:
108104
- keep-alive
109105
method: DELETE
110-
uri: https://api.opper.ai/v1/functions/32ff6adc-614e-463b-890a-bb87d117cac3
106+
uri: http://localhost:8000/v1/functions/9dd227ae-5c87-4eaa-9edd-eb28a1eb8b2a
111107
response:
112108
body:
113109
string: ''
114110
headers:
115-
Connection:
116-
- keep-alive
117-
Content-Type:
111+
content-type:
118112
- application/json
119-
Date:
120-
- Thu, 22 Aug 2024 14:02:23 GMT
113+
date:
114+
- Tue, 15 Oct 2024 14:17:49 GMT
121115
server:
122116
- uvicorn
123117
status:

tests/fixtures/vcr_cassettes/test_async_functions/test_create_function.yaml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ interactions:
77
connection:
88
- keep-alive
99
method: GET
10-
uri: https://api.opper.ai/v1/functions/by_path/test/sdk/test_create_function_async
10+
uri: http://localhost:8000/v1/functions/by_path/test/sdk/test_create_function_async
1111
response:
1212
body:
1313
string: '{"errors":[{"type":"HTTPException","message":"Function not found","detail":"Function
1414
not found"}]}'
1515
headers:
16-
Connection:
17-
- keep-alive
18-
Content-Length:
16+
content-length:
1917
- '98'
20-
Content-Type:
18+
content-type:
2119
- application/json
22-
Date:
23-
- Thu, 22 Aug 2024 14:01:54 GMT
20+
date:
21+
- Tue, 15 Oct 2024 14:17:41 GMT
2422
server:
2523
- uvicorn
2624
status:
@@ -41,21 +39,19 @@ interactions:
4139
content-type:
4240
- application/json
4341
method: POST
44-
uri: https://api.opper.ai/v1/functions
42+
uri: http://localhost:8000/v1/functions
4543
response:
4644
body:
47-
string: '{"id":7129,"uuid":"cf49e2ab-7896-41cb-8052-80c829006f16","dataset_uuid":"a118aaf3-8c72-4f1f-aabc-769da84966c1","description":"Test
45+
string: '{"id":34,"uuid":"a100d8fb-c3c9-43eb-a23d-7a727e15207d","dataset_uuid":"c5e7c7d8-9f5e-4718-adf3-56e267504fee","description":"Test
4846
function","few_shot_count":2,"few_shot":false,"index_ids":[],"input_schema":null,"instructions":"Do
49-
something","language_model_id":null,"model":"azure/gpt4-eu","out_schema":null,"path":"test/sdk/test_create_function_async","project":{"uuid":"1e29233e-9569-4fa3-a40c-edfd42d65e8d","name":"jctestsql"},"revision":1,"use_semantic_search":false}'
47+
something","language_model_id":null,"model":"azure/gpt4-eu","out_schema":null,"path":"test/sdk/test_create_function_async","project":{"uuid":"e64848ae-df03-4c0b-9a6f-4c498bf3dc8b","name":"asdfasdf"},"revision":1,"use_semantic_search":false}'
5048
headers:
51-
Connection:
52-
- keep-alive
53-
Content-Length:
54-
- '472'
55-
Content-Type:
49+
content-length:
50+
- '469'
51+
content-type:
5652
- application/json
57-
Date:
58-
- Thu, 22 Aug 2024 14:01:55 GMT
53+
date:
54+
- Tue, 15 Oct 2024 14:17:41 GMT
5955
server:
6056
- uvicorn
6157
status:
@@ -69,17 +65,15 @@ interactions:
6965
connection:
7066
- keep-alive
7167
method: DELETE
72-
uri: https://api.opper.ai/v1/functions/cf49e2ab-7896-41cb-8052-80c829006f16
68+
uri: http://localhost:8000/v1/functions/a100d8fb-c3c9-43eb-a23d-7a727e15207d
7369
response:
7470
body:
7571
string: ''
7672
headers:
77-
Connection:
78-
- keep-alive
79-
Content-Type:
73+
content-type:
8074
- application/json
81-
Date:
82-
- Thu, 22 Aug 2024 14:01:55 GMT
75+
date:
76+
- Tue, 15 Oct 2024 14:17:41 GMT
8377
server:
8478
- uvicorn
8579
status:

0 commit comments

Comments
 (0)