Skip to content

Commit

Permalink
Update dependencies (#268)
Browse files Browse the repository at this point in the history
* change the message log formatter

* update
  • Loading branch information
braisedpork1964 authored Nov 6, 2024
1 parent 248103b commit 5726f95
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 38 deletions.
2 changes: 1 addition & 1 deletion examples/run_async_agent_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'Below is a math problem. Please solve it step by step with the assistance of Python programming. Consider using Sympy or Numpy library '
'to facilitate your derivation, calculation and equation solving. Utilize the "pi" symbol and "Rational" from Sympy '
'for $$\pi$$ and fractions, and simplify all fractions and square roots without converting them to decimal values. '
'Please encapsulate each generated Jupyter Python code block with tags "{start}" and "{end}". Conclude the '
'Please encapsulate each generated Jupyter Python code block with tags "{begin}" and "{end}". Conclude the '
r'final answer when observations are sufficient and encapsulate the numerical result with LaTeX syntax "\boxed{{}}" '
'without any unit, and end your conclusion with the special token "[END]" to denote the completion of your response. '
'Keep the following points in mind:\n'
Expand Down
2 changes: 1 addition & 1 deletion examples/run_async_agent_vllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
asyncio.set_event_loop(loop)
# initialize the model
model = AsyncVllmModel(
path='internlm/internlm2_5-7b-chat',
path='Qwen/Qwen2-7B-Instruct',
meta_template=INTERNLM2_META,
tp=1,
top_k=1,
Expand Down
36 changes: 2 additions & 34 deletions lagent/agents/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get_steps(self, session_id=0):
for msg in self.agent.memory.get_memory(session_id):
if msg.sender == self.agent.name:
steps.append(
dict(role='language', content=msg.formatted['thought']))
dict(role='thought', content=msg.formatted['thought']))
if msg.formatted['tool_type']:
tool_type = msg.formatted['tool_type']
steps.append(
Expand Down Expand Up @@ -253,7 +253,7 @@ def get_steps(self, session_id=0):
for msg in self.agent.memory.get_memory(session_id):
if msg.sender == self.agent.name:
steps.append(
dict(role='language', content=msg.formatted['thought']))
dict(role='thought', content=msg.formatted['thought']))
if msg.formatted['tool_type']:
tool_type = msg.formatted['tool_type']
steps.append(
Expand Down Expand Up @@ -314,35 +314,3 @@ async def forward(self, message: AgentMessage, session_id=0, **kwargs):
iter(self.interpreter_executor.actions.values()))
if interpreter.name == 'AsyncIPythonInterpreter':
await interpreter.close_session(session_id)


if __name__ == '__main__':
from lagent.llms import GPTAPI

interpreter_prompt = (
'Below is a math problem. Please solve it step by step with the assistance of Python programming. Consider using Sympy or Numpy library '
'to facilitate your derivation, calculation and equation solving. Utilize the "pi" symbol and "Rational" from Sympy '
'for $$\pi$$ and fractions, and simplify all fractions and square roots without converting them to decimal values. '
'Please encapsulate each generated Jupyter Python code block with tags "{begin}" and "{end}". Conclude the '
r'final answer when observations are sufficient and encapsulate the numerical result with LaTeX syntax "\boxed{{}}" '
'without any unit, and end your conclusion with the special token "[END]" to denote the completion of your response. '
'Keep the following points in mind:\n'
'- You must alternately use human and programming languages in the chain of thought;\n'
'- The number of your reasoning steps should not exceed **three**, which means you may merge some intermediate steps when the original answer is tedious.'
)

llm = dict(
type=GPTAPI,
model_type='gpt-4o-2024-05-13',
retry=50,
key=None,
max_new_tokens=2048,
stop_words=['</python'],
)
agent = MathCoder(
llm=llm,
output_format=InterpreterParser(
template=interpreter_prompt, begin='<python>', end='</python>'),
aggregator=InternLMToolAggregator(
environment_begin='<output>\n', environment_end='\n</output>'),
finish_condition=lambda m: '[END]' in m.content)
3 changes: 2 additions & 1 deletion lagent/hooks/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
class MessageLogger(Hook):

def __init__(self, name: str = 'lagent'):
self.logger = get_logger(name, 'info')
self.logger = get_logger(
name, 'info', '%(asctime)s %(levelname)8s %(name)8s - %(message)s')
self.sender2color = {}

def before_agent(self, agent, messages, session_id):
Expand Down
2 changes: 1 addition & 1 deletion requirements/runtime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jsonschema
jupyter==1.0.0
jupyter_core==5.7.2
jupyter_client==8.6.2
pydantic==2.6.4
requests
stdlib_list==0.10.0
streamlit
termcolor
tiktoken
timeout-decorator
Expand Down

0 comments on commit 5726f95

Please sign in to comment.