Skip to content

Commit 0efa440

Browse files
authored
embedding 3 fix dimensions (#47)
1 parent 2196150 commit 0efa440

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/integration_tests/test_embedding.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,27 @@ def test_embeddings(logging_conf):
2424
print(err)
2525
except zhipuai.core._errors.APIStatusError as err:
2626
print(err)
27+
28+
29+
def test_embeddings_dimensions(logging_conf):
30+
logging.config.dictConfig(logging_conf) # type: ignore
31+
32+
client = ZhipuAI()
33+
try:
34+
response = client.embeddings.create(
35+
model="embedding-3", #填写需要调用的模型名称
36+
input="你好",
37+
dimensions=512,
38+
extra_body={"model_version": "v1"}
39+
)
40+
assert response.data[0].object == "embedding"
41+
assert len(response.data[0].embedding) == 512
42+
print(len(response.data[0].embedding))
43+
44+
45+
except zhipuai.core._errors.APIRequestFailedError as err:
46+
print(err)
47+
except zhipuai.core._errors.APIInternalError as err:
48+
print(err)
49+
except zhipuai.core._errors.APIStatusError as err:
50+
print(err)

zhipuai/api_resource/embeddings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def create(
2222
*,
2323
input: Union[str, List[str], List[int], List[List[int]]],
2424
model: Union[str],
25+
dimensions: Union[int],
2526
encoding_format: str | NotGiven = NOT_GIVEN,
2627
user: str | NotGiven = NOT_GIVEN,
2728
request_id: Optional[str] | NotGiven = NOT_GIVEN,
@@ -39,6 +40,7 @@ def create(
3940
body={
4041
"input": input,
4142
"model": model,
43+
"dimensions": dimensions,
4244
"encoding_format": encoding_format,
4345
"user": user,
4446
"request_id": request_id,

0 commit comments

Comments
 (0)