root layout

패스트캠퍼스

ch02_03 소수 찾는 코드

2025.03.05 00:35 수정

user_proxy = autogen.UserProxyAgent(

name = 'user_proxy',

max_consecutive_auto_reply = 10,

is_termination_msg = lambda x: x.get('content', '').rstrip().endswith('TERMINATE'),

code_execution_config = {

'executor': LocalCommandLineCodeExecutor(work_dir='coding'),

},

human_input_mode = 'NEVER'

)


여기서 is_termination_msg = lambda x: x.get('content', '').rstrip().endswith('TERMINATE'), 이 옵션때문에 never로 줘도 한 턴만에 멈춰버립니다. 턴마다 TERMINATE 메시지가 뜨는고 있네요..


user_proxy (to assistant):

100까지 소수가 어떤 것이 있는지 코드로 살펴봐

--------------------------------------------------------------------------------

assistant (to user_proxy):

아래의 파이썬 코드는 100까지의 소수를 찾아 출력합니다:

```python

# filename: primes_up_to_100.py

import math

def is_prime(n):

if n < 2:

return False

for i in range(2, int(math.sqrt(n)) + 1):

if n % i == 0:

return False

return True

primes = [i for i in range(101) if is_prime(i)]

print("100까지의 소수:", primes)

```

이 코드를 실행하면 100까지의 소수 목록이 출력됩니다.

TERMINATE

--------------------------------------------------------------------------------






그리고, human_input_mode = 'ALWAYS'옵션으로 변경하고 돌려보면

user_proxy (to assistant):

100까지 소수가 어떤 것이 있는지 코드로 살펴봐

--------------------------------------------------------------------------------

assistant (to user_proxy):

아래의 파이썬 코드는 100까지의 소수를 찾아 출력합니다:

```python

# filename: primes_up_to_100.py

import math

def is_prime(n):

if n < 2:

return False

for i in range(2, int(math.sqrt(n)) + 1):

if n % i == 0:

return False

return True

primes = [i for i in range(101) if is_prime(i)]

print("100까지의 소수:", primes)

```

이 코드를 실행하면 100까지의 소수 목록이 출력됩니다.

TERMINATE

--------------------------------------------------------------------------------

Replying as user_proxy. Provide feedback to assistant. Press enter to skip and use auto-reply, or type 'exit' to end the conversation:

>>>>>>>> NO HUMAN INPUT RECEIVED.


유저가 엔터를 입력하면 저기서 코드가 종료가 되고 코드실행은 하지 않네요..





###########

원인을 찾았습니다.

o3-mini모델로 설정하고 실행하면 위와 같이 에러가 뜨는데요, 추론모델과 gpt-4o같은 일반 모델의 차이점때문에 발생하는 에러일까요?


####

해결방법

\anaconda3\Lib\site-packages\langchain_openai\chat_models\base.py

파일 내

if model.startswith("o1") and "temperature" not in values:

이 부분을

if (model.startswith("o1") or model.startswith("o3")) and "temperature" not in values:

로 변경하면 'o3-mini'모델도 정상 작동하네요


답변 

연관 질문

커뮤니티 질문보기