Repository navigation
Expand file tree
/
Copy pathtest_assistant_api.py
More file actions
75 lines (69 loc) · 2.33 KB
/
Copy pathtest_assistant_api.py
File metadata and controls
75 lines (69 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
# Copyright (c) Alibaba, Inc. and its affiliates.
from dashscope import Assistants
import os
assistant = Assistants.create(
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 此处以qwen-max为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
model="qwen-max",
name="smart helper",
description="A tool helper.",
instructions="You are a helpful assistant. When asked a question, use tools wherever possible.",
tools=[
{
"type": "search",
},
{
"type": "function",
"function": {
"name": "big_add",
"description": "Add to number",
"parameters": {
"type": "object",
"properties": {
"left": {
"type": "integer",
"description": "The left operator",
},
"right": {
"type": "integer",
"description": "The right operator.",
},
},
"required": ["left", "right"],
},
},
},
],
top_k=10,
top_p=0.5,
temperature=1.0,
max_tokens=2048,
)
print(f"\n初始Assistant: request_id: {assistant.request_id}")
print(f"{assistant}\n")
print(
f"top_p: {assistant.top_p}, top_k: {assistant.top_k}, temperature: {assistant.temperature}, max_tokens: {assistant.max_tokens}, object: {assistant.object}",
)
# ==== test case 2: 新增和更新参数 =====
assistant = Assistants.update(
assistant.id,
top_k=9,
top_p=0.4,
temperature=0.9,
max_tokens=1024,
)
print(f"\n更新参数: request_id: {assistant.request_id}")
print(
f"top_p: {assistant.top_p}, top_k: {assistant.top_k}, temperature: {assistant.temperature}, max_tokens: {assistant.max_tokens}, object: {assistant.object}",
)
# ===== test case 1: 清空tools =====
# # 更新智能体:仅更新模型,Tools不变
# assistant = Assistants.update(assistant.id, model='qwen-plus')
# print('\n更新Model后')
# print(assistant)
#
# # 更新智能体: 清空Tools
# assistant = Assistants.update(assistant.id, tools=[])
# print('\n清空Tools后')
# print(assistant)