Skip to content
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

fix: DIA-1402: Include async GET/POST interactions for /refine #333

Merged
merged 2 commits into from
Oct 4, 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
20 changes: 17 additions & 3 deletions .mock/definition/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2347,20 +2347,34 @@ types:
organization: optional<PromptVersionOrganization>
source:
openapi: openapi/openapi.yaml
RefinedPromptResponseRefinementStatus:
enum:
- Pending
- InProgress
- Completed
- Failed
docs: Status of the refinement job
default: Pending
source:
openapi: openapi/openapi.yaml
RefinedPromptResponse:
properties:
title:
type: string
type: optional<string>
docs: Title of the refined prompt
reasoning:
type: string
type: optional<string>
docs: Reasoning behind the refinement
prompt:
type: string
docs: The refined prompt text
refinement_job_id:
type: string
type: optional<string>
docs: Unique identifier for the refinement job
refinement_status:
type: optional<RefinedPromptResponseRefinementStatus>
docs: Status of the refinement job
default: Pending
source:
openapi: openapi/openapi.yaml
InferenceRunOrganization:
Expand Down
41 changes: 41 additions & 0 deletions .mock/definition/prompts/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,46 @@ service:
organization: 1
audiences:
- public
get_refined_prompt:
path: /api/prompts/{prompt_id}/versions/{version_id}/refine
method: GET
auth: true
docs: |
Get the refined prompt based on the `refinement_job_id`.
path-parameters:
prompt_id:
type: integer
docs: Prompt ID
version_id:
type: integer
docs: Prompt Version ID
display-name: Get refined prompt
request:
name: VersionsGetRefinedPromptRequest
query-parameters:
refinement_job_id:
type: string
docs: >-
Refinement Job ID acquired from the `POST
/api/prompts/{prompt_id}/versions/{version_id}/refine` endpoint
response:
docs: ''
type: root.RefinedPromptResponse
examples:
- path-parameters:
prompt_id: 1
version_id: 1
query-parameters:
refinement_job_id: refinement_job_id
response:
body:
title: title
reasoning: reasoning
prompt: prompt
refinement_job_id: refinement_job_id
refinement_status: Pending
audiences:
- public
refine_prompt:
path: /api/prompts/{prompt_id}/versions/{version_id}/refine
method: POST
Expand Down Expand Up @@ -204,6 +244,7 @@ service:
reasoning: reasoning
prompt: prompt
refinement_job_id: refinement_job_id
refinement_status: Pending
audiences:
- public
source:
Expand Down
88 changes: 88 additions & 0 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -15161,6 +15161,94 @@ client.prompts.versions.update(
</dl>


</dd>
</dl>
</details>

<details><summary><code>client.prompts.versions.<a href="src/label_studio_sdk/prompts/versions/client.py">get_refined_prompt</a>(...)</code></summary>
<dl>
<dd>

#### 📝 Description

<dl>
<dd>

<dl>
<dd>

Get the refined prompt based on the `refinement_job_id`.
</dd>
</dl>
</dd>
</dl>

#### 🔌 Usage

<dl>
<dd>

<dl>
<dd>

```python
from label_studio_sdk.client import LabelStudio

client = LabelStudio(
api_key="YOUR_API_KEY",
)
client.prompts.versions.get_refined_prompt(
prompt_id=1,
version_id=1,
refinement_job_id="refinement_job_id",
)

```
</dd>
</dl>
</dd>
</dl>

#### ⚙️ Parameters

<dl>
<dd>

<dl>
<dd>

**prompt_id:** `int` — Prompt ID

</dd>
</dl>

<dl>
<dd>

**version_id:** `int` — Prompt Version ID

</dd>
</dl>

<dl>
<dd>

**refinement_job_id:** `str` — Refinement Job ID acquired from the `POST /api/prompts/{prompt_id}/versions/{version_id}/refine` endpoint

</dd>
</dl>

<dl>
<dd>

**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.

</dd>
</dl>
</dd>
</dl>


</dd>
</dl>
</details>
Expand Down
2 changes: 2 additions & 0 deletions src/label_studio_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
RedisImportStorage,
RedisImportStorageStatus,
RefinedPromptResponse,
RefinedPromptResponseRefinementStatus,
S3ExportStorage,
S3ExportStorageStatus,
S3ImportStorage,
Expand Down Expand Up @@ -277,6 +278,7 @@
"RedisImportStorage",
"RedisImportStorageStatus",
"RefinedPromptResponse",
"RefinedPromptResponseRefinementStatus",
"S3ExportStorage",
"S3ExportStorageStatus",
"S3ImportStorage",
Expand Down
114 changes: 114 additions & 0 deletions src/label_studio_sdk/prompts/versions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,63 @@ def update(
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

def get_refined_prompt(
self,
prompt_id: int,
version_id: int,
*,
refinement_job_id: str,
request_options: typing.Optional[RequestOptions] = None,
) -> RefinedPromptResponse:
"""
Get the refined prompt based on the `refinement_job_id`.

Parameters
----------
prompt_id : int
Prompt ID

version_id : int
Prompt Version ID

refinement_job_id : str
Refinement Job ID acquired from the `POST /api/prompts/{prompt_id}/versions/{version_id}/refine` endpoint

request_options : typing.Optional[RequestOptions]
Request-specific configuration.

Returns
-------
RefinedPromptResponse


Examples
--------
from label_studio_sdk.client import LabelStudio

client = LabelStudio(
api_key="YOUR_API_KEY",
)
client.prompts.versions.get_refined_prompt(
prompt_id=1,
version_id=1,
refinement_job_id="refinement_job_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"api/prompts/{jsonable_encoder(prompt_id)}/versions/{jsonable_encoder(version_id)}/refine",
method="GET",
params={"refinement_job_id": refinement_job_id},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return pydantic_v1.parse_obj_as(RefinedPromptResponse, _response.json()) # type: ignore
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

def refine_prompt(
self,
prompt_id: int,
Expand Down Expand Up @@ -727,6 +784,63 @@ async def update(
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

async def get_refined_prompt(
self,
prompt_id: int,
version_id: int,
*,
refinement_job_id: str,
request_options: typing.Optional[RequestOptions] = None,
) -> RefinedPromptResponse:
"""
Get the refined prompt based on the `refinement_job_id`.

Parameters
----------
prompt_id : int
Prompt ID

version_id : int
Prompt Version ID

refinement_job_id : str
Refinement Job ID acquired from the `POST /api/prompts/{prompt_id}/versions/{version_id}/refine` endpoint

request_options : typing.Optional[RequestOptions]
Request-specific configuration.

Returns
-------
RefinedPromptResponse


Examples
--------
from label_studio_sdk.client import AsyncLabelStudio

client = AsyncLabelStudio(
api_key="YOUR_API_KEY",
)
await client.prompts.versions.get_refined_prompt(
prompt_id=1,
version_id=1,
refinement_job_id="refinement_job_id",
)
"""
_response = await self._client_wrapper.httpx_client.request(
f"api/prompts/{jsonable_encoder(prompt_id)}/versions/{jsonable_encoder(version_id)}/refine",
method="GET",
params={"refinement_job_id": refinement_job_id},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return pydantic_v1.parse_obj_as(RefinedPromptResponse, _response.json()) # type: ignore
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

async def refine_prompt(
self,
prompt_id: int,
Expand Down
2 changes: 2 additions & 0 deletions src/label_studio_sdk/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from .redis_import_storage import RedisImportStorage
from .redis_import_storage_status import RedisImportStorageStatus
from .refined_prompt_response import RefinedPromptResponse
from .refined_prompt_response_refinement_status import RefinedPromptResponseRefinementStatus
from .s3export_storage import S3ExportStorage
from .s3export_storage_status import S3ExportStorageStatus
from .s3import_storage import S3ImportStorage
Expand Down Expand Up @@ -169,6 +170,7 @@
"RedisImportStorage",
"RedisImportStorageStatus",
"RefinedPromptResponse",
"RefinedPromptResponseRefinementStatus",
"S3ExportStorage",
"S3ExportStorageStatus",
"S3ImportStorage",
Expand Down
12 changes: 9 additions & 3 deletions src/label_studio_sdk/types/refined_prompt_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

from ..core.datetime_utils import serialize_datetime
from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1
from .refined_prompt_response_refinement_status import RefinedPromptResponseRefinementStatus


class RefinedPromptResponse(pydantic_v1.BaseModel):
title: str = pydantic_v1.Field()
title: typing.Optional[str] = pydantic_v1.Field(default=None)
"""
Title of the refined prompt
"""

reasoning: str = pydantic_v1.Field()
reasoning: typing.Optional[str] = pydantic_v1.Field(default=None)
"""
Reasoning behind the refinement
"""
Expand All @@ -23,11 +24,16 @@ class RefinedPromptResponse(pydantic_v1.BaseModel):
The refined prompt text
"""

refinement_job_id: str = pydantic_v1.Field()
refinement_job_id: typing.Optional[str] = pydantic_v1.Field(default=None)
"""
Unique identifier for the refinement job
"""

refinement_status: typing.Optional[RefinedPromptResponseRefinementStatus] = pydantic_v1.Field(default=None)
"""
Status of the refinement job
"""

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
return super().json(**kwargs_with_defaults)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was auto-generated by Fern from our API Definition.

import typing

RefinedPromptResponseRefinementStatus = typing.Union[
typing.Literal["Pending", "InProgress", "Completed", "Failed"], typing.Any
]
Loading