Skip to content

Commit

Permalink
update to get file content (#38165)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhakulin authored Oct 29, 2024
1 parent f780407 commit 222a07d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 57 deletions.
4 changes: 3 additions & 1 deletion sdk/ai/azure-ai-projects/azure/ai/projects/aio/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ def upload_file(self, file_path: Union[Path, str, PathLike]) -> str:
from azure.ai.ml.constants import AssetTypes
except ImportError:
raise ImportError(
"azure-ai-ml must be installed to use this function. Please install it using `pip install azure-ai-ml`")
"azure-ai-ml must be installed to use this function. Please install it using `pip install azure-ai-ml`"
)

data = Data(
path=file_path,
Expand Down Expand Up @@ -273,6 +274,7 @@ def scope(self) -> Dict[str, str]:
"project_name": self._config3.project_name,
}


__all__: List[str] = [
"AIProjectClient",
] # Add all objects you want publicly available to users at this package level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3517,13 +3517,13 @@ async def get_file(self, file_id: str, **kwargs: Any) -> _models.OpenAIFile:
return deserialized # type: ignore

@distributed_trace_async
async def get_file_content(self, file_id: str, **kwargs: Any) -> _models.FileContentResponse:
"""Returns information about a specific file. Does not retrieve file content.
async def get_file_content(self, file_id: str, **kwargs: Any) -> bytes:
"""Retrieves the raw content of a specific file.
:param file_id: The ID of the file to retrieve. Required.
:type file_id: str
:return: FileContentResponse. The FileContentResponse is compatible with MutableMapping
:rtype: ~azure.ai.projects.models.FileContentResponse
:return: bytes
:rtype: bytes
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map: MutableMapping = {
Expand All @@ -3537,7 +3537,7 @@ async def get_file_content(self, file_id: str, **kwargs: Any) -> _models.FileCon
_headers = kwargs.pop("headers", {}) or {}
_params = kwargs.pop("params", {}) or {}

cls: ClsType[_models.FileContentResponse] = kwargs.pop("cls", None)
cls: ClsType[bytes] = kwargs.pop("cls", None)

_request = build_agents_get_file_content_request(
file_id=file_id,
Expand Down Expand Up @@ -3574,7 +3574,7 @@ async def get_file_content(self, file_id: str, **kwargs: Any) -> _models.FileCon
if _stream:
deserialized = response.iter_bytes()
else:
deserialized = _deserialize(_models.FileContentResponse, response.json())
deserialized = _deserialize(bytes, response.json(), format="base64")

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore
Expand Down
2 changes: 0 additions & 2 deletions sdk/ai/azure-ai-projects/azure/ai/projects/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
Evaluation,
EvaluationSchedule,
EvaluatorConfiguration,
FileContentResponse,
FileDeletionStatus,
FileListResponse,
FileSearchToolDefinition,
Expand Down Expand Up @@ -218,7 +217,6 @@
"Evaluation",
"EvaluationSchedule",
"EvaluatorConfiguration",
"FileContentResponse",
"FileDeletionStatus",
"FileListResponse",
"FileSearchToolDefinition",
Expand Down
29 changes: 0 additions & 29 deletions sdk/ai/azure-ai-projects/azure/ai/projects/models/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,35 +1137,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)


class FileContentResponse(_model_base.Model):
"""A response from a file get content operation.
:ivar content: The content of the file, in bytes. Required.
:vartype content: bytes
"""

content: bytes = rest_field(format="base64")
"""The content of the file, in bytes. Required."""

@overload
def __init__(
self,
*,
content: bytes,
) -> None: ...

@overload
def __init__(self, mapping: Mapping[str, Any]) -> None:
"""
:param mapping: raw JSON to initialize the model.
:type mapping: Mapping[str, Any]
"""

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)


class FileDeletionStatus(_model_base.Model):
"""A status response from a file deletion operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4913,13 +4913,13 @@ def get_file(self, file_id: str, **kwargs: Any) -> _models.OpenAIFile:
return deserialized # type: ignore

@distributed_trace
def get_file_content(self, file_id: str, **kwargs: Any) -> _models.FileContentResponse:
"""Returns information about a specific file. Does not retrieve file content.
def get_file_content(self, file_id: str, **kwargs: Any) -> bytes:
"""Retrieves the raw content of a specific file.
:param file_id: The ID of the file to retrieve. Required.
:type file_id: str
:return: FileContentResponse. The FileContentResponse is compatible with MutableMapping
:rtype: ~azure.ai.projects.models.FileContentResponse
:return: bytes
:rtype: bytes
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map: MutableMapping = {
Expand All @@ -4933,7 +4933,7 @@ def get_file_content(self, file_id: str, **kwargs: Any) -> _models.FileContentRe
_headers = kwargs.pop("headers", {}) or {}
_params = kwargs.pop("params", {}) or {}

cls: ClsType[_models.FileContentResponse] = kwargs.pop("cls", None)
cls: ClsType[bytes] = kwargs.pop("cls", None)

_request = build_agents_get_file_content_request(
file_id=file_id,
Expand Down Expand Up @@ -4970,7 +4970,7 @@ def get_file_content(self, file_id: str, **kwargs: Any) -> _models.FileContentRe
if _stream:
deserialized = response.iter_bytes()
else:
deserialized = _deserialize(_models.FileContentResponse, response.json())
deserialized = _deserialize(bytes, response.json(), format="base64")

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ async def main():
# id=RelevanceEvaluator.id,
id="azureml://registries/azureml-staging/models/Relevance-Evaluator/versions/3",
init_params={
"model_config": default_connection.to_evaluator_model_config(deployment_name=deployment_name,
api_version=api_version)
"model_config": default_connection.to_evaluator_model_config(
deployment_name=deployment_name, api_version=api_version
)
},
),
"violence": EvaluatorConfiguration(
# id=ViolenceEvaluator.id,
id="azureml://registries/azureml-staging/models/Violent-Content-Evaluator/versions/3",
init_params={
"azure_ai_project": project_client.scope
},
init_params={"azure_ai_project": project_client.scope},
),
},
)
Expand All @@ -86,7 +85,5 @@ async def main():
print("----------------------------------------------------------------")




if __name__ == "__main__":
asyncio.run(main())
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@
# id=RelevanceEvaluator.id,
id="azureml://registries/azureml-staging/models/Relevance-Evaluator/versions/3",
init_params={
"model_config": default_connection.to_evaluator_model_config(deployment_name=deployment_name,
api_version=api_version)
"model_config": default_connection.to_evaluator_model_config(
deployment_name=deployment_name, api_version=api_version
)
},
),
"violence": EvaluatorConfiguration(
# id=ViolenceEvaluator.id,
id="azureml://registries/azureml-staging/models/Violent-Content-Evaluator/versions/3",
init_params={
"azure_ai_project": project_client.scope
},
init_params={"azure_ai_project": project_client.scope},
),
},
)
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/azure-ai-projects/tsp-location.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
directory: specification/ai/Azure.AI.Projects
commit: d60552bb88d19b2c7cc7978619aeddcc5f9dd602
commit: d46982df7fb73959661c21c4ee47d56935ea8e22
repo: Azure/azure-rest-api-specs
additionalDirectories:

0 comments on commit 222a07d

Please sign in to comment.