AgentEra / Agently-Daily-News-Collector

An open-source LLM based automatically daily news collecting workflow showcase powered by Agently AI application development framework.
http://agently.tech
Apache License 2.0
423 stars 70 forks source link

MODEL_PROVIDER: OAIClient #10

Closed JayGatsby1 closed 3 months ago

JayGatsby1 commented 3 months ago

MODEL_PROVIDER: OAIClient #默认使用OpenAI格式的兼容客户端,此客户端能够适配OpenAI以及各类兼容OpenAI格式的本地模型

您好,测试过程兼容OpenAI格式的本地模型都有哪些?

Agently Guidebook

Apply Developers WeChat Group or Scan QR Code to Apply.

image
Maplemx commented 3 months ago

Use Ollama or Xinference to start a local model service. Their model services are compatible OpenAI format automatically.

使用Ollama或者Xinference这样的本地模型推理服务启动框架,他们的本地服务默认适配了OpenAI的格式

JayGatsby1 commented 3 months ago

好的 谢谢。

JayGatsby1 commented 3 months ago

您好,我安装完X inference和Agently环境后通过一下两种方式访问:

  1. 通过命令行的方式访问(没有问题) curl -X 'POST' \ 'http://127.0.0.1:9997/v1/chat/completions' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "model": "my-internlm2-chat", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "你好,请介绍一下你自己?" } ] }' {"id":"chat286fe888-25c2-11ef-a6bb-0242ac110004","object":"chat.completion","created":1717870130,"model":"my-internlm2-chat","choices":[{"index":0,"message":{"role":"assistant","content":"您好!我是一名人工智能助手,能够帮助您完成各种基于语言的任务。我致力于通过执行常见的基于语言的任务和提供建议来帮助人类。如果您有任何问题或需要帮助,请随时向我提问。"},"finish_reason":"stop"}],"usage":{"prompt_tokens":-1,"completion_tokens":-1,"total_tokens":-1}}%

2.通过Agently框架访问-报错 import Agently

agent_factory = ( Agently.AgentFactory() .set_settings("current_model", "OAIClient") .set_settings("model.OAIClient.auth", { "api_key": "" }) .set_settings("model.OAIClient.url", "http://127.0.0.1:9997/v1") .set_settings("model.OAIClient.options", { "model": "my-internlm2-chat" }) ) agent = agent_factory.create_agent()

@agent.on_event("delta") def handler(data): print(data,end="")

result = ( agent.input("你好,请介绍下你自己?") .start() ) pass

Exception in thread Thread-1: Traceback (most recent call last): File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/Agently/Agent/Agent.py", line 240, in start_in_theard reply = loop.run_until_complete(self.start_async(request_type)) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/Agently/Agent/Agent.py", line 227, in start_async raise(e) File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/Agently/Agent/Agent.py", line 177, in start_async event_generator = await self.request.get_event_generator(request_type) File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/Agently/Request/Request.py", line 116, in get_event_generator response_generator = await request_plugin_export"request_model" File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/Agently/plugins/request/OAIClient.py", line 208, in request_model stream = await client.chat.completions.create(**request_data) File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/openai/resources/chat/completions.py", line 1181, in create return await self._post( File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/openai/_base_client.py", line 1790, in post return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls) File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/openai/_base_client.py", line 1493, in request return await self._request( File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/openai/_base_client.py", line 1569, in _request return await self._retry_request( File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/openai/_base_client.py", line 1615, in _retry_request return await self._request( File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/openai/_base_client.py", line 1569, in _request return await self._retry_request( File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/openai/_base_client.py", line 1615, in _retry_request return await self._request( File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/openai/_base_client.py", line 1584, in _request raise self._make_status_error_from_response(err.response) from None openai.InternalServerError: Error code: 502

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/Users/yangli/Library/Python/3.8/lib/python/site-packages/Agently/Agent/Agent.py", line 243, in start_in_theard raise Exception(f"[Agent Request] Error: { str(e) }") Exception: [Agent Request] Error: Error code: 502

这是为什么?

Maplemx commented 3 months ago

您好,请问如果尝试把.set_settings("model.OAIClient.auth", { "api_key": "" })注释掉,能够正常工作吗

JayGatsby1 commented 3 months ago

您好。不可以。

JayGatsby1 commented 3 months ago

您好,关闭本地代理就解决上面问题。

JayGatsby1 commented 3 months ago

2024-06-14 02:22:24,694 - ERROR - Node Execution Exception-'generate_columns'(8db2f047-6ac4-4ac2-8dfd-0cc9065b0ec4): asyncio.run() cannot be called from a running event loop Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 336, in _exec_chunk_with_dep_core exec_res = chunk_executor(input_value, self.store) File "/Users/yangli/Desktop/doc/ChatGPT/Agently-Daily-News-Collector-main/workflows/main_workflow.py", line 58, in generate_columns_executor column_data = start_column_workflow( File "/Users/yangli/Desktop/doc/ChatGPT/Agently-Daily-News-Collector-main/workflows/column_workflow.py", line 152, in start column_workflow.start() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/Workflow.py", line 76, in start res = asyncio.run(self.start_async(start_data)) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 33, in run raise RuntimeError( RuntimeError: asyncio.run() cannot be called from a running event loop

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/yangli/Desktop/doc/ChatGPT/Agently-Daily-News-Collector-main/./app.py", line 21, in main_workflow.start( File "/Users/yangli/Desktop/doc/ChatGPT/Agently-Daily-News-Collector-main/workflows/main_workflow.py", line 109, in start main_workflow.start() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/Workflow.py", line 76, in start res = asyncio.run(self.start_async(start_data)) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/Workflow.py", line 72, in start_async res = await self.executor.start(executed_schema, start_data) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 46, in start await self._execute_main(executed_schema.get('entries') or []) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 101, in _execute_main await asyncio.gather(entry_tasks) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 87, in execute_from_entry await self._execute_partial( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 175, in _execute_partial await asyncio.gather(next_child_tasks) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 146, in _execute_partial await execute_child_chunk(next_chunk) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 129, in execute_child_chunk child_executed = await self._execute_single_chunk( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 203, in _execute_single_chunk await self._execute_single_chunk_core( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 230, in _execute_single_chunk_core exec_value = await self._exec_chunk_with_dep_core(chunk, single_dep_map) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 340, in _exec_chunk_with_dep_core raise Exception(e) Exception: asyncio.run() cannot be called from a running event loop sys:1: RuntimeWarning: coroutine 'Workflow.start_async' was never awaited

Maplemx commented 3 months ago

2024-06-14 02:22:24,694 - ERROR - Node Execution Exception-'generate_columns'(8db2f047-6ac4-4ac2-8dfd-0cc9065b0ec4): asyncio.run() cannot be called from a running event loop Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 336, in _exec_chunk_with_dep_core exec_res = chunk_executor(input_value, self.store) File "/Users/yangli/Desktop/doc/ChatGPT/Agently-Daily-News-Collector-main/workflows/main_workflow.py", line 58, in generate_columns_executor column_data = start_column_workflow( File "/Users/yangli/Desktop/doc/ChatGPT/Agently-Daily-News-Collector-main/workflows/column_workflow.py", line 152, in start column_workflow.start() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/Workflow.py", line 76, in start res = asyncio.run(self.start_async(start_data)) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 33, in run raise RuntimeError( RuntimeError: asyncio.run() cannot be called from a running event loop

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/yangli/Desktop/doc/ChatGPT/Agently-Daily-News-Collector-main/./app.py", line 21, in main_workflow.start( File "/Users/yangli/Desktop/doc/ChatGPT/Agently-Daily-News-Collector-main/workflows/main_workflow.py", line 109, in start main_workflow.start() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/Workflow.py", line 76, in start res = asyncio.run(self.start_async(start_data)) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/Workflow.py", line 72, in start_async res = await self.executor.start(executed_schema, start_data) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 46, in start await self._execute_main(executed_schema.get('entries') or []) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 101, in _execute_main await asyncio.gather(entry_tasks) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 87, in execute_from_entry await self._execute_partial( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 175, in _execute_partial await asyncio.gather(next_child_tasks) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 146, in _execute_partial await execute_child_chunk(next_chunk) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 129, in execute_child_chunk child_executed = await self._execute_single_chunk( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 203, in _execute_single_chunk await self._execute_single_chunk_core( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 230, in _execute_single_chunk_core exec_value = await self._exec_chunk_with_dep_core(chunk, single_dep_map) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Agently/Workflow/MainExecutor.py", line 340, in _exec_chunk_with_dep_core raise Exception(e) Exception: asyncio.run() cannot be called from a running event loop sys:1: RuntimeWarning: coroutine 'Workflow.start_async' was never awaited

这个问题是主框架升级3.3.0.0版本更新了workflow的工作内核逻辑导致的,因为之前workflow不支持list循环,项目里用了奇怪的方式进行适配,我后续会修改项目的实现方式

现在重装一下Agently框架,回退到3.2.2.11版本即可

pip install Agently==3.2.2.11

我也已经修改了requirements.txt文件,做了版本限制

Maplemx commented 3 months ago

新版本3.3.1.2已经适配了当前的表达方式,能够支持在workflow里直接用.start()嵌套另一个workflow了

该问题完全修正了