Observed since 20 Oct, 21:48 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
AgentDev provides basic components that used on Bailian.platform with unified API
AgentDev is a component-based framework for building AI-powered applications. Key features include:
pip install agentdev
Create a python file named main.py with the following code.
Notice that the DashscopeChatRequest is the original Dashscope chat request format,
if you want to use openai compatible request, you can use OpenAIChatRequest or BailianChatRequest instead.
from agentdev.models.llm import BaseLLM
from agentdev.schemas.llm_schemas import DashscopeChatRequest
from agentdev.server.fastapi_server import FastApiServer
async def general_arun(request: DashscopeChatRequest):
"""Test arun method"""
llm = BaseLLM()
try:
async for chunk in await llm.arun(model=request.model, messages=request.input.messages,
parameters=request.parameters):
yield chunk
except Exception as e:
import traceback
print(f'error {e} with traceback {traceback.format_exc()}')
server = FastApiServer(
func=general_arun,
endpoint_path='/api/v1/chat/completions',
request_model=DashscopeChatRequest,
)
if __name__ == '__main__':
server.run()
Then run the python file with your DASHSCOPE_API_KEY
export DASHSCOPE_API_KEY=your_api_key
python main.py
then a local llm service will run on your local machine at http://127.0.0.1:8000/api/v1/chat/completions
query the service with curl
curl --location 'http://127.0.0.1:8000/api/v1/chat/completions' \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen-max",
"input":{
"messages":[{"role": "user", "content":"今天天气如何"}]
},
"parameters": {
}
}'
the response should be like this
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"","role":"assistant"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"我"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"目前"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"无法直接获取实时天气"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"信息。您可以通过查询网络"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"、使用天气应用查看"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":",或者告诉我您"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"所在的城市和地区,我可以提供"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"一些一般性的天气信息和"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"建议。如果需要准确"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"的天气情况,请参考"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"当地的气象预报。"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":""},"finish_reason":"stop","index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
import asyncio
from agentdev.base.component import Component
from pydantic import BaseModel, Field
from typing import Any
# define the input format
class SearchInput(BaseModel):
"""
Search Input.
"""
query: str = Field(..., title='Query')
context: dict
# define the output format
class SearchOutput(BaseModel):
"""
Search Output.
"""
results: list[str]
context: dict
# define the component runtime method
class SearchComponent(Component[SearchInput, SearchOutput]):
"""
Search Component.
"""
async def arun(self, args: SearchInput, **kwargs: Any) -> SearchOutput:
"""
Run asynchronously.
"""
if not isinstance(args, SearchInput):
raise TypeError(
'Argument must be an instance of SearchInput or its subclass')
await asyncio.sleep(1) # 模拟异步操作
return SearchOutput(results=['result1', 'result2'],
context=args.context)
# instantiate the component
search_component = SearchComponent(
name='Search Component',
description='Search Component For Example',
config={})
search_input = SearchInput(query='query', context={})
# run
async def main():
search_output = await search_component.arun(search_input)
print(search_output)
print(search_component.function_schema)
asyncio.run(main())
Run tests using pytest:
pytest test/
Please follow these guidelines:
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.5.0 | 26 May 2025 | 23 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 21:48 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:f319fba5d32dd851fd14494f69a927b04bedd4038835fbcdd842ea3c14f40a46