Skip to content

Commit 83060de

Browse files
committed
update auto auth
1 parent 78e712d commit 83060de

30 files changed

+507
-738
lines changed

tests/test_agent.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,6 @@ def test_agent_with_tracers():
199199
assert tracer2 in agent.tracers
200200

201201

202-
@patch.dict(
203-
"os.environ",
204-
{"MODEL_AGENT_NAME": "env_model_name", "MODEL_AGENT_API_KEY": "mock_api_key"},
205-
clear=True,
206-
)
207-
def test_agent_environment_variables():
208-
agent = Agent()
209-
print(agent)
210-
assert agent.model_name == "env_model_name"
211-
212-
213202
@patch.dict("os.environ", {"MODEL_AGENT_API_KEY": "mock_api_key"})
214203
def test_agent_custom_name_and_description():
215204
custom_name = "CustomAgent"

tests/test_tos.py

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

veadk/agent.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@
2626
from pydantic import ConfigDict, Field
2727
from typing_extensions import Any
2828

29-
from veadk.config import getenv
29+
from veadk.config import settings
3030
from veadk.consts import (
3131
DEFAULT_AGENT_NAME,
32-
DEFAULT_MODEL_AGENT_API_BASE,
33-
DEFAULT_MODEL_AGENT_NAME,
34-
DEFAULT_MODEL_AGENT_PROVIDER,
3532
DEFAULT_MODEL_EXTRA_CONFIG,
3633
)
3734
from veadk.evaluation import EvalSetRecorder
@@ -63,26 +60,16 @@ class Agent(LlmAgent):
6360
instruction: str = DEFAULT_INSTRUCTION
6461
"""The instruction for the agent, such as principles of function calling."""
6562

66-
model_name: str = Field(
67-
default_factory=lambda: getenv("MODEL_AGENT_NAME", DEFAULT_MODEL_AGENT_NAME)
68-
)
63+
model_name: str = Field(default_factory=lambda: settings.model.name)
6964
"""The name of the model for agent running."""
7065

71-
model_provider: str = Field(
72-
default_factory=lambda: getenv(
73-
"MODEL_AGENT_PROVIDER", DEFAULT_MODEL_AGENT_PROVIDER
74-
)
75-
)
66+
model_provider: str = Field(default_factory=lambda: settings.model.provider)
7667
"""The provider of the model for agent running."""
7768

78-
model_api_base: str = Field(
79-
default_factory=lambda: getenv(
80-
"MODEL_AGENT_API_BASE", DEFAULT_MODEL_AGENT_API_BASE
81-
)
82-
)
69+
model_api_base: str = Field(default_factory=lambda: settings.model.api_base)
8370
"""The api base of the model for agent running."""
8471

85-
model_api_key: str = Field(default_factory=lambda: getenv("MODEL_AGENT_API_KEY"))
72+
model_api_key: str = Field(default_factory=lambda: settings.model.api_key)
8673
"""The api key of the model for agent running."""
8774

8875
model_extra_config: dict = Field(default_factory=dict)

veadk/auth/veauth/apmplus_veauth.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ def __init__(
2828
self,
2929
access_key: str = os.getenv("VOLCENGINE_ACCESS_KEY", ""),
3030
secret_key: str = os.getenv("VOLCENGINE_SECRET_KEY", ""),
31+
region: str = "cn-beijing",
3132
) -> None:
3233
super().__init__(access_key, secret_key)
3334

35+
self.region = region
36+
3437
self._token: str = ""
3538

3639
@override
@@ -44,8 +47,10 @@ def _fetch_token(self) -> None:
4447
sk=self.secret_key,
4548
service="apmplus_server",
4649
version="2024-07-30",
47-
region="cn-beijing",
50+
region=self.region,
4851
host="open.volcengineapi.com",
52+
# APMPlus frontend required
53+
header={"X-Apmplus-Region": self.region.replace("-", "_")},
4954
)
5055
try:
5156
self._token = res["data"]["app_key"]

veadk/auth/veauth/ark_veauth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(
3535

3636
@override
3737
def _fetch_token(self) -> None:
38+
logger.info("Fetching ARK token...")
3839
# list api keys
3940
first_api_key_id = ""
4041
res = ve_request(

veadk/auth/veauth/base_veauth.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import os
1616
from abc import ABC, abstractmethod
17-
from typing import Type
1817

1918
from veadk.auth.base_auth import BaseAuth
2019

@@ -49,36 +48,3 @@ def _fetch_token(self) -> None: ...
4948

5049
@property
5150
def token(self) -> str: ...
52-
53-
54-
def veauth(auth_token_name: str, auth_cls: Type[BaseVeAuth]):
55-
def decorator(cls: Type):
56-
# api_key -> _api_key
57-
# for cache
58-
private_auth_token_name = f"_{auth_token_name}"
59-
setattr(cls, private_auth_token_name, "")
60-
61-
# init a auth cls for fetching token
62-
auth_cls_instance = "_auth_cls_instance"
63-
setattr(cls, auth_cls_instance, auth_cls())
64-
65-
def getattribute(self, name: str):
66-
if name != auth_token_name:
67-
return object.__getattribute__(self, name)
68-
if name == auth_token_name:
69-
token = object.__getattribute__(self, name)
70-
71-
if token:
72-
return token
73-
elif not token and not getattr(cls, private_auth_token_name):
74-
token = getattr(cls, auth_cls_instance).token
75-
setattr(cls, private_auth_token_name, token)
76-
return token
77-
elif not token and getattr(cls, private_auth_token_name):
78-
return getattr(cls, private_auth_token_name)
79-
return token
80-
81-
setattr(cls, "__getattribute__", getattribute)
82-
return cls
83-
84-
return decorator

veadk/auth/veauth/prompt_pilot_veauth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(
3131
) -> None:
3232
super().__init__(access_key, secret_key)
3333

34-
self._token: str | dict = ""
34+
self._token: str = ""
3535

3636
@override
3737
def _fetch_token(self) -> None:
@@ -53,7 +53,7 @@ def _fetch_token(self) -> None:
5353
raise ValueError(f"Failed to get Prompt Pilot token: {res}")
5454

5555
@property
56-
def token(self) -> str | dict:
56+
def token(self) -> str:
5757
if self._token:
5858
return self._token
5959
self._fetch_token()

veadk/cli/cli_deploy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
import click
17+
1718
from veadk.version import VERSION
1819

1920
TEMP_PATH = "/tmp"

veadk/cli/cli_prompt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def prompt(path: str, feedback: str, api_key: str, model_name: str) -> None:
3131
from pathlib import Path
3232

3333
from veadk.agent import Agent
34-
from veadk.config import getenv
34+
from veadk.config import settings
3535
from veadk.integrations.ve_prompt_pilot.ve_prompt_pilot import VePromptPilot
3636
from veadk.utils.misc import load_module_from_file
3737

@@ -55,7 +55,7 @@ def prompt(path: str, feedback: str, api_key: str, model_name: str) -> None:
5555
click.echo(f"Found {len(agents)} agents in {module_abs_path}")
5656

5757
if not api_key:
58-
api_key = getenv("PROMPT_PILOT_API_KEY")
58+
api_key = settings.prompt_pilot.api_key
5959
ve_prompt_pilot = VePromptPilot(api_key)
6060
ve_prompt_pilot.optimize(
6161
agents=agents, feedback=feedback, model_name=model_name

0 commit comments

Comments
 (0)