Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/conversation/components/conversation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: echo
spec:
type: conversation.echo
version: v1
250 changes: 250 additions & 0 deletions examples/conversation/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions examples/conversation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "conversation",
"version": "1.0.0",
"description": "An example utilizing the Dapr JS SDK to call a conversation component",
"main": "dist/index.js",
"private": true,
"type": "module",
"scripts": {
"build": "rimraf ./dist && tsc",
"start": "npm run build && node dist/index.js",
"start:dapr": "dapr run --app-id conversation --app-protocol grpc --dapr-grpc-port 3500 --resources-path ./components/ -- npm run start"
},
"author": "",
"keywords": [],
"license": "ISC",
"devDependencies": {
"rimraf": "^3.0.2",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
},
"dependencies": {
"@dapr/dapr": "file:../../build",
"@types/node": "^15.3.0"
}
}
86 changes: 86 additions & 0 deletions examples/conversation/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Copyright 2022 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// @ts-nocheck
import { DaprClient } from "@dapr/dapr";

const LLM_NAME = "echo";

async function main() {
const daprHost = process.env.DAPR_HOST || "http://localhost";
const daprHttpPort = process.env.DAPR_HTTP_PORT || "3500";
const client = new DaprClient({ daprHost, daprPort: daprHttpPort });

try {
const response = await client.conversation.converseAsync(
LLM_NAME,
[
{
messages: [
{
of_user: {
content: [
{
text: "What is the weather like in San Francisco in celsius?",
},
],
},
},
],
scrub_pii: false,
},
],
{
metadata: {
api_key: "test-key",
version: "1.0",
},
scrub_pii: 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"],
},
},
},
],
tool_choice: "auto",
},
);
console.log("Response:", response);
} catch (error) {
console.error("Error:", (error as Error).message);
process.exit(1);
}
}

main().catch((error) => {
console.error("Unhandled error:", error);
process.exit(1);
});
Loading