-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 定义不太文件类型解析类 * 文件管理相关接口 * 知识库管理业务 * 知识库管理集成测试 * 知识库管理集成测试 * 修改embedding_model * pythonsdk,上传知识库文件接口缺少参数custom_separator pythonsdk,查询知识库接口多了一个data参数,参考文档修改 pythonsdk,文件上传接口,response对象DocumentSuccessinfo中多余参数,参考文档修改 请求knowledge.document.list报错 查询文件详情接口参照文档修改,多了几个参数 * pydantic-core = ">=2.14.6"
- Loading branch information
Showing
38 changed files
with
1,584 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,88 @@ | ||
from zhipuai import ZhipuAI | ||
import zhipuai | ||
|
||
from __future__ import annotations | ||
|
||
import unittest | ||
import os | ||
|
||
import logging | ||
import logging.config | ||
|
||
import zhipuai | ||
|
||
import httpx | ||
import pytest | ||
from respx import MockRouter | ||
|
||
from zhipuai import ZhipuAI | ||
from zhipuai.api_resource import FilesWithRawResponse | ||
|
||
@pytest.fixture(scope='class') | ||
def test_server(): | ||
class SharedData: | ||
client = ZhipuAI() | ||
file_id1 = None | ||
file_id2 = None | ||
|
||
return SharedData() | ||
|
||
|
||
class TestZhipuAIFileServer: | ||
|
||
def test_logs(self, logging_conf): | ||
logging.config.dictConfig(logging_conf) # type: ignore | ||
|
||
def test_files(self,test_server, test_file_path): | ||
|
||
try: | ||
result = test_server.client.files.create( | ||
file=open(os.path.join(test_file_path,"demo.jsonl"), "rb"), | ||
purpose="fine-tune" | ||
) | ||
print(result) | ||
test_server.file_id1 = result.id | ||
|
||
|
||
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) | ||
|
||
|
||
def test_files_validation(self,test_server, test_file_path): | ||
try: | ||
result = test_server.client.files.create( | ||
file=open(os.path.join(test_file_path,"demo.jsonl"), "rb"), | ||
purpose="fine-tune" | ||
) | ||
print(result) | ||
|
||
test_server.file_id2 = result.id | ||
|
||
|
||
|
||
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) | ||
|
||
|
||
def test_files_list(self,test_server): | ||
try: | ||
list = test_server.client.files.list() | ||
print(list) | ||
|
||
|
||
|
||
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) | ||
|
||
|
||
|
||
def test_files(test_file_path, logging_conf): | ||
logging.config.dictConfig(logging_conf) # type: ignore | ||
client = ZhipuAI() | ||
try: | ||
result = client.files.create( | ||
file=open(os.path.join(test_file_path,"demo.jsonl"), "rb"), | ||
purpose="fine-tune" | ||
) | ||
print(result) | ||
# "file-20240418025911536-6dqgr" | ||
|
||
|
||
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) | ||
|
||
|
||
def test_files_validation(test_file_path, logging_conf): | ||
logging.config.dictConfig(logging_conf) # type: ignore | ||
client = ZhipuAI() | ||
try: | ||
result = client.files.create( | ||
file=open(os.path.join(test_file_path,"demo.jsonl"), "rb"), | ||
purpose="fine-tune" | ||
) | ||
print(result) | ||
# "file-20240418025931214-c87tj" | ||
|
||
|
||
|
||
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) | ||
|
||
def test_files_list(logging_conf): | ||
logging.config.dictConfig(logging_conf) # type: ignore | ||
client = ZhipuAI() | ||
try: | ||
list = client.files.list() | ||
print(list) | ||
|
||
|
||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
from __future__ import annotations | ||
|
||
import unittest | ||
import os | ||
|
||
import logging | ||
import logging.config | ||
|
||
import zhipuai | ||
|
||
import httpx | ||
import pytest | ||
from respx import MockRouter | ||
|
||
from zhipuai import ZhipuAI | ||
|
||
|
||
@pytest.fixture(scope='class') | ||
def test_server(): | ||
class SharedData: | ||
client = ZhipuAI() | ||
test_knowledge_document_id = None | ||
test_knowledge_id = None | ||
|
||
return SharedData() | ||
|
||
|
||
class TestZhipuAIKnowledgeServer: | ||
|
||
def test_logs(self, logging_conf): | ||
logging.config.dictConfig(logging_conf) # type: ignore | ||
|
||
def test_knowledge_create(self, test_server): | ||
|
||
try: | ||
result = test_server.client.knowledge.create( | ||
embedding_id=1, | ||
name="test", | ||
description="测试", | ||
background="blue", | ||
icon="question", | ||
|
||
) | ||
print(result) | ||
test_server.test_knowledge_id = result.id | ||
|
||
|
||
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) | ||
|
||
def test_knowledge_document_create(self, test_server, test_file_path): | ||
|
||
try: | ||
result = test_server.client.knowledge.document.create( | ||
file=open(os.path.join(test_file_path, "file.xlsx"), "rb"), | ||
purpose="retrieval", | ||
knowledge_id=test_server.test_knowledge_id, | ||
sentence_size=202 | ||
) | ||
print(result) | ||
test_server.test_knowledge_document_id = result.successInfos[0].documentId | ||
|
||
|
||
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) | ||
|
||
def test_knowledge_modify(self, test_server): | ||
|
||
try: | ||
result = test_server.client.knowledge.modify( | ||
knowledge_id=test_server.test_knowledge_id, | ||
embedding_id=1, | ||
name="测试1", | ||
background="red", | ||
icon="book", | ||
|
||
) | ||
print(result) | ||
|
||
|
||
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) | ||
|
||
def test_knowledge_query(self, test_server): | ||
|
||
try: | ||
result = test_server.client.knowledge.query( | ||
) | ||
print(result) | ||
|
||
|
||
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) | ||
|
||
def test_knowledge_used(self, test_server): | ||
|
||
try: | ||
result = test_server.client.knowledge.used( | ||
) | ||
print(result) | ||
|
||
|
||
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) | ||
|
||
def test_knowledge_document_retrieve(self, test_server, test_file_path): | ||
try: | ||
result = test_server.client.knowledge.document.retrieve( | ||
test_server.test_knowledge_document_id | ||
) | ||
print(result) | ||
|
||
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) | ||
|
||
def test_knowledge_document_edit(self, test_server): | ||
try: | ||
result = test_server.client.knowledge.document.edit( | ||
document_id=test_server.test_knowledge_document_id, | ||
knowledge_type="1", | ||
sentence_size=204, | ||
) | ||
print(result) | ||
|
||
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) | ||
|
||
def test_knowledge_document_list(self, test_server): | ||
try: | ||
result = test_server.client.knowledge.document.list( | ||
test_server.test_knowledge_id, | ||
purpose="retrieval" | ||
) | ||
print(result) | ||
|
||
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) | ||
|
||
def test_knowledge_document_delete(self, test_server): | ||
try: | ||
file1 = test_server.client.knowledge.document.delete(test_server.test_knowledge_document_id) | ||
print(file1) | ||
|
||
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) | ||
|
||
def test_knowledge_delete(self, test_server): | ||
|
||
try: | ||
result = test_server.client.knowledge.delete( | ||
knowledge_id=test_server.test_knowledge_id | ||
) | ||
print(result) | ||
|
||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"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}} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.