Skip to content

feat(api): OpenAPI spec update via Stainless API #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.prism.log
.vscode
_dev

Expand Down
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 21
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/prompt-foundry%2Fprompt-foundry-sdk-d9b855455d537bcf385efd28281b3ec5d7a7169fca24bf1961e9b58fb8202b7c.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/prompt-foundry%2Fprompt-foundry-sdk-34a4feda5ed017fa6e768340bc744158d41437857466ad44d553ec4a5c1083d9.yml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ response = client.prompts.with_raw_response.get_parameters(
print(response.headers.get('X-My-Header'))

prompt = response.parse() # get the object that `prompts.get_parameters()` would have returned
print(prompt.provider)
print(prompt)
```

These methods return an [`APIResponse`](https://github.com/prompt-foundry/python-sdk/tree/main/src/prompt_foundry_python_sdk/_response.py) object.
Expand Down
5 changes: 4 additions & 1 deletion src/prompt_foundry_python_sdk/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@
maybe_transform as maybe_transform,
async_maybe_transform as async_maybe_transform,
)
from ._reflection import function_has_argument as function_has_argument
from ._reflection import (
function_has_argument as function_has_argument,
assert_signatures_in_sync as assert_signatures_in_sync,
)
34 changes: 34 additions & 0 deletions src/prompt_foundry_python_sdk/_utils/_reflection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import inspect
from typing import Any, Callable

Expand All @@ -6,3 +8,35 @@ def function_has_argument(func: Callable[..., Any], arg_name: str) -> bool:
"""Returns whether or not the given function has a specific parameter"""
sig = inspect.signature(func)
return arg_name in sig.parameters


def assert_signatures_in_sync(
source_func: Callable[..., Any],
check_func: Callable[..., Any],
*,
exclude_params: set[str] = set(),
) -> None:
"""Ensure that the signature of the second function matches the first."""

check_sig = inspect.signature(check_func)
source_sig = inspect.signature(source_func)

errors: list[str] = []

for name, source_param in source_sig.parameters.items():
if name in exclude_params:
continue

custom_param = check_sig.parameters.get(name)
if not custom_param:
errors.append(f"the `{name}` param is missing")
continue

if custom_param.annotation != source_param.annotation:
errors.append(
f"types for the `{name}` param are do not match; source={repr(source_param.annotation)} checking={repr(source_param.annotation)}"
)
continue

if errors:
raise AssertionError(f"{len(errors)} errors encountered when comparing signatures:\n\n" + "\n\n".join(errors))
64 changes: 35 additions & 29 deletions src/prompt_foundry_python_sdk/resources/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Dict, Iterable, Optional
from typing import Any, Dict, Iterable, Optional, cast

import httpx

Expand Down Expand Up @@ -257,21 +257,24 @@ def get_parameters(
"""
if not id:
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
return self._post(
f"/sdk/v1/prompts/{id}",
body=maybe_transform(
{
"append_messages": append_messages,
"override_messages": override_messages,
"user": user,
"variables": variables,
},
prompt_get_parameters_params.PromptGetParametersParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
return cast(
ModelParameters,
self._post(
f"/sdk/v1/prompts/{id}",
body=maybe_transform(
{
"append_messages": append_messages,
"override_messages": override_messages,
"user": user,
"variables": variables,
},
prompt_get_parameters_params.PromptGetParametersParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=cast(Any, ModelParameters), # Union types cannot be passed in as arguments in the type system
),
cast_to=ModelParameters,
)


Expand Down Expand Up @@ -501,21 +504,24 @@ async def get_parameters(
"""
if not id:
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
return await self._post(
f"/sdk/v1/prompts/{id}",
body=await async_maybe_transform(
{
"append_messages": append_messages,
"override_messages": override_messages,
"user": user,
"variables": variables,
},
prompt_get_parameters_params.PromptGetParametersParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
return cast(
ModelParameters,
await self._post(
f"/sdk/v1/prompts/{id}",
body=await async_maybe_transform(
{
"append_messages": append_messages,
"override_messages": override_messages,
"user": user,
"variables": variables,
},
prompt_get_parameters_params.PromptGetParametersParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=cast(Any, ModelParameters), # Union types cannot be passed in as arguments in the type system
),
cast_to=ModelParameters,
)


Expand Down
Loading