Skip to content
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
67 changes: 67 additions & 0 deletions .github/workflows/_integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: integration_test

on:
workflow_dispatch:
inputs:
working-directory:
required: true
type: string
default: '.'
description: "From which folder this pipeline executes"

env:
POETRY_VERSION: "1.7.1"

jobs:
build:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest

environment: Scheduled testing publish
outputs:
pkg-name: ${{ steps.check-version.outputs.pkg-name }}
version: ${{ steps.check-version.outputs.version }}
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
name: "make integration_test #${{ matrix.python-version }}"
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: core


- name: Import test dependencies
run: poetry install --with test
working-directory: ${{ inputs.working-directory }}

- name: Run integration tests
shell: bash
env:
ZHIPUAI_API_KEY: ${{ secrets.ZHIPUAI_API_KEY }}
ZHIPUAI_BASE_URL: ${{ secrets.ZHIPUAI_BASE_URL }}
run: |
make integration_tests

- name: Ensure the tests did not create any additional files
shell: bash
run: |
set -eu

STATUS="$(git status)"
echo "$STATUS"

# grep will exit non-zero if the target message isn't found,
# and `set -e` above will cause the step to fail.
echo "$STATUS" | grep 'nothing to commit, working tree clean'
61 changes: 61 additions & 0 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: test

on:
workflow_dispatch:
inputs:
working-directory:
required: true
type: string
default: '.'
description: "From which folder this pipeline executes"

env:
POETRY_VERSION: "1.7.1"

jobs:
build:
defaults:
run:
working-directory: ${{ inputs.working-directory }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
name: "make test #${{ matrix.python-version }}"
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: core


- name: Import test dependencies
run: poetry install --with test
working-directory: ${{ inputs.working-directory }}

- name: Run core tests
shell: bash
run: |
make test

- name: Ensure the tests did not create any additional files
shell: bash
run: |
set -eu

STATUS="$(git status)"
echo "$STATUS"

# grep will exit non-zero if the target message isn't found,
# and `set -e` above will cause the step to fail.
echo "$STATUS" | grep 'nothing to commit, working tree clean'
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pydantic = ">=1.9.0,<3.0"
pydantic-core = ">=2.14.6"
cachetools = ">=4.2.2"
pyjwt = "~=2.8.0"
pandas = {version = ">=1.0.0", python = ">=3.8,<3.9.7 || >3.9.7,<4.0"}
openpyxl = {version = ">=3.1.0", python = ">=3.8,<3.9.7 || >3.9.7,<4.0"}


[tool.poetry.group.test.dependencies]
Expand Down
Binary file removed tests/unit_tests/batchinput.xlsx
Binary file not shown.
20 changes: 1 addition & 19 deletions tests/unit_tests/test_http_client_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,7 @@ def test_file_download_jsonl(self, test_file_path: str, respx_mock: MockRouter)

text = next(files_content.iter_text())
assert text == '{"custom_id": "request-1", "method": "POST", "url": "/v4/chat/completions", "body": {"model": "glm-4", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}'

@pytest.mark.respx(base_url=base_url)
def test_file_download_xlsx(self, test_file_path: str, respx_mock: MockRouter) -> None:
with open(os.path.join(test_file_path, "batchinput.xlsx"), "rb") as file:
respx_mock.get("/files/1/content").mock(
return_value=httpx.Response(200, content=file.read(),
headers={
"Content-Type": "application/jsonl",
"Content-Disposition": "attachment; filename=batchinput.xlsx"
}
)
)
legacy = FilesWithRawResponse(self.client.files)
response = legacy.content("1")
files_content = response.parse()
assert files_content.json() == []
text = next(files_content.iter_text())
# 去除换行符
assert text.replace("\n", "") == ""


def test_is_closed(self):
assert self.client.is_closed() is False
Expand Down
3 changes: 1 addition & 2 deletions zhipuai/core/_legacy_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from ._sse_client import StreamResponse, is_stream_class_type, extract_stream_chunk_type
from ._errors import APIResponseValidationError
from ._legacy_binary_response import HttpxBinaryResponseContent, HttpxTextBinaryResponseContent, HttpxResponseContent
from ._legacy_xlsx_response import HttpxXlsxBinaryResponseContent

if TYPE_CHECKING:
from ._request_opt import FinalRequestOptions
Expand Down Expand Up @@ -253,7 +252,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
if filename and filename.endswith(".jsonl"):
return cast(R, HttpxTextBinaryResponseContent(response))
elif filename and filename.endswith(".xlsx"):
return cast(R, HttpxXlsxBinaryResponseContent(response))
return cast(R, HttpxTextBinaryResponseContent(response))
else:
return cast(R, cast_type(response)) # type: ignore

Expand Down
68 changes: 0 additions & 68 deletions zhipuai/core/_legacy_xlsx_response.py

This file was deleted.