Loading...
Loading...
Compare original and translation side by side
ai-agent-deep-diveai-agent-deep-diveundefinedundefinedundefinedundefinedsrc/agt/agent.pysrc/agt/cli.pysrc/agt/agent.pysrc/agt/cli.pyundefinedundefinedundefinedundefinedquery--skills-dir./skills--list-skillsquery--skills-dir./skills--list-skillsfrom agt.agent import Agentfrom agt.agent import Agentundefinedundefinedfrom agt.agent import Agentfrom agt.agent import Agentundefinedundefinedfrom agt.agent import Agent
class RealLLM:
"""Replace the fake LLM with real API calls"""
def __init__(self, api_key=None):
self.api_key = api_key or os.getenv("OPENAI_API_KEY")
def stream_response(self, prompt: str):
"""Stream tokens from real LLM"""
# Implementation would call actual API
# and yield tokens as they arrive
passfrom agt.agent import Agent
class RealLLM:
"""Replace the fake LLM with real API calls"""
def __init__(self, api_key=None):
self.api_key = api_key or os.getenv("OPENAI_API_KEY")
def stream_response(self, prompt: str):
"""Stream tokens from real LLM"""
# 实现需调用真实API
# 并在令牌到达时生成
passundefinedundefinedundefinedundefinedundefinedundefinedfrom agt.agent import Agent
import osfrom agt.agent import Agent
import osundefinedundefinedundefinedundefinedundefinedundefinedfrom agt.agent import Agent
agent = Agent(
skills_dir="./custom_skills", # Custom skills location
verbose=True, # Enable detailed logging
max_iterations=10 # Limit agent loop iterations
)from agt.agent import Agent
agent = Agent(
skills_dir="./custom_skills", # 自定义技能位置
verbose=True, # 启用详细日志
max_iterations=10 # 限制Agent循环迭代次数
)ai-agent-deep-dive/
├── src/
│ └── agt/
│ ├── agent.py # Core agent implementation
│ ├── cli.py # CLI entry point
│ └── __init__.py
├── skills/ # Skill modules directory
├── docs/ # Teaching documentation
├── pyproject.toml # Poetry dependencies
└── README.mdai-agent-deep-dive/
├── src/
│ └── agt/
│ ├── agent.py # 核心Agent实现
│ ├── cli.py # CLI入口
│ └── __init__.py
├── skills/ # 技能模块目录
├── docs/ # 教学文档
├── pyproject.toml # Poetry依赖配置
└── README.mdfrom agt.agent import Agent
import osfrom agt.agent import Agent
import osundefinedundefinedfrom agt.agent import Agent
agent = Agent()from agt.agent import Agent
agent = Agent()undefinedundefinedfrom agt.agent import Agent
class CustomAgent(Agent):
"""Extended agent with custom behavior"""
def pre_process(self, query: str) -> str:
"""Custom preprocessing"""
return query.strip().lower()
def post_process(self, response: str) -> str:
"""Custom postprocessing"""
return response.upper()
def run(self, query: str) -> str:
query = self.pre_process(query)
response = super().run(query)
return self.post_process(response)from agt.agent import Agent
class CustomAgent(Agent):
"""带自定义行为的扩展Agent"""
def pre_process(self, query: str) -> str:
"""自定义预处理"""
return query.strip().lower()
def post_process(self, response: str) -> str:
"""自定义后处理"""
return response.upper()
def run(self, query: str) -> str:
query = self.pre_process(query)
response = super().run(query)
return self.post_process(response)ai-agent-deep-dive-v2.1.pdfai-agent-deep-dive-v2.pdf/docsai-agent-deep-dive-v2.1.pdfai-agent-deep-dive-v2.pdf/docsundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedimport os
from openai import OpenAI
class OpenAILLM:
def __init__(self):
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def stream_response(self, prompt: str):
stream = self.client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
yield chunk.choices[0].delta.contentimport os
from openai import OpenAI
class OpenAILLM:
def __init__(self):
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def stream_response(self, prompt: str):
stream = self.client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
yield chunk.choices[0].delta.content