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

embedding 3 fix dimensions #47

Merged
merged 1 commit into from
Aug 8, 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
24 changes: 24 additions & 0 deletions tests/integration_tests/test_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,27 @@ def test_embeddings(logging_conf):
print(err)
except zhipuai.core._errors.APIStatusError as err:
print(err)


def test_embeddings_dimensions(logging_conf):
logging.config.dictConfig(logging_conf) # type: ignore

client = ZhipuAI()
try:
response = client.embeddings.create(
model="embedding-3", #填写需要调用的模型名称
input="你好",
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 zhipuai.core._errors.APIRequestFailedError as err:
print(err)
except zhipuai.core._errors.APIInternalError as err:
print(err)
except zhipuai.core._errors.APIStatusError as err:
print(err)
2 changes: 2 additions & 0 deletions zhipuai/api_resource/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create(
*,
input: Union[str, List[str], List[int], List[List[int]]],
model: Union[str],
dimensions: Union[int],
encoding_format: str | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
request_id: Optional[str] | NotGiven = NOT_GIVEN,
Expand All @@ -39,6 +40,7 @@ def create(
body={
"input": input,
"model": model,
"dimensions": dimensions,
"encoding_format": encoding_format,
"user": user,
"request_id": request_id,
Expand Down