본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Quickstart: Conversation

원문 보기 위키 갱신

Dapr conversation 빌딩 블록으로 시작해 봐요.

Alpha

conversation 빌딩 블록은 현재 alpha 단계예요.

Dapr conversation 빌딩 블록이 대규모 언어 모델(LLM)과의 상호작용을 어떻게 쉽게 만드는지 살펴볼게요. 이 quickstart에서는 echo 컴포넌트로 mock LLM과 통신하면서 Dapr을 정의하도록 요청해요.

이 conversation quickstart는 다음 두 가지 방식으로 체험할 수 있어요.

  • Multi-App Run 템플릿 파일로 이 샘플의 어플리케이션을 실행하거나,
  • 템플릿 없이 어플리케이션 실행.

참고

현재 quickstart 샘플에서 JavaScript는 HTTP로만 사용할 수 있으며, JavaScript SDK는 사용할 수 없어요.

출처: Dapr 문서

본문

템플릿 파일로 앱 실행하기

Quickstart를 진행하기 전에 선호하는 언어별 Dapr SDK를 선택해요.

  • Python
  • JavaScript
  • .NET
  • Java
  • Go

1단계: 사전 조건 (Pre-requisites)

이 예제에 필요한 것들:

  • Dapr CLI와 초기화된 환경.

  • Python 3.7+ 설치.

  • Docker Desktop.

2단계: 환경 설정하기

Quickstarts 저장소에 제공된 샘플을 클론해요.

git clone https://github.com/dapr/quickstarts.git

Quickstarts 디렉터리 루트에서 conversation 디렉터리로 이동해요.

cd conversation/python/sdk/conversation

의존성을 설치해요.

pip3 install -r requirements.txt

3단계: conversation 서비스 실행하기

dapr run -f .

참고: Windows에는 Python3.exe가 정의되어 있지 않으므로 python3 app.py 대신 python app.py를 사용해야 할 수 있어요.

예상 출력

== APP - conversation == Input sent: What is dapr?
== APP - conversation == Output response: What is dapr?

무슨 일이 일어났나요?

이 Quickstart에서 dapr run -f .을 실행하면 app.py가 시작돼요.

dapr.yaml Multi-App Run 템플릿 파일

dapr run -f .로 Multi-App Run 템플릿 파일을 실행하면 프로젝트의 모든 어플리케이션이 시작돼요. 이 Quickstart에는 어플리케이션이 하나뿐이라 dapr.yaml 파일은 다음을 포함해요.

version: 1
common:
resourcesPath: ../../components/
apps:
- appID: conversation
appDirPath: ./conversation/
command: ["python3", "app.py"]

Echo mock LLM 컴포넌트

quickstart의 conversation/components에서 conversation.yaml 파일이 echo LLM 컴포넌트를 구성해요.

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: echo
spec:
type: conversation.echo
version: v1

실제 LLM과 연동하려면 mock 컴포넌트를 지원되는 conversation 컴포넌트 중 하나로 교체해요. 예를 들어 OpenAI 컴포넌트를 사용하려면 conversation how-to 가이드의 예제를 참고해요.

app.py conversation 앱

어플리케이션 코드에서:

  • 앱은 echo mock LLM 컴포넌트에 “What is dapr?”라는 입력을 보내요.
  • mock LLM은 “What is dapr?”를 그대로 되돌려줘요(echo).
from dapr.clients import DaprClient
from dapr.clients.grpc.conversation import ConversationInputAlpha2, ConversationMessage, ConversationMessageContent, ConversationMessageOfUser

with DaprClient() as d:
text_input = "What is dapr?"
provider_component = "echo"

inputs = [
ConversationInputAlpha2(messages=[ConversationMessage(of_user=ConversationMessageOfUser(content=[ConversationMessageContent(text=text_input)]))],
scrub_pii=True),
]

print(f'Input sent: {text_input}')

response = d.converse_alpha2(name=provider_component, inputs=inputs, temperature=0.7, context_id='chat-123')

for output in response.outputs:
print(f'Output response: {output.choices[0].message.content}')

1단계: 사전 조건 (Pre-requisites)

이 예제에 필요한 것들:

  • Dapr CLI와 초기화된 환경.

  • 최신 Node.js 설치.

  • Docker Desktop.

2단계: 환경 설정하기

Quickstarts 저장소에 제공된 샘플을 클론해요.

git clone https://github.com/dapr/quickstarts.git

Quickstarts 디렉터리 루트에서 conversation 디렉터리로 이동해요.

cd conversation/javascript/http/conversation

의존성을 설치해요.

npm install

3단계: conversation 서비스 실행하기

http 디렉터리로 돌아가서 다음 명령으로 conversation 서비스를 시작해요.

dapr run -f .

예상 출력

== APP - conversation == Conversation input sent: What is dapr?
== APP - conversation == Output response: What is dapr?
== APP - conversation == Tool calling input sent: What is the weather like in San Francisco in celsius?
== APP - conversation == Output message: { outputs: [ { choices: [Array] } ] }
== APP - conversation == Output message: What is the weather like in San Francisco in celsius?
== APP - conversation == Tool calls detected: [{"id":"0","function":{"name":"get_weather","arguments":"location,unit"}}]

무슨 일이 일어났나요?

이 Quickstart에서 dapr run -f .을 실행하면 conversation.go가 시작돼요.

dapr.yaml Multi-App Run 템플릿 파일

dapr run -f .로 Multi-App Run 템플릿 파일을 실행하면 프로젝트의 모든 어플리케이션이 시작돼요. 이 Quickstart에는 어플리케이션이 하나뿐이라 dapr.yaml 파일은 다음을 포함해요.

version: 1
common:
resourcesPath: ../../components/
apps:
- appID: conversation
appDirPath: ./conversation/
daprHTTPPort: 3502
command: ["npm", "run", "start"]

Echo mock LLM 컴포넌트

quickstart의 conversation/components에서 conversation.yaml 파일이 echo LLM 컴포넌트를 구성해요.

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: echo
spec:
type: conversation.echo
version: v1

실제 LLM과 연동하려면 mock 컴포넌트를 지원되는 conversation 컴포넌트 중 하나로 교체해요. 예를 들어 OpenAI 컴포넌트를 사용하려면 conversation how-to 가이드의 예제를 참고해요.

index.js conversation 앱

어플리케이션 코드의 첫 번째 부분에서:

  • 앱은 echo mock LLM 컴포넌트에 “What is dapr?”라는 입력을 보내요.
  • mock LLM은 “What is dapr?”를 그대로 되돌려줘요.
const daprHost = process.env.DAPR_HOST || "http://localhost";
const daprHttpPort = process.env.DAPR_HTTP_PORT || "3500";

const reqURL = `${daprHost}:${daprHttpPort}/v1.0-alpha2/conversation/${conversationComponentName}/converse`;

// Plain conversation
try {
const converseInputBody = {
inputs: [
{
messages: [
{
ofUser: {
content: [
{
text: "What is dapr?",
},
],
},
},
],
},
],
parameters: {},
metadata: {},
};
const response = await fetch(reqURL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(converseInputBody),
});

console.log("Conversation input sent: What is dapr?");

const data = await response.json();
const result = data.outputs[0].choices[0].message.content;
console.log("Output response:", result);
} catch (error) {
console.error("Error:", error.message);
process.exit(1);
}

어플리케이션 코드의 두 번째 부분에서:

  • 앱은 사용 가능한 도구인 get_weather의 정의와 함께 “What is the weather like in San Francisco in celsius”라는 입력을 보내요.
  • mock LLM은 “What is the weather like in San Francisco in celsius?”와 함수 정의를 그대로 되돌려주고, 이는 응답에서 감지돼요.
try {
const toolCallingInputBody = {
inputs: [
{
messages: [
{
ofUser: {
content: [
{
text: "What is the weather like in San Francisco in celsius?",
},
],
},
},
],
scrubPii: false,
},
],
metadata: {
api_key: "test-key",
version: "1.0",
},
scrubPii: false,
temperature: 0.7,
tools: [
{
function: {
name: "get_weather",
description: "Get the current weather for a location",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and state, e.g. San Francisco, CA",
},
unit: {
type: "string",
enum: ["celsius", "fahrenheit"],
description: "The temperature unit to use",
},
},
required: ["location"],
},
},
},
],
toolChoice: "auto",
};
const response = await fetch(reqURL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(toolCallingInputBody),
});

console.log(
"Tool calling input sent: What is the weather like in San Francisco in celsius?"
);

const data = await response.json();

const result = data?.outputs?.[0]?.choices?.[0]?.message?.content;
console.log("Output message:", result);

if (data?.outputs?.[0]?.choices?.[0]?.message?.toolCalls) {
console.log(
"Tool calls detected:",
JSON.stringify(data.outputs[0].choices[0].message?.toolCalls)
);
} else {
console.log("No tool calls in response");
}
} catch (error) {
console.error("Error:", error.message);
process.exit(1);
}

1단계: 사전 조건 (Pre-requisites)

이 예제에 필요한 것들:

  • Dapr CLI와 초기화된 환경.

  • .NET 8 SDK+ 설치.

  • Docker Desktop.

2단계: 환경 설정하기

Quickstarts 저장소에 제공된 샘플을 클론해요.

git clone https://github.com/dapr/quickstarts.git

Quickstarts 디렉터리 루트에서 conversation 디렉터리로 이동해요.

cd conversation/csharp/sdk

3단계: conversation 서비스 실행하기

다음 명령으로 conversation 서비스를 시작해요.

dapr run -f .

예상 출력

== APP - conversation == Conversation input sent: What is dapr?
== APP - conversation == Output response: What is dapr?
== APP - conversation == Tool calling input sent: What is the weather like in San Francisco in celsius?
== APP - conversation == Output message: What is the weather like in San Francisco in celsius?
== APP - conversation == Tool calls detected:
== APP - conversation == Tool call: {"id":0,"function":{"name":"get_weather","arguments":"location,unit"}}
== APP - conversation == Function name: get_weather
== APP - conversation == Function arguments: location,unit

무슨 일이 일어났나요?

이 Quickstart에서 dapr run -f .을 실행하면 conversation Program.cs가 시작돼요.

dapr.yaml Multi-App Run 템플릿 파일

dapr run -f .로 Multi-App Run 템플릿 파일을 실행하면 프로젝트의 모든 어플리케이션이 시작돼요. 이 Quickstart에는 어플리케이션이 하나뿐이라 dapr.yaml 파일은 다음을 포함해요.

version: 1
common:
resourcesPath: ../../components/
apps:
- appDirPath: ./conversation/
appID: conversation
daprHTTPPort: 3500
command: ["dotnet", "run"]

Echo mock LLM 컴포넌트

conversation/components에서 conversation.yaml 파일이 echo mock LLM 컴포넌트를 구성해요.

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: echo
spec:
type: conversation.echo
version: v1

실제 LLM과 연동하려면 mock 컴포넌트를 지원되는 conversation 컴포넌트 중 하나로 교체해요. 예를 들어 OpenAI 컴포넌트를 사용하려면 conversation how-to 가이드의 예제를 참고해요.

Program.cs conversation 앱

어플리케이션 코드에서:

  • 앱은 echo mock LLM 컴포넌트에 “What is dapr?”라는 입력을 보내요.
  • mock LLM은 “What is dapr?”를 그대로 되돌려줘요.
  • 앱은 사용 가능한 도구인 get_weather의 정의와 함께 “What is the weather like in San Francisco in celsius”라는 입력을 보내요.
  • mock LLM은 “What is the weather like in San Francisco in celsius?”와 함수 정의를 그대로 되돌려주고, 이는 응답에서 감지돼요.
using System.Text.Json;
using Dapr.AI.Conversation;
using Dapr.AI.Conversation.ConversationRoles;
using Dapr.AI.Conversation.Extensions;
using Dapr.AI.Conversation.Tools;

const string conversationComponentName = "echo";
const string conversationText = "What is dapr?";
const string toolCallInput = "What is the weather like in San Francisco in celsius?";

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDaprConversationClient();
var app = builder.Build();

//
// Setup

var conversationClient = app.Services.GetRequiredService<DaprConversationClient>();

var conversationOptions = new ConversationOptions(conversationComponentName)
{
ScrubPII = false,
ToolChoice = ToolChoice.Auto,
Temperature = 0.7,
Tools = [
new ToolFunction("function")
{
Name = "get_weather",
Description = "Get the current weather for a location",
Parameters = JsonSerializer.Deserialize<Dictionary<string, object?>>("""
{
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use"
}
},
"required": ["location"]
}
""") ?? throw new("Unable to parse tool function parameters."),
},
],
};

//
// Simple Conversation

var conversationResponse = await conversationClient.ConverseAsync(
[new ConversationInput(new List<IConversationMessage>
{
new UserMessage {
Name = "TestUser",
Content = [
new MessageContent(conversationText),
],
},
})],
conversationOptions
);

Console.WriteLine($"Conversation input sent: {conversationText}");
Console.WriteLine($"Output response: {conversationResponse.Outputs.First().Choices.First().Message.Content}");

//
// Tool Calling

var toolCallResponse = await conversationClient.ConverseAsync(
[new ConversationInput(new List<IConversationMessage>
{
new UserMessage {
Name = "TestUser",
Content = [
new MessageContent(toolCallInput),
],
},
})],
conversationOptions
);

Console.WriteLine($"Tool calling input sent: {toolCallInput}");
Console.WriteLine($"Output message: {toolCallResponse.Outputs.First().Choices.First().Message.Content}");
Console.WriteLine("Tool calls detected:");

var functionToolCall = toolCallResponse.Outputs.First().Choices.First().Message.ToolCalls.First() as CalledToolFunction
?? throw new("Unexpected tool call type for demo.");

var toolCallJson = JsonSerializer.Serialize(new
{
id = 0,
function = new
{
name = functionToolCall.Name,
arguments = functionToolCall.JsonArguments,
},
});
Console.WriteLine($"Tool call: {toolCallJson}");
Console.WriteLine($"Function name: {functionToolCall.Name}");
Console.WriteLine($"Function arguments: {functionToolCall.JsonArguments}");

1단계: 사전 조건 (Pre-requisites)

이 예제에 필요한 것들:

  • Dapr CLI와 초기화된 환경.

  • Java JDK 17 (이상): Oracle JDK, 또는

  • OpenJDK

  • Apache Maven, 버전 3.x.

  • Docker Desktop.

2단계: 환경 설정하기

Quickstarts 저장소에 제공된 샘플을 클론해요.

git clone https://github.com/dapr/quickstarts.git

Quickstarts 디렉터리 루트에서 conversation 디렉터리로 이동해요.

cd conversation/java/sdk/conversation

의존성을 설치해요.

mvn clean install

3단계: conversation 서비스 실행하기

sdk 디렉터리로 돌아가서 다음 명령으로 conversation 서비스를 시작해요.

dapr run -f .

예상 출력

== APP - conversation == Input: What is Dapr?
== APP - conversation == Output response: What is Dapr?

무슨 일이 일어났나요?

이 Quickstart에서 dapr run -f .을 실행하면 Conversation.java가 시작돼요.

dapr.yaml Multi-App Run 템플릿 파일

dapr run -f .로 Multi-App Run 템플릿 파일을 실행하면 프로젝트의 모든 어플리케이션이 시작돼요. 이 Quickstart에는 어플리케이션이 하나뿐이라 dapr.yaml 파일은 다음을 포함해요.

version: 1
common:
resourcesPath: ../../components
apps:
- appID: conversation
appDirPath: ./conversation/target
command: ["java", "-jar", "ConversationAIService-0.0.1-SNAPSHOT.jar"]

Echo mock LLM 컴포넌트

quickstart의 conversation/components에서 conversation.yaml 파일이 echo LLM 컴포넌트를 구성해요.

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: echo
spec:
type: conversation.echo
version: v1

실제 LLM과 연동하려면 mock 컴포넌트를 지원되는 conversation 컴포넌트 중 하나로 교체해요. 예를 들어 OpenAI 컴포넌트를 사용하려면 conversation how-to 가이드의 예제를 참고해요.

Conversation.java conversation 앱

어플리케이션 코드에서:

  • 앱은 echo mock LLM 컴포넌트에 “What is dapr?”라는 입력을 보내요.
  • mock LLM은 “What is dapr?”를 그대로 되돌려줘요.
package com.service;

import io.dapr.client.DaprClientBuilder;
import io.dapr.client.DaprPreviewClient;
import io.dapr.client.domain.ConversationInput;
import io.dapr.client.domain.ConversationRequest;
import io.dapr.client.domain.ConversationResponse;
import reactor.core.publisher.Mono;

import java.util.List;

public class Conversation {

public static void main(String[] args) {
String prompt = "What is Dapr?";

try (DaprPreviewClient client = new DaprClientBuilder().buildPreviewClient()) {
System.out.println("Input: " + prompt);

ConversationInput daprConversationInput = new ConversationInput(prompt);

// Component name is the name provided in the metadata block of the conversation.yaml file.
Mono<ConversationResponse> responseMono = client.converse(new ConversationRequest("echo",
List.of(daprConversationInput))
.setContextId("contextId")
.setScrubPii(true).setTemperature(1.1d));
ConversationResponse response = responseMono.block();
System.out.printf("Output response: %s", response.getConversationOutputs().get(0).getResult());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

1단계: 사전 조건 (Pre-requisites)

이 예제에 필요한 것들:

  • Dapr CLI와 초기화된 환경.

  • 최신 버전의 Go.

  • Docker Desktop.

2단계: 환경 설정하기

Quickstarts 저장소에 제공된 샘플을 클론해요.

git clone https://github.com/dapr/quickstarts.git

Quickstarts 디렉터리 루트에서 conversation 디렉터리로 이동해요.

cd conversation/go/sdk

3단계: conversation 서비스 실행하기

다음 명령으로 conversation 서비스를 시작해요.

dapr run -f .

예상 출력

== APP - conversation-sdk == Input sent: What is dapr?
== APP - conversation-sdk == Output response: What is dapr?
== APP - conversation-sdk == Tool calling input sent: What is the weather like in San Francisco in celsius?'
== APP - conversation-sdk == Tool Call: Name: getWeather - Arguments: location,unit
== APP - conversation-sdk == Tool Call Output: The weather in San Francisco is 25 degrees Celsius

무슨 일이 일어났나요?

이 Quickstart에서 dapr run -f .을 실행하면 conversation.go가 시작돼요.

dapr.yaml Multi-App Run 템플릿 파일

dapr run -f .로 Multi-App Run 템플릿 파일을 실행하면 프로젝트의 모든 어플리케이션이 시작돼요. 이 Quickstart에는 어플리케이션이 하나뿐이라 dapr.yaml 파일은 다음을 포함해요.

version: 1
common:
resourcesPath: ../../components/
apps:
- appDirPath: ./conversation/
appID: conversation
daprHTTPPort: 3501
command: ["go", "run", "."]

Echo mock LLM 컴포넌트

quickstart의 conversation/components에서 conversation.yaml 파일이 echo LLM 컴포넌트를 구성해요.

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: echo
spec:
type: conversation.echo
version: v1

실제 LLM과 연동하려면 mock 컴포넌트를 지원되는 conversation 컴포넌트 중 하나로 교체해요. 예를 들어 OpenAI 컴포넌트를 사용하려면 conversation how-to 가이드의 예제를 참고해요.

conversation.go conversation 앱

어플리케이션 코드에서:

  • 앱은 echo mock LLM 컴포넌트에 “What is dapr?”라는 입력을 보내요.
  • mock LLM은 “What is dapr?”를 그대로 되돌려줘요.
  • 앱은 사용 가능한 도구인 get_weather의 정의와 함께 “What is the weather like in San Francisco in celsius”라는 입력을 보내요.
  • mock LLM은 “What is the weather like in San Francisco in celsius?”와 함수 정의를 그대로 되돌려주고, 이는 응답에서 감지돼요.
import (
"context"
"encoding/json"
"fmt"
"log"
"strings"

"github.com/invopop/jsonschema"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/structpb"

dapr "github.com/dapr/go-sdk/client"
)

// createMapOfArgsForEcho is a helper function to deal with the issue with the echo component not returning args as a map but in csv format
func createMapOfArgsForEcho(s string) ([]byte, error) {
m := map[string]any{}
for _, p := range strings.Split(s, ",") {
m[p] = p
}
return json.Marshal(m)
}

// getWeatherInLocation is an example function to use as a tool call
func getWeatherInLocation(request GetDegreesWeatherRequest, defaultValues GetDegreesWeatherRequest) string {
location := request.Location
unit := request.Unit
if location == "location" {
location = defaultValues.Location
}
if unit == "unit" {
unit = defaultValues.Unit
}
return fmt.Sprintf("The weather in %s is 25 degrees %s", location, unit)
}

type GetDegreesWeatherRequest struct {
Location string `json:"location" jsonschema:"title=Location,description=The location to look up the weather for"`
Unit string `json:"unit" jsonschema:"enum=celsius,enum=fahrenheit,description=Unit"`
}

// GenerateFunctionTool helper method to create jsonschema input
func GenerateFunctionTool[T any](name, description string) (*dapr.ConversationToolsAlpha2, error) {
reflector := jsonschema.Reflector{
AllowAdditionalProperties: false,
DoNotReference: true,
}
var v T

schema := reflector.Reflect(v)

schemaBytes, err := schema.MarshalJSON()
if err != nil {
return nil, err
}

var protoStruct structpb.Struct
if err := protojson.Unmarshal(schemaBytes, &protoStruct); err != nil {
return nil, fmt.Errorf("converting jsonschema to proto Struct: %w", err)
}

return (*dapr.ConversationToolsAlpha2)(&dapr.ConversationToolsFunctionAlpha2{
Name: name,
Description: &description,
Parameters: &protoStruct,
}), nil
}

// createUserMessageInput is a helper method to create user messages in expected proto format
func createUserMessageInput(msg string) *dapr.ConversationInputAlpha2 {
return &dapr.ConversationInputAlpha2{
Messages: []*dapr.ConversationMessageAlpha2{
{
ConversationMessageOfUser: &dapr.ConversationMessageOfUserAlpha2{
Content: []*dapr.ConversationMessageContentAlpha2{
{
Text: &msg,
},
},
},
},
},
}
}

func main() {
client, err := dapr.NewClient()
if err != nil {
panic(err)
}

inputMsg := "What is dapr?"
conversationComponent := "echo"

request := dapr.ConversationRequestAlpha2{
Name: conversationComponent,
Inputs: []*dapr.ConversationInputAlpha2{createUserMessageInput(inputMsg)},
}

fmt.Println("Input sent:", inputMsg)

resp, err := client.ConverseAlpha2(context.Background(), request)
if err != nil {
log.Fatalf("err: %v", err)
}

fmt.Println("Output response:", resp.Outputs[0].Choices[0].Message.Content)

tool, err := GenerateFunctionTool[GetDegreesWeatherRequest]("getWeather", "get weather from a location in the given unit")
if err != nil {
log.Fatalf("err: %v", err)
}

weatherMessage := "Tool calling input sent: What is the weather like in San Francisco in celsius?'"
requestWithTool := dapr.ConversationRequestAlpha2{
Name: conversationComponent,
Inputs: []*dapr.ConversationInputAlpha2{createUserMessageInput(weatherMessage)},
Tools: []*dapr.ConversationToolsAlpha2{tool},
}

resp, err = client.ConverseAlpha2(context.Background(), requestWithTool)
if err != nil {
log.Fatalf("err: %v", err)
}

fmt.Println(resp.Outputs[0].Choices[0].Message.Content)
for _, toolCalls := range resp.Outputs[0].Choices[0].Message.ToolCalls {
fmt.Printf("Tool Call: Name: %s - Arguments: %v\n", toolCalls.ToolTypes.Name, toolCalls.ToolTypes.Arguments)

// parse the arguments and execute tool
args := []byte(toolCalls.ToolTypes.Arguments)
if conversationComponent == "echo" {
// The echo component does not return a compliant tool calling response in json format but rather returns a csv
args, err = createMapOfArgsForEcho(toolCalls.ToolTypes.Arguments)
if err != nil {
log.Fatalf("err: %v", err)
}
}

// find the tool (only one in this case) and execute
for _, toolInfo := range requestWithTool.Tools {
if toolInfo.Name == toolCalls.ToolTypes.Name && toolInfo.Name == "getWeather" {
var reqArgs GetDegreesWeatherRequest
if err = json.Unmarshal(args, &reqArgs); err != nil {
log.Fatalf("err: %v", err)
}
// execute tool
toolExecutionOutput := getWeatherInLocation(reqArgs, GetDegreesWeatherRequest{Location: "San Francisco", Unit: "Celsius"})
fmt.Printf("Tool Call Output: %s\n", toolExecutionOutput)
}
}
}
}

템플릿 없이 앱 실행하기

  • Python
  • JavaScript
  • .NET
  • Java
  • Go

1단계: 사전 조건 (Pre-requisites)

이 예제에 필요한 것들:

  • Dapr CLI와 초기화된 환경.

  • Python 3.7+ 설치.

  • Docker Desktop.

2단계: 환경 설정하기

Quickstarts 저장소에 제공된 샘플을 클론해요.

git clone https://github.com/dapr/quickstarts.git

Quickstarts 디렉터리 루트에서 conversation 디렉터리로 이동해요.

cd conversation/python/sdk/conversation

의존성을 설치해요.

pip3 install -r requirements.txt

3단계: conversation 서비스 실행하기

sdk 디렉터리로 돌아가서 다음 명령으로 conversation 서비스를 시작해요.

dapr run --app-id conversation --resources-path ../../../components -- python3 app.py

참고: Windows에는 Python3.exe가 정의되어 있지 않으므로 python3 app.py 대신 python app.py를 사용해야 할 수 있어요.

예상 출력

== APP - conversation == Input sent: What is dapr?
== APP - conversation == Output response: What is dapr?

1단계: 사전 조건 (Pre-requisites)

이 예제에 필요한 것들:

  • Dapr CLI와 초기화된 환경.

  • 최신 Node.js 설치.

  • Docker Desktop.

2단계: 환경 설정하기

Quickstarts 저장소에 제공된 샘플을 클론해요.

git clone https://github.com/dapr/quickstarts.git

Quickstarts 디렉터리 루트에서 conversation 디렉터리로 이동해요.

cd conversation/javascript/http/conversation

의존성을 설치해요.

npm install

3단계: conversation 서비스 실행하기

dapr run --app-id conversation --resources-path ../../../components -- npm run start

예상 출력

== APP == Conversation input sent: What is dapr?
== APP == Output response: What is dapr?
== APP == Tool calling input sent: What is the weather like in San Francisco in celsius?
== APP == Output message: What is the weather like in San Francisco in celsius?
== APP == Tool calls detected: [{"id":"0","function":{"name":"get_weather","arguments":"location,unit"}}]

1단계: 사전 조건 (Pre-requisites)

이 예제에 필요한 것들:

  • Dapr CLI와 초기화된 환경.

  • .NET 8+ SDK 설치.

  • Docker Desktop.

2단계: 환경 설정하기

Quickstarts 저장소에 제공된 샘플을 클론해요.

git clone https://github.com/dapr/quickstarts.git

Quickstarts 디렉터리 루트에서 conversation 디렉터리로 이동해요.

cd conversation/csharp/sdk/conversation

의존성을 설치해요.

dotnet build

3단계: conversation 서비스 실행하기

다음 명령으로 conversation 서비스를 시작해요.

dapr run --app-id conversation --resources-path ../../../components/ -- dotnet run

예상 출력

== APP == Conversation input sent: What is dapr?
== APP == Output response: What is dapr?
== APP == Tool calling input sent: What is the weather like in San Francisco in celsius?
== APP == Output message: What is the weather like in San Francisco in celsius?
== APP == Tool calls detected:
== APP == Tool call: {"id":0,"function":{"name":"get_weather","arguments":"location,unit"}}
== APP == Function name: get_weather
== APP == Function arguments: location,unit

1단계: 사전 조건 (Pre-requisites)

이 예제에 필요한 것들:

  • Dapr CLI와 초기화된 환경.

  • Java JDK 17 (이상): Oracle JDK, 또는

  • OpenJDK

  • Apache Maven, 버전 3.x.

  • Docker Desktop.

2단계: 환경 설정하기

Quickstarts 저장소에 제공된 샘플을 클론해요.

git clone https://github.com/dapr/quickstarts.git

Quickstarts 디렉터리 루트에서 conversation 디렉터리로 이동해요.

cd conversation/java/sdk/conversation

의존성을 설치해요.

mvn clean install

3단계: conversation 서비스 실행하기

다음 명령으로 conversation 서비스를 시작해요.

dapr run --app-id conversation --resources-path ../../../components/ -- java -jar target/ConversationAIService-0.0.1-SNAPSHOT.jar com.service.Conversation

예상 출력

== APP == Input: What is Dapr?
== APP == Output response: What is Dapr?

1단계: 사전 조건 (Pre-requisites)

이 예제에 필요한 것들:

  • Dapr CLI와 초기화된 환경.

  • 최신 버전의 Go.

  • Docker Desktop.

2단계: 환경 설정하기

Quickstarts 저장소에 제공된 샘플을 클론해요.

git clone https://github.com/dapr/quickstarts.git

Quickstarts 디렉터리 루트에서 conversation 디렉터리로 이동해요.

cd conversation/go/sdk/conversation

의존성을 설치해요.

go build .

3단계: conversation 서비스 실행하기

다음 명령으로 conversation 서비스를 시작해요.

dapr run --app-id conversation --resources-path ../../../components/ -- go run .

예상 출력

== APP == dapr client initializing for: 127.0.0.1:53826
== APP == Input sent: What is dapr?
== APP == Output response: What is dapr?
== APP == Tool calling input sent: What is the weather like in San Francisco in celsius?'
== APP == Tool Call: Name: getWeather - Arguments: location,unit
== APP == Tool Call Output: The weather in San Francisco is 25 degrees Celsius

데모

Diagrid의 Dapr v1.15 기념 행사에서 발표된 데모 영상을 시청해서 .NET SDK를 사용한 conversation API의 동작을 확인해 봐요.

의견을 들려주세요!

우린 Quickstart 예제를 계속 개선하고 있고 여러분의 피드백을 소중히 여겨요. 이 Quickstart가 도움이 됐나요? 개선할 제안이 있나요? Discord Server에 참여해서 의견을 공유해 주세요.

다음 단계

  • 이 quickstart의 HTTP 샘플: Python

  • JavaScript

  • .NET

  • Go

  • conversation 빌딩 블록에 대해 더 알아봐요

Dapr tutorials 탐색하기 >>

더 알아보기 (Learn more)