Skip to content

Commit a23b7e4

Browse files
authored
Merge branch 'master' into lyh_tool_token
2 parents 989560a + 473c93f commit a23b7e4

File tree

55 files changed

+7691
-1659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+7691
-1659
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 🐛 Bug Report
22
description: File an issue about a bug.
33
title: "[BUG] "
4-
labels: [bug]
4+
labels: [bug, Needs Triage]
55
body:
66
- type: markdown
77
attributes:
@@ -26,7 +26,7 @@ body:
2626
attributes:
2727
label: What version of camel are you using?
2828
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
29-
placeholder: E.g., 0.2.78
29+
placeholder: E.g., 0.2.79a0
3030
validations:
3131
required: true
3232

.github/ISSUE_TEMPLATE/feature_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: ✨ Feature Request
22
description: Suggest an idea for this project.
33
title: "[Feature Request] "
4-
labels: [enhancement]
4+
labels: [Needs Triage]
55
body:
66
- type: checkboxes
77
id: steps

.github/ISSUE_TEMPLATE/questions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 🤔 Questions / Help / Support
22
description: Do you need support?
33
title: "[Question] "
4-
labels: [question]
4+
labels: [question, Needs Triage]
55
body:
66
- type: checkboxes
77
id: steps
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: PR Label Automation
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
7+
permissions:
8+
pull-requests: write
9+
10+
jobs:
11+
add-labels:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Add Review Required label
15+
uses: actions/github-script@v7
16+
with:
17+
github-token: ${{ secrets.GITHUB_TOKEN }}
18+
script: |
19+
github.rest.issues.addLabels({
20+
owner: context.repo.owner,
21+
repo: context.repo.repo,
22+
issue_number: context.issue.number,
23+
labels: ['Review Required']
24+
})

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repos:
44
hooks:
55
- id: ruff
66
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
7-
exclude: ^(docs/cookbooks/|examples/usecases/) # Ignore files under docs/cookbooks and examples/usecases
7+
exclude: ^(docs/cookbooks/|examples/usecases/|examples/custom_client_usage\.py) # Ignore files under docs/cookbooks and examples/usecases
88
- id: ruff-format
99
exclude: ^(docs/cookbooks/|examples/usecases/) # Ignore files under docs/cookbooks and examples/usecases
1010

camel/__init__.py

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

1515
from camel.logger import disable_logging, enable_logging, set_log_level
1616

17-
__version__ = '0.2.78'
17+
__version__ = '0.2.79a0'
1818

1919
__all__ = [
2020
'__version__',

camel/models/aws_bedrock_model.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,11 @@
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1414

1515
import os
16-
from typing import Any, Dict, List, Optional, Type, Union
17-
18-
from openai import AsyncStream
19-
from pydantic import BaseModel
16+
from typing import Any, Dict, Optional, Union
2017

2118
from camel.configs import BedrockConfig
22-
from camel.messages import OpenAIMessage
2319
from camel.models.openai_compatible_model import OpenAICompatibleModel
2420
from camel.types import (
25-
ChatCompletion,
26-
ChatCompletionChunk,
2721
ModelType,
2822
)
2923
from camel.utils import BaseTokenCounter, api_keys_required
@@ -93,13 +87,3 @@ def __init__(
9387
max_retries=max_retries,
9488
**kwargs,
9589
)
96-
97-
async def _arun(
98-
self,
99-
messages: List[OpenAIMessage],
100-
response_format: Optional[Type[BaseModel]] = None,
101-
tools: Optional[List[Dict[str, Any]]] = None,
102-
) -> Union[ChatCompletion, AsyncStream[ChatCompletionChunk]]:
103-
raise NotImplementedError(
104-
"AWS Bedrock does not support async inference."
105-
)

camel/models/azure_openai_model.py

Lines changed: 78 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,19 @@ class AzureOpenAIModel(BaseModelBackend):
8888
(default: :obj:`None`)
8989
max_retries (int, optional): Maximum number of retries for API calls.
9090
(default: :obj:`3`)
91+
client (Optional[Any], optional): A custom synchronous AzureOpenAI
92+
client instance. If provided, this client will be used instead of
93+
creating a new one. Useful for RL frameworks like AReaL or rLLM
94+
that provide Azure OpenAI-compatible clients. The client should
95+
implement the AzureOpenAI client interface with
96+
`.chat.completions.create()` and `.beta.chat.completions.parse()`
97+
methods. (default: :obj:`None`)
98+
async_client (Optional[Any], optional): A custom asynchronous
99+
AzureOpenAI client instance. If provided, this client will be
100+
used instead of creating a new one. The client should implement
101+
the AsyncAzureOpenAI client interface. (default: :obj:`None`)
91102
**kwargs (Any): Additional arguments to pass to the client
92-
initialization.
103+
initialization. Ignored if custom clients are provided.
93104
94105
References:
95106
https://learn.microsoft.com/en-us/azure/ai-services/openai/
@@ -108,6 +119,8 @@ def __init__(
108119
azure_ad_token_provider: Optional["AzureADTokenProvider"] = None,
109120
azure_ad_token: Optional[str] = None,
110121
max_retries: int = 3,
122+
client: Optional[Any] = None,
123+
async_client: Optional[Any] = None,
111124
**kwargs: Any,
112125
) -> None:
113126
if model_config_dict is None:
@@ -138,56 +151,72 @@ def __init__(
138151
"or `AZURE_DEPLOYMENT_NAME` environment variable."
139152
)
140153

141-
if is_langfuse_available():
142-
from langfuse.openai import AsyncAzureOpenAI as LangfuseAsyncOpenAI
143-
from langfuse.openai import AzureOpenAI as LangfuseOpenAI
144-
145-
self._client = LangfuseOpenAI(
146-
azure_endpoint=str(self._url),
147-
azure_deployment=self._azure_deployment_name,
148-
api_version=self.api_version,
149-
api_key=self._api_key,
150-
azure_ad_token=self._azure_ad_token,
151-
azure_ad_token_provider=self.azure_ad_token_provider,
152-
timeout=self._timeout,
153-
max_retries=max_retries,
154-
**kwargs,
155-
)
156-
self._async_client = LangfuseAsyncOpenAI(
157-
azure_endpoint=str(self._url),
158-
azure_deployment=self._azure_deployment_name,
159-
api_version=self.api_version,
160-
api_key=self._api_key,
161-
azure_ad_token=self._azure_ad_token,
162-
azure_ad_token_provider=self.azure_ad_token_provider,
163-
timeout=self._timeout,
164-
max_retries=max_retries,
165-
**kwargs,
166-
)
154+
# Use custom clients if provided, otherwise create new ones
155+
if client is not None:
156+
# Use the provided custom sync client
157+
self._client = client
167158
else:
168-
self._client = AzureOpenAI(
169-
azure_endpoint=str(self._url),
170-
azure_deployment=self._azure_deployment_name,
171-
api_version=self.api_version,
172-
api_key=self._api_key,
173-
azure_ad_token=self._azure_ad_token,
174-
azure_ad_token_provider=self.azure_ad_token_provider,
175-
timeout=self._timeout,
176-
max_retries=max_retries,
177-
**kwargs,
178-
)
159+
# Create default sync client
160+
if is_langfuse_available():
161+
from langfuse.openai import AzureOpenAI as LangfuseOpenAI
162+
163+
self._client = LangfuseOpenAI(
164+
azure_endpoint=str(self._url),
165+
azure_deployment=self._azure_deployment_name,
166+
api_version=self.api_version,
167+
api_key=self._api_key,
168+
azure_ad_token=self._azure_ad_token,
169+
azure_ad_token_provider=self.azure_ad_token_provider,
170+
timeout=self._timeout,
171+
max_retries=max_retries,
172+
**kwargs,
173+
)
174+
else:
175+
self._client = AzureOpenAI(
176+
azure_endpoint=str(self._url),
177+
azure_deployment=self._azure_deployment_name,
178+
api_version=self.api_version,
179+
api_key=self._api_key,
180+
azure_ad_token=self._azure_ad_token,
181+
azure_ad_token_provider=self.azure_ad_token_provider,
182+
timeout=self._timeout,
183+
max_retries=max_retries,
184+
**kwargs,
185+
)
179186

180-
self._async_client = AsyncAzureOpenAI(
181-
azure_endpoint=str(self._url),
182-
azure_deployment=self._azure_deployment_name,
183-
api_version=self.api_version,
184-
api_key=self._api_key,
185-
azure_ad_token=self._azure_ad_token,
186-
azure_ad_token_provider=self.azure_ad_token_provider,
187-
timeout=self._timeout,
188-
max_retries=max_retries,
189-
**kwargs,
190-
)
187+
if async_client is not None:
188+
# Use the provided custom async client
189+
self._async_client = async_client
190+
else:
191+
# Create default async client
192+
if is_langfuse_available():
193+
from langfuse.openai import (
194+
AsyncAzureOpenAI as LangfuseAsyncOpenAI,
195+
)
196+
197+
self._async_client = LangfuseAsyncOpenAI(
198+
azure_endpoint=str(self._url),
199+
azure_deployment=self._azure_deployment_name,
200+
api_version=self.api_version,
201+
api_key=self._api_key,
202+
azure_ad_token=self._azure_ad_token,
203+
azure_ad_token_provider=self.azure_ad_token_provider,
204+
timeout=self._timeout,
205+
max_retries=max_retries,
206+
**kwargs,
207+
)
208+
else:
209+
self._async_client = AsyncAzureOpenAI(
210+
azure_endpoint=str(self._url),
211+
azure_deployment=self._azure_deployment_name,
212+
api_version=self.api_version,
213+
api_key=self._api_key,
214+
azure_ad_token=self._azure_ad_token,
215+
azure_ad_token_provider=self.azure_ad_token_provider,
216+
timeout=self._timeout,
217+
max_retries=max_retries,
218+
**kwargs,
219+
)
191220

192221
@property
193222
def token_counter(self) -> BaseTokenCounter:

camel/models/model_factory.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1414
import json
1515
import os
16-
from typing import ClassVar, Dict, Optional, Type, Union
16+
from typing import Any, ClassVar, Dict, Optional, Type, Union
1717

1818
from camel.models.aiml_model import AIMLModel
1919
from camel.models.amd_model import AMDModel
@@ -119,6 +119,8 @@ def create(
119119
url: Optional[str] = None,
120120
timeout: Optional[float] = None,
121121
max_retries: int = 3,
122+
client: Optional[Any] = None,
123+
async_client: Optional[Any] = None,
122124
**kwargs,
123125
) -> BaseModelBackend:
124126
r"""Creates an instance of `BaseModelBackend` of the specified type.
@@ -145,6 +147,14 @@ def create(
145147
for API calls. (default: :obj:`None`)
146148
max_retries (int, optional): Maximum number of retries
147149
for API calls. (default: :obj:`3`)
150+
client (Optional[Any], optional): A custom synchronous client
151+
instance. Supported by models that use OpenAI-compatible APIs
152+
. The client should implement the appropriate client interface
153+
for the platform. (default: :obj:`None`)
154+
async_client (Optional[Any], optional): A custom asynchronous
155+
client instance. Supported by models that use OpenAI-compatible
156+
APIs. The client should implement the appropriate async client
157+
interface for the platform. (default: :obj:`None`)
148158
**kwargs: Additional model-specific parameters that will be passed
149159
to the model constructor. For example, Azure OpenAI models may
150160
require `api_version`, `azure_deployment_name`,
@@ -190,6 +200,12 @@ def create(
190200
if model_class is None:
191201
raise ValueError(f"Unknown model platform `{model_platform}`")
192202

203+
# Pass client and async_client via kwargs if provided
204+
if client is not None:
205+
kwargs['client'] = client
206+
if async_client is not None:
207+
kwargs['async_client'] = async_client
208+
193209
return model_class(
194210
model_type=model_type,
195211
model_config_dict=model_config_dict,

0 commit comments

Comments
 (0)