1.nm纯英文的怎么玩
2.pycharm打开项目
3。创建虚拟环境

python -m venv .venv

4.安装依赖
.venv\Scripts\activarte
pip install openai-agents
5.报错
ERROR: Exception:
Traceback (most recent call last):
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\cli\base_command.py”, line 160, in exc_logging_wrapper
status = run_func(*args)
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\cli\req_command.py”, line 247, in wrapper
return func(self, options, args)
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\commands\install.py”, line 419, in run
requirement_set = resolver.resolve(
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\resolution\resolvelib\resolver.py”, line 92, in resolve
result = self._result = resolver.resolve(
File “E:\openai-agents-python.venv\lib\site-packages\pip_vendor\resolvelib\resolvers.py”, line 481, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File “E:\openai-agents-python.venv\lib\site-packages\pip_vendor\resolvelib\resolvers.py”, line 348, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File “E:\openai-agents-python.venv\lib\site-packages\pip_vendor\resolvelib\resolvers.py”, line 172, in _add_to_criteria
if not criterion.candidates:
File “E:\openai-agents-python.venv\lib\site-packages\pip_vendor\resolvelib\structs.py”, line 151, in bool
return bool(self._sequence)
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\resolution\resolvelib\found_candidates.py”, line 155, in bool
return any(self)
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\resolution\resolvelib\found_candidates.py”, line 143, in
return (c for c in iterator if id© not in self._incompatible_ids)
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\resolution\resolvelib\found_candidates.py”, line 44, in _iter_built
for version, func in infos:
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\resolution\resolvelib\factory.py”, line 279, in iter_index_candidate_info
s
result = self._finder.find_best_candidate(
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\index\package_finder.py”, line 890, in find_best_candidate
candidates = self.find_all_candidates(project_name)
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\index\package_finder.py”, line 831, in find_all_candidates
page_candidates = list(page_candidates_it)
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\index\sources.py”, line 134, in page_candidates
yield from self._candidates_from_page(self.link)
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\index\package_finder.py”, line 795, in process_project_url
page_links = list(parse_links(index_response))
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\index\collector.py”, line 223, in wrapper_wrapper
return list(fn(page))
File “E:\openai-agents-python.venv\lib\site-packages\pip_internal\index\collector.py”, line 236, in parse_links
data = json.loads(page.content)
File "D:\miniconda\lib\json_init
.py", line 346, in loads
return _default_decoder.decode(s)
File “D:\miniconda\lib\json\decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “D:\miniconda\lib\json\decoder.py”, line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 35461 (char 35460)
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=‘pypi.org’, port
=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLEOFError(8, ‘[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in viol
ation of protocol (_ssl.c:1017)’))) - skipping

网络不行,科学上网
6.没有openai 的apikey
7.安装litellm依赖,

pip install litellm
8.创建.ven文件存放apikey
9.报错
[图片]
用text文本就可以了
10.在终端安装依赖

pip install litellm python-dotenv
11.
测试 API 调用(可选)
通过 Anthropic API 兼容,快速测试 MiniMax M2.71. 安装 Anthropic SDK
Python
Node.js
pip install anthropic
2. 配置环境变量
export ANTHROPIC_BASE_URL=https://api.minimaxi.com/anthropicexport ANTHROPIC_API_KEY=${YOUR_API_KEY}
minimax推荐这样兼容接入调用api
13
[图片]
看不懂
14报错,路径问题
(.venv) E:\openai-agents-python>python.\tests\voice\test_haiku.py
系统找不到指定的路径。

(.venv) E:\openai-agents-python>

15报错

你用的 instructions 参数是错误的参数名。

根据 Anthropic Messages API:

  • ❌ instructions — 这个参数不存在

  • ✅ system — 才是用来传递系统提示的正确参数

    解决方法

    把代码中的:
    message = client.messages.create(
    instructions=“…”, # 错误

    )

    改成:
    message = client.messages.create(
    system=“…”, # 正确

    )
    改用流式调用:

    非流式(有 10 分钟限制)

    message = client.messages.create(…)

    流式(无 10 分钟限制) with client.messages.stream(…) as stream:

    message = stream.get_final_message()                                                                              
    

    — 如果你需要我帮你改代码,把文件内容发给我。
    14.安装依赖
    15这是 anthropic SDK 和 httpx 版本不兼容的问题!
    (.venv) E:\openai-agents-python>python tests\test_haiku.py
    Traceback (most recent call last):
    File “E:\openai-agents-python\tests\test_haiku.py”, line 7, in
    client = Anthropic(
    File “D:\miniconda\lib\site-packages\anthropic_client.py”, line 122, in init
    super().init(
    File “D:\miniconda\lib\site-packages\anthropic_base_client.py”, line 825, in init
    self._client = http_client or SyncHttpxClientWrapper(
    File “D:\miniconda\lib\site-packages\anthropic_base_client.py”, line 723, in init
    super().init(**kwargs)
    TypeError: Client.init() got an unexpected keyword argument ‘proxies’

(.venv) E:\openai-agents-python>

pip install --upgrade anthropic升级依赖
16又错
(.venv) E:\openai-agents-python>python tests\test_haiku.py
Traceback (most recent call last):
File “E:\openai-agents-python\tests\test_haiku.py”, line 12, in
message = client.messages.create(
File “D:\miniconda\lib\site-packages\anthropic_utils_utils.py”, line 268, in wrapper
return func(*args, **kwargs)
File “D:\miniconda\lib\site-packages\anthropic\resources\messages\messages.py”, line 973, i
n create
timeout = self._client._calculate_nonstreaming_timeout(
File “D:\miniconda\lib\site-packages\anthropic_base_client.py”, line 736, in _calculate_no
nstreaming_timeout
raise ValueError(
ValueError: Streaming is required for operations that may take longer than 10 minutes. See ht
tps://github.com/anthropics/anthropic-sdk-python#long-requests for more details

(.venv) E:\openai-agents-python>
超时
为什么超时会报错呢?
17.这是因为 API Key 没读到!.env 文件可能没加载成功。
(.venv) E:\openai-agents-python>python tests\test_haiku.py
Traceback (most recent call last):
File “E:\openai-agents-python\tests\test_haiku.py”, line 12, in
message = client.messages.create(
File “D:\miniconda\lib\site-packages\anthropic_utils_utils.py”, line 268, in wrapper
return func(*args, **kwargs)
File “D:\miniconda\lib\site-packages\anthropic\resources\messages\messages.py”, line 991, i
n create
return self._post(
File “D:\miniconda\lib\site-packages\anthropic_base_client.py”, line 1368, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))

File “D:\miniconda\lib\site-packages\anthropic_base_client.py”, line 1062, in request
request = self._build_request(options, retries_taken=retries_taken)
File “D:\miniconda\lib\site-packages\anthropic_base_client.py”, line 521, in _build_reques
t
headers = self._build_headers(options, retries_taken=retries_taken)
File “D:\miniconda\lib\site-packages\anthropic_base_client.py”, line 451, in _build_header
s
self._validate_headers(headers_dict, custom_headers)
File “D:\miniconda\lib\site-packages\anthropic_client.py”, line 196, in _validate_headers
raise TypeError(
TypeError: “Could not resolve authentication method. Expected either api_key or auth_token to
be set. Or for one of the X-Api-Key or Authorization headers to be explicitly omitted”

(.venv) E:\openai-agents-python>

18.ven配置文件写错了,
export 是 Shell 命令

export 是 Linux/bash 的命令,意思是"把这个变量暴露给子进程用"。
不应该用export
==============26/5/2=
1.什么是streaming流式输出?
普通模式等ai全部完成再返回
流式输出:
ai边生成边返回
代码
from agents import Agent

agent = Agent(name=“助手”, instructions=“你是一个有帮助的助手”)

普通模式

result = agent.run(“写一首诗”)
print(result)

流式模式

for event in agent.run_streaming(“写一首诗”):
# event 包含每个token
print(event, end=“”, flush=True)
2.tools的实验使用
代码:
from agents import Agent, tool

@tool
def get_weather(city:str) -> str:
“”“获取城市天气”“”
data = {“北京”:“晴天25度”,“上海”:“雨天20度”}
return data.get(city,“未知城市”)

@tool
def calculate(expression:str) ->str:
“”“计算数学表达式”“”
try:
return str(eval(expression));
except:
return “计算错误”

agent = Agent(
name = “助手”,
instruction = “用工具回答问题”,
tools = [get_weather,calculate]
)

result = agent.run(“北京天气怎么样?2 + 3 * 5等于多少?”)
报错:
(.venv) E:\openai-agents-python>python tests/test_tools.py
Traceback (most recent call last):
File “E:\openai-agents-python\tests\test_tools.py”, line 4, in
def get_weather(city:str) -> str:
TypeError: ‘module’ object is not callable

(.venv) E:\openai-agents-python>

两个错误:
1.tool是模块,不是装饰器函数,项目图谱显示用function_tool
2.agent.run()用法错误
Result = agent.run(“北京天气怎么样?”)同步调用,sdk用法不对
官方示例
From agents import Agent, Runner, function_tool

=5/3=========================
Handoffs概念,把任务给另一个Agent
1.

更多推荐