Skip to content

Commit 8ca64b5

Browse files
authored
Merge pull request #74 from MetaGLM/feature/agent-api-0622
Feature/agent api 0622
2 parents 6fd4142 + 98e905f commit 8ca64b5

File tree

14 files changed

+248
-262
lines changed

14 files changed

+248
-262
lines changed

tests/agent/glm3_agent.py

Lines changed: 0 additions & 141 deletions
This file was deleted.

tests/agent/test_agent.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/agent/test_create_structured_funcation_call.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

tests/agent/test_prompt_parser_agent.py

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import os.path
2+
3+
from zhipuai import ZhipuAI
4+
import zhipuai
5+
import time
6+
7+
import logging
8+
import logging.config
9+
10+
11+
def test_completions_sync(logging_conf):
12+
logging.config.dictConfig(logging_conf) # type: ignore
13+
client = ZhipuAI() # 填写您自己的APIKey
14+
try:
15+
# 生成request_id
16+
request_id = time.time()
17+
print(f"request_id:{request_id}")
18+
response = client.agents.invoke(
19+
request_id=request_id,
20+
agent_id="general_translation",
21+
messages=[
22+
{
23+
"role": "user",
24+
"content": "tell me a joke"
25+
}
26+
],
27+
user_id="12345678"
28+
)
29+
print(response)
30+
31+
except zhipuai.core._errors.APIRequestFailedError as err:
32+
print(err)
33+
except zhipuai.core._errors.APIInternalError as err:
34+
print(err)
35+
except zhipuai.core._errors.APIStatusError as err:
36+
print(err)
37+
38+
def test_completions_stream(logging_conf):
39+
logging.config.dictConfig(logging_conf) # type: ignore
40+
client = ZhipuAI() # 填写您自己的APIKey
41+
try:
42+
# 生成request_id
43+
request_id = time.time()
44+
print(f"request_id:{request_id}")
45+
response = client.agents.invoke(
46+
request_id=request_id,
47+
agent_id="general_translation",
48+
messages=[
49+
{
50+
"role": "user",
51+
"content": "tell me a joke"
52+
}
53+
],
54+
user_id="12345678",
55+
stream=True
56+
)
57+
for item in response:
58+
print(item)
59+
60+
61+
except zhipuai.core._errors.APIRequestFailedError as err:
62+
print(err)
63+
except zhipuai.core._errors.APIInternalError as err:
64+
print(err)
65+
except zhipuai.core._errors.APIStatusError as err:
66+
print(err)

zhipuai/_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def __init__(
6868
self.web_search = api_resource.WebSearchApi(self)
6969
self.audio = api_resource.audio.Audio(self)
7070
self.moderation = api_resource.moderation.Moderation(self)
71+
self.agents = api_resource.agents.Agents(self)
7172

7273
@property
7374
@override

zhipuai/api_resource/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
WebSearchApi
4646
)
4747

48+
from .agents import (
49+
Agents
50+
)
51+
4852
__all__ = [
4953
'Videos',
5054
'AsyncCompletions',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from zhipuai.api_resource.agents.agents import Agents
2+
3+
__all__= [
4+
"Agents"
5+
]

0 commit comments

Comments
 (0)