z-ai-sdk-python/tests/integration_tests/test_embedding.py
wellenzheng 81cffb6cc4
feat: translate and enrich doc (#3)
* init

* enrich doc

* init

* init

* init

* doc

* chore: remove deprecated email field from pyproject.toml

* feat: translate content from Chinese to English and update documentation

This commit translates all Chinese text content in the codebase to English, including:
- Test messages and prompts
- Error messages
- Documentation strings
- API parameter descriptions
- README and release notes content

The changes ensure consistency in language usage across the entire project while maintaining all functionality. Documentation has been updated to reflect these changes and provide clearer English descriptions of features and usage.

* refactor: update branding from ZaiClient to Z.ai

Update SDK name in README and HTTP headers to reflect new branding. Also update endpoint references in type definitions.

* ci: allow spaces in PR commit message subject pattern

---------

Co-authored-by: zhengweijun <weijun.zheng@aminer.cn>
2025-07-11 15:20:27 +08:00

48 lines
1.2 KiB
Python

import logging
import logging.config
import zai
from zai import ZaiClient
def test_embeddings(logging_conf):
logging.config.dictConfig(logging_conf) # type: ignore
client = ZaiClient()
try:
response = client.embeddings.create(
model='embedding-2', # Fill in the model name to call
input='hello',
extra_body={'model_version': 'v1'},
)
print(response)
except zai.core._errors.APIRequestFailedError as err:
print(err)
except zai.core._errors.APIInternalError as err:
print(err)
except zai.core._errors.APIStatusError as err:
print(err)
def test_embeddings_dimensions(logging_conf):
logging.config.dictConfig(logging_conf) # type: ignore
client = ZaiClient()
try:
response = client.embeddings.create(
model='embedding-3', # Fill in the model name to call
input='hello',
dimensions=512,
extra_body={'model_version': 'v1'},
)
assert response.data[0].object == 'embedding'
assert len(response.data[0].embedding) == 512
print(len(response.data[0].embedding))
except zai.core._errors.APIRequestFailedError as err:
print(err)
except zai.core._errors.APIInternalError as err:
print(err)
except zai.core._errors.APIStatusError as err:
print(err)