Skip to content

Commit 02f13ad

Browse files
feat(api): OpenAPI spec update via Stainless API (#104)
1 parent af8d3ab commit 02f13ad

File tree

11 files changed

+347
-114
lines changed

11 files changed

+347
-114
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.prism.log
12
.vscode
23
_dev
34

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 21
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/prompt-foundry%2Fprompt-foundry-sdk-d9b855455d537bcf385efd28281b3ec5d7a7169fca24bf1961e9b58fb8202b7c.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/prompt-foundry%2Fprompt-foundry-sdk-34a4feda5ed017fa6e768340bc744158d41437857466ad44d553ec4a5c1083d9.yml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ response = client.prompts.with_raw_response.get_parameters(
214214
print(response.headers.get('X-My-Header'))
215215

216216
prompt = response.parse() # get the object that `prompts.get_parameters()` would have returned
217-
print(prompt.provider)
217+
print(prompt)
218218
```
219219

220220
These methods return an [`APIResponse`](https://github.com/prompt-foundry/python-sdk/tree/main/src/prompt_foundry_python_sdk/_response.py) object.

src/prompt_foundry_python_sdk/_utils/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@
4949
maybe_transform as maybe_transform,
5050
async_maybe_transform as async_maybe_transform,
5151
)
52-
from ._reflection import function_has_argument as function_has_argument
52+
from ._reflection import (
53+
function_has_argument as function_has_argument,
54+
assert_signatures_in_sync as assert_signatures_in_sync,
55+
)

src/prompt_foundry_python_sdk/_utils/_reflection.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import inspect
24
from typing import Any, Callable
35

@@ -6,3 +8,35 @@ def function_has_argument(func: Callable[..., Any], arg_name: str) -> bool:
68
"""Returns whether or not the given function has a specific parameter"""
79
sig = inspect.signature(func)
810
return arg_name in sig.parameters
11+
12+
13+
def assert_signatures_in_sync(
14+
source_func: Callable[..., Any],
15+
check_func: Callable[..., Any],
16+
*,
17+
exclude_params: set[str] = set(),
18+
) -> None:
19+
"""Ensure that the signature of the second function matches the first."""
20+
21+
check_sig = inspect.signature(check_func)
22+
source_sig = inspect.signature(source_func)
23+
24+
errors: list[str] = []
25+
26+
for name, source_param in source_sig.parameters.items():
27+
if name in exclude_params:
28+
continue
29+
30+
custom_param = check_sig.parameters.get(name)
31+
if not custom_param:
32+
errors.append(f"the `{name}` param is missing")
33+
continue
34+
35+
if custom_param.annotation != source_param.annotation:
36+
errors.append(
37+
f"types for the `{name}` param are do not match; source={repr(source_param.annotation)} checking={repr(source_param.annotation)}"
38+
)
39+
continue
40+
41+
if errors:
42+
raise AssertionError(f"{len(errors)} errors encountered when comparing signatures:\n\n" + "\n\n".join(errors))

src/prompt_foundry_python_sdk/resources/prompts.py

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, Iterable, Optional
5+
from typing import Any, Dict, Iterable, Optional, cast
66

77
import httpx
88

@@ -257,21 +257,24 @@ def get_parameters(
257257
"""
258258
if not id:
259259
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
260-
return self._post(
261-
f"/sdk/v1/prompts/{id}",
262-
body=maybe_transform(
263-
{
264-
"append_messages": append_messages,
265-
"override_messages": override_messages,
266-
"user": user,
267-
"variables": variables,
268-
},
269-
prompt_get_parameters_params.PromptGetParametersParams,
270-
),
271-
options=make_request_options(
272-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
260+
return cast(
261+
ModelParameters,
262+
self._post(
263+
f"/sdk/v1/prompts/{id}",
264+
body=maybe_transform(
265+
{
266+
"append_messages": append_messages,
267+
"override_messages": override_messages,
268+
"user": user,
269+
"variables": variables,
270+
},
271+
prompt_get_parameters_params.PromptGetParametersParams,
272+
),
273+
options=make_request_options(
274+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
275+
),
276+
cast_to=cast(Any, ModelParameters), # Union types cannot be passed in as arguments in the type system
273277
),
274-
cast_to=ModelParameters,
275278
)
276279

277280

@@ -501,21 +504,24 @@ async def get_parameters(
501504
"""
502505
if not id:
503506
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
504-
return await self._post(
505-
f"/sdk/v1/prompts/{id}",
506-
body=await async_maybe_transform(
507-
{
508-
"append_messages": append_messages,
509-
"override_messages": override_messages,
510-
"user": user,
511-
"variables": variables,
512-
},
513-
prompt_get_parameters_params.PromptGetParametersParams,
514-
),
515-
options=make_request_options(
516-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
507+
return cast(
508+
ModelParameters,
509+
await self._post(
510+
f"/sdk/v1/prompts/{id}",
511+
body=await async_maybe_transform(
512+
{
513+
"append_messages": append_messages,
514+
"override_messages": override_messages,
515+
"user": user,
516+
"variables": variables,
517+
},
518+
prompt_get_parameters_params.PromptGetParametersParams,
519+
),
520+
options=make_request_options(
521+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
522+
),
523+
cast_to=cast(Any, ModelParameters), # Union types cannot be passed in as arguments in the type system
517524
),
518-
cast_to=ModelParameters,
519525
)
520526

521527

0 commit comments

Comments
 (0)