이 글은 기계 번역의 미러 문서이며, 원본 기사로 바로 이동하려면 여기를 클릭해 주세요.

보기: 1326|회답: 3

[출처] [AI] (16) 의미 커널은 Qwen을 기반으로 함수 호출을 테스트합니다

[링크 복사]
2025-3-26 17:46:52에 게시됨 | | | |
요구사항: 현재 시간, 오늘의 날씨, 급행 배송 확인 등 실시간 정보를 얻기 위해 대형 모델을 사용하거나, 비즈니스 데이터를 분석할 때 대형 모델을 사용한다면 함수 호출 기능을 사용해야 합니다. 인터넷 상의 많은 글들이 함수 호출에 대해 매우 모호하고 명확하게 설명하지 않는데, 저는 요청 정보를 바탕으로 이 기능을 이해하고 있습니다.

먼저 렌더링을 보고 대형 모델을 사용해 봅시다현재 시간, 상하이의 날씨, 그리고 컴퓨터를 켤 수 있게 도와준 계산기를 확인하세요, 아래 그림에서 볼 수 있습니다:



OpenAI 인터페이스 문서:하이퍼링크 로그인이 보입니다., 아래 그림에서 볼 수 있습니다:



함수 호출

대형 모델은 실시간 문제, 수학적 계산 및 기타 문제에 직면할 때 효과적이지 않을 수 있습니다. 함수 호출 기능을 사용하면 외부 도구를 도입하여 대형 모델이 외부 세계와 상호작용할 수 있도록 할 수 있습니다.

함수 호출은 대형 모델이 실제 산업적 구현으로 나아가도록 돕기 위해 대형 모델과 외부 도구 및 API를 연결하는 새로운 기능입니다. 함수 호출은 사용자가 복잡한 프롬프트를 입력하지 않고도 모델로부터 구조화된 데이터를 더 신뢰성 있게 얻을 수 있게 합니다.

이 기능을 사용할 때, 함수 집합의 함수와 정의를 자연어로 모델에 설명할 수 있습니다; 대화 중에 대형 모델이 기능을 사용해야 한다고 판단하면, 해당 기능을 지능적으로 선택하고 사용자의 특정 요구를 충족하기 위해 필요한 매개변수를 호출합니다. 다른 경우에는 대형 모델이 함수를 반환하지 않고 대화를 계속합니다. 대형 모델은 직접 함수를 호출하지 않고, 해당 입력 매개변수를 반환하며, 직접 함수/API 인터페이스를 호출할 수 있습니다.

간단히 말해, 함수 호출은 자연어와 정보 인터페이스 간의 "번역기"입니다

자연어를 필요한 함수와 매개변수로 변환한 후 대형 모델 호출자에게 반환합니다
대형 모델 호출자가 함수를 실행한 후, 결과는 대형 모델로 반환되며, 대규모 모델은 자연어로 요약되거나 하위 작업을 계속 계획할 수 있습니다

워크플로우 다이어그램은 아래에 나와 있습니다:



의미적 핵

Semantic Kernel은 가볍고 오픈소스 개발 키트로, AI 에이전트를 쉽게 생성하고 최신 AI 모델을 C#, Python 또는 Java 코드베이스에 통합할 수 있습니다. 효율적인 미들웨어로서 기업 수준의 솔루션을 신속하게 제공할 수 있게 합니다.

문서조사:하이퍼링크 로그인이 보입니다.
근원:하이퍼링크 로그인이 보입니다.

C#은 Alibaba Cloud Tongyi Qianwen을 호출하여 함수 호출을 실행합니다

다음 참조를 가진 새로운 .NET 8 콘솔 프로젝트를 생성하세요:

코드는 다음과 같습니다:

처음에 렌더링하는 프로그램을 실행하고, 현재 시간과 상하이 날씨를 확인한 후 계산기를 열어보세요.

실행 기록:

=============================================================================
Request:
Method: POST
Uri: 하이퍼링크 로그인이 보입니다.
요청 콘텐츠: {"tools":[{"function":{"description":"시간이 몇 시인지 알고 싶을 때 매우 유용합니다." ,"name":"itsvse-get_current_time","strict":false,"parameters":{"type":"object","required":[],"properties":{}}},"type":"function"},{"function":{"description":" 이 기능은 오늘 특정 도시의 날씨를 확인하고 싶을 때 유용합니다. ","name":"itsvse-get_current_weather","strict":false,"parameters":{"type":"object","required":["location"],"properties":{"location":{"description":"도시 또는 군, 예를 들어 베이징, 상하이, 항저우시, 위항구 등이 있습니다. ","type":"string"}}},"type":"function"},{"function":{"description":"명시된 Express 물류 정보를 조회하고 싶을 때 매우 유용합니다." ","name":"itsvse-get_current_test","strict":false,"parameters":{"type":"object","required":["no"],"properties":{"no":{"description":"택배 추적 번호(예: SF, ZTO, 우편 택배 추적 번호)도 허용됩니다." ","type":"string"}}},"type":"function"},{"function":{"description":"계산기를 열고 싶을 때 매우 유용합니다." ,"name":"itsvse-open_calculator","strict":false,"parameters":{"type":"object","required":[],"properties":{}}},"type":function"}],"messages":[{"role":"user","content" "안녕하세요, 상하이의 현재 시간과 오늘 날씨를 확인하는 데 도움을 주세요." 그럼, 나도 출근 계산기 도와줘, 오늘 수입을 계산하고 싶어. "}],"model":"qwen-max","tool_choice":"auto","parallel_tool_calls":true}
Response:
상태 코드: OK
Body: {"choices":[{"message":{"content":"","role":"assistant","tool_calls":[{"function":{"name":"itsvse-get_current_time","arguments":"{}"},"index":0,"id":"call_6e6cade782f54c9ca87186","type":"function"},{"function":{"name":"itsvse-get_current_weather","arguments":"{\"location\": \"上海市\"}"},"index":1,"id":"call_cc957be34f5741f4b2a969","type":"function"},{"function":{"name":"itsvse-open_calculator","arguments":"{}"},"index":2,"id":"call_6023df74d7bd48c789e876","type":"function"}]},"finish_reason":"tool_calls","index":0,"logprobs":null}],"object":"chat.completion","usage":{"prompt_tokens":500,"completion_tokens":53,"total_tokens":553,"prompt_tokens_details":{"cached_tokens":256}},"created":1742980780,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-1761acb9-717a-997c-9f17-7284e82fd121"}
=============================================================================
----------------------- 시간을 얻는 방법을 말하지-----------------------
----------------------------------------------------------------
----------------------- 날씨를 얻는 방법이라고 부르나요-----------------------
매개변수: 상하이
----------------------------------------------------------------
----------------------- 컴퓨터 계산기를 열어-----------------------
=============================================================================
Request:
Method: POST
Uri: 하이퍼링크 로그인이 보입니다.
요청 콘텐츠: {"tools":[{"function":{"description":"시간이 몇 시인지 알고 싶을 때 매우 유용합니다." ,"name":"itsvse-get_current_time","strict":false,"parameters":{"type":"object","required":[],"properties":{}}},"type":"function"},{"function":{"description":" 이 기능은 오늘 특정 도시의 날씨를 확인하고 싶을 때 유용합니다. ","name":"itsvse-get_current_weather","strict":false,"parameters":{"type":"object","required":["location"],"properties":{"location":{"description":"도시 또는 군, 예를 들어 베이징, 상하이, 항저우시, 위항구 등이 있습니다. ","type":"string"}}},"type":"function"},{"function":{"description":"명시된 Express 물류 정보를 조회하고 싶을 때 매우 유용합니다." ","name":"itsvse-get_current_test","strict":false,"parameters":{"type":"object","required":["no"],"properties":{"no":{"description":"택배 추적 번호(예: SF, ZTO, 우편 택배 추적 번호)도 허용됩니다." ","type":"string"}}},"type":"function"},{"function":{"description":"계산기를 열고 싶을 때 매우 유용합니다." ,"name":"itsvse-open_calculator","strict":false,"parameters":{"type":"object","required":[],"properties":{}}},"type":function"}],"messages":[{"role":"user","content" "안녕하세요, 상하이의 현재 시간과 오늘 날씨를 확인하는 데 도움을 주세요." 그럼, 나도 출근 계산기 도와줘, 오늘 수입을 계산하고 싶어. "},{"role":"assistant","content":"","tool_calls":[{"id":"call_6e6cade782f54c9ca87186","function":{"name":"itsvse-get_current_time","arguments":"{}"},"type":"function" ","index":0},{"id":"call_cc957be34f5741f4b2a969","function":{"name":"itsvse-get_current_weather","arguments":"{\"location\": \"Shanghai\"}"},"type":"function","index":1},{" id":"call_6023df74d7bd48c789e876","function":{"name":"itsvse-open_calculator","arguments":"{}"},"type":"function","index":2}]},{"role":"tool","tool_call_id":"call_ 6e6cade782f54c9ca87186","content":"2025/3/26 17:19:40"},{"role":tool","tool_call_id":"call_cc957be34f5741f4b2a969","content":"상하이의 기상 조건은 다음과 같습니다: 흐리고 뇌우가 있으며, 기온은 10°C에서 20°C 사이"},{" role":"tool","tool_call_id":"call_6023df74d7bd48c789e876","content":"계산기가 열렸습니다." }],"model":"qwen-max","tool_choice":"auto","parallel_tool_calls":true}
Response:
상태 코드: OK
Body: {"choices":[{"message":{"content":"现在的时间是2025年3月26日17点19分40秒。\n\n今天上海市的天气情况如下:多云转雷阵雨,气温介于10°C到20°C之间,请记得带伞哦。\n\n我已经 帮你打开了计算器,你可以开始计算今天的收入了。","role":"assistant"},"finish_reason":"stop","index":0,"logprobs":null}],"object":"chat.completion","usage":{"prompt_tokens":621,"completion_tokens":70,"total_tokens":691,"prompt_tokens_details":{"cached_tokens":0}},"created":1742980783,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-b0bd149e-3f5b-9a53-91d7-7bb26487d822"}
=============================================================================
보조 > 현재 2025년 3월 26일 17:19:40입니다.

오늘 상하이의 기상 상황은 다음과 같습니다: 흐림에서 뇌우, 기온은 10°C에서 20°C 사이이며, 우산 꼭 챙기시기 바랍니다.

계산기를 열어드렸으니 오늘부터 수익 계산을 시작하셔도 됩니다.

참조:

하이퍼링크 로그인이 보입니다.
하이퍼링크 로그인이 보입니다.
하이퍼링크 로그인이 보입니다.
하이퍼링크 로그인이 보입니다.
하이퍼링크 로그인이 보입니다.

점수

참가자 수1MB+1 무너지다 이유
굿타임 + 1 주인이 좋은 글을 올릴 수 있도록 응원해 주세요. 저도 좋은 글을 올릴게요!

모든 평점 보기





이전의:toPlainString, toEngineeringString, toString for BigDecimal in Java
다음:.NET/C# 부모-자식 프로세스는 표준 입출력 스트림을 사용하여 통신합니다
 집주인| 2025-3-27 08:59:23에 게시됨 |
다중 턴 대화 코드:


요청 시작 정보는 다음과 같습니다:



 집주인| 2025-3-27 08:58:04에 게시됨 |
스트리밍 결과물에 대하여

스트림 모드에서도 tool_calls 적용되지만, 아래에 나열된 몇 가지 추가 사항도 있습니다:

스트리밍 출력 중에는 finish_reason가 최종 청크에 나타나므로, delta.tool_calls 필드의 존재 여부를 사용하여 현재 응답에 툴 호출이 포함되어 있는지 판단하는 것이 권장됩니다;
스트리밍 출력 중에는 delta.content 먼저 출력되고 그 다음에 delta.tool_calls가 나오므로, delta.content 출력이 완료될 때까지 기다려야 판단하고 식별할 수 tool_calls;
스트리밍 출력 과정에서는 초기 데이터 블록에서 현재 호출 tool_calls의 tool_call.id와 tool_call.function.name을 지정하고, 이후 데이터 블록에는 tool_call.function.argument만 출력됩니다.
스트리밍 출력 과정에서 Kimi 모델이 동시에 여러 tool_calls을 반환하면, index라는 추가 필드를 사용해 현재 tool_call 인덱스를 식별하여 tool_call.function.arguments 매개변수를 올바르게 스티치할 수 있게 합니다.

하이퍼링크 로그인이 보입니다.

스트리밍 응답의 예는 다음과 같습니다:

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"name":"itsvse-get_current_time","arguments":""},"index":0,"id":"call_deb0063d315441b18b50d8","type":"function"}],"role":"assistant"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"arguments":"{}"},"index":0,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":0,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":0,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":0,"id":"","type":"function"},{"function":{"name":"itsvse-get_current_weather","arguments":""},"index":1,"id":"call_9790fb45e2b7419097d578","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"arguments":"{\"location\": \""},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"arguments":"上海市\"}"},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"tool_calls":[{"function":{"arguments":null},"index":1,"id":"","type":"function"},{"function":{"arguments":"{}","name":"itsvse-open_calculator"},"index":2,"id":"call_3ad6478075f04021ab9ea1","type":"function"}]},"index":0}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"finish_reason":"tool_calls","delta":{},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":500,"completion_tokens":53,"total_tokens":553,"prompt_tokens_details":{"cached_tokens":0}},"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: [DONE]


 집주인| 2025-10-22 11:30:02에 게시됨 |
MCP (1) 모델 컨텍스트 프로토콜 입문 튜토리얼
https://www.itsvse.com/thread-11104-1-1.html
면책 조항:
Code Farmer Network에서 발행하는 모든 소프트웨어, 프로그래밍 자료 또는 기사는 학습 및 연구 목적으로만 사용됩니다; 위 내용은 상업적 또는 불법적인 목적으로 사용되지 않으며, 그렇지 않으면 모든 책임이 사용자에게 부담됩니다. 이 사이트의 정보는 인터넷에서 가져온 것이며, 저작권 분쟁은 이 사이트와는 관련이 없습니다. 위 내용은 다운로드 후 24시간 이내에 컴퓨터에서 완전히 삭제해야 합니다. 프로그램이 마음에 드신다면, 진짜 소프트웨어를 지원하고, 등록을 구매하며, 더 나은 진짜 서비스를 받아주세요. 침해가 있을 경우 이메일로 연락해 주시기 바랍니다.

Mail To:help@itsvse.com