Skip to content

Commit 138ac62

Browse files
committed
created keys for metric
1 parent 6a347e3 commit 138ac62

File tree

3 files changed

+45
-243
lines changed

3 files changed

+45
-243
lines changed

components/chatbot/ChatBot.tsx

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import { Input } from "@/components/ui/input";
66
import { wait } from "@/utils/utils";
77
import { useChat } from "ai/react";
88
import { v4 as uuidv4 } from "uuid";
9-
// Force the page to be dynamic and allow streaming responses up to 30 seconds
10-
// export const dynamic = "force-dynamic";
11-
// export const maxDuration = 30;
9+
import { useFlags, useLDClient } from "launchdarkly-react-client-sdk";
1210

1311
//https://sdk.vercel.ai/providers/legacy-providers/aws-bedrock
1412
export default function Chatbot() {
@@ -17,7 +15,7 @@ export default function Chatbot() {
1715
const startArray: object[] = [];
1816
const [messages2, setMessages2] = useState(startArray);
1917
const [isLoading, setIsLoading] = useState(false);
20-
18+
const client = useLDClient();
2119
const handleInputChange2 = (e: any) => {
2220
setInput2(e.target.value);
2321
};
@@ -88,29 +86,32 @@ export default function Chatbot() {
8886
<Button
8987
variant="ghost"
9088
size="icon"
91-
title = "How was our service today?"
89+
title="How was our service today?"
9290
className="rounded-full bg-[#55efc4] text-gray-900 hover:bg-[#00b894] dark:bg-[#55efc4] dark:text-gray-900 dark:hover:bg-[#00b894]"
91+
onClick={() => client?.track("ai-chatbot-good-service", client.getContext())}
9392
>
9493
<SmileIcon className="h-6 w-6" />
95-
<span className="sr-only">Smile</span>
94+
<span className="sr-only">Good</span>
9695
</Button>
9796
<Button
9897
variant="ghost"
9998
size="icon"
100-
title = "How was our service today?"
99+
title="How was our service today?"
101100
className="rounded-full bg-[#ffeaa7] text-gray-900 hover:bg-[#fdcb6e] dark:bg-[#ffeaa7] dark:text-gray-900 dark:hover:bg-[#fdcb6e]"
101+
onClick={() => client?.track("ai-chatbot-neutral-service", client.getContext())}
102102
>
103103
<MehIcon className="h-6 w-6" />
104104
<span className="sr-only">Neutral</span>
105105
</Button>
106106
<Button
107107
variant="ghost"
108108
size="icon"
109-
title = "How was our service today?"
109+
title="How was our service today?"
110110
className="rounded-full bg-[#ff7675] text-gray-50 hover:bg-[#d63031] dark:bg-[#ff7675] dark:text-gray-50 dark:hover:bg-[#d63031]"
111+
onClick={() => client?.track("ai-chatbot-bad-service", client.getContext())}
111112
>
112113
<FrownIcon className="h-6 w-6" />
113-
<span className="sr-only">Sad</span>
114+
<span className="sr-only">Bad</span>
114115
</Button>
115116
<Button
116117
variant="ghost"
@@ -255,7 +256,7 @@ function SmileIcon(props) {
255256
<line x1="9" x2="9.01" y1="9" y2="9" />
256257
<line x1="15" x2="15.01" y1="9" y2="9" />
257258
</svg>
258-
)
259+
);
259260
}
260261

261262
function FrownIcon(props) {
@@ -277,10 +278,9 @@ function FrownIcon(props) {
277278
<line x1="9" x2="9.01" y1="9" y2="9" />
278279
<line x1="15" x2="15.01" y1="9" y2="9" />
279280
</svg>
280-
)
281+
);
281282
}
282283

283-
284284
function MehIcon(props) {
285285
return (
286286
<svg
@@ -300,5 +300,5 @@ function MehIcon(props) {
300300
<line x1="9" x2="9.01" y1="9" y2="9" />
301301
<line x1="15" x2="15.01" y1="9" y2="9" />
302302
</svg>
303-
)
303+
);
304304
}

pages/api/chat.ts

+32-72
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
import {
22
BedrockRuntimeClient,
33
InvokeModelCommand,
4-
InvokeModelWithResponseStreamCommand,
5-
ConverseStreamCommand,
6-
ConverseCommand,
7-
ConversationRole,
4+
// InvokeModelWithResponseStreamCommand,
5+
// ConverseStreamCommand,
6+
// ConverseCommand,
7+
// ConversationRole,
88
} from "@aws-sdk/client-bedrock-runtime";
9-
import {
10-
AWSBedrockAnthropicStream,
11-
StreamingTextResponse,
12-
AWSBedrockLlama2Stream,
13-
AWSBedrockCohereStream,
14-
AWSBedrockStream,
15-
} from "ai";
16-
import { experimental_buildAnthropicPrompt, experimental_buildLlama2Prompt } from "ai/prompts";
9+
// import {
10+
// AWSBedrockAnthropicStream,
11+
// StreamingTextResponse,
12+
// AWSBedrockLlama2Stream,
13+
// AWSBedrockCohereStream,
14+
// AWSBedrockStream,
15+
// } from "ai";
16+
//import { experimental_buildAnthropicPrompt, experimental_buildLlama2Prompt } from "ai/prompts";
1717
import { NextApiRequest, NextApiResponse } from "next";
18-
import { NextResponse } from "next/server";
1918
import { getServerClient } from "@/utils/ld-server";
20-
21-
import { wait } from "@/utils/utils";
2219
// import { ldClient } from "@/utils/ld-server/serverClient";
2320
import { getCookie } from "cookies-next";
2421
// export const dynamic = "force-dynamic";
2522
// export const runtime = "edge";
2623

24+
//https://sdk.vercel.ai/providers/legacy-providers/aws-bedrock
2725
export default async function chatResponse(req: NextApiRequest, res: NextApiResponse) {
2826
const bedrockClient = new BedrockRuntimeClient({
2927
region: process.env.AWS_DEFAULT_REGION ?? "us-west-2",
@@ -33,9 +31,9 @@ export default async function chatResponse(req: NextApiRequest, res: NextApiResp
3331
},
3432
});
3533
const messages = req.body;
36-
console.log("awefawefmessages", messages);
34+
3735
const ldClient = await getServerClient(process.env.LD_SDK_KEY || "");
38-
36+
console.log("ldClient",ldClient)
3937
const context: any = getCookie("ld-context") || { "kind": "user", "name": "anonymous", "key": "abc-123" };
4038

4139
const model = await ldClient.variation("ai-chatbot", context, {
@@ -47,12 +45,12 @@ export default async function chatResponse(req: NextApiRequest, res: NextApiResp
4745
})
4846

4947
// Ask Claude for a streaming chat completion given the prompt
50-
const claudeMessage = [
51-
{
52-
role: "user",
53-
content: "Where is a good vacation place for under $1000? Limit to 100 characters.",
54-
},
55-
];
48+
// const claudeMessage = [
49+
// {
50+
// role: "user",
51+
// content: "Where is a good vacation place for under $1000? Limit to 100 characters.",
52+
// },
53+
// ];
5654

5755
const chatBotModelInput = new InvokeModelCommand({
5856
modelId: model.modelId,
@@ -67,8 +65,6 @@ export default async function chatResponse(req: NextApiRequest, res: NextApiResp
6765
}),
6866
});
6967

70-
71-
7268
try {
7369
const bedrockResponse = await bedrockClient.send(chatBotModelInput);
7470
const decoder = new TextDecoder();
@@ -79,52 +75,16 @@ export default async function chatResponse(req: NextApiRequest, res: NextApiResp
7975
throw new Error(error.message);
8076
}
8177

82-
// const llamaMessage = [
83-
// {
84-
// role: "user",
85-
// content: "Where is a good vacation place for under $1000? Limit to 100 characters.",
86-
// },
87-
// ];
88-
89-
// const llama = new InvokeModelWithResponseStreamCommand({
90-
// modelId: "meta.llama2-13b-chat-v1",
91-
// contentType: "application/json",
92-
// accept: "application/json",
93-
// body: JSON.stringify({
94-
// prompt: experimental_buildLlama2Prompt(llamaMessage),
95-
// temperature: 0.9,
96-
// max_gen_len: 500,
97-
// top_p: 1,
98-
// }),
99-
// });
100-
101-
// const bedrockResponse = await bedrockClient.send(llama);
102-
// const stream = AWSBedrockLlama2Stream(bedrockResponse); // Convert the response into a friendly text-stream
103-
// return new StreamingTextResponse(stream); // Respond with the stream
104-
105-
// const cohereMessage = [
106-
// {
107-
// role: "user",
108-
// content: "Where is a good vacation place for under $1000? Limit to 100 characters.",
109-
// },
110-
// ];
111-
11278
// const cohere = new InvokeModelWithResponseStreamCommand({
113-
// modelId: "cohere.command-text-v14",
114-
// contentType: "application/json",
115-
// accept: "application/json",
116-
// body: JSON.stringify({
117-
// prompt: experimental_buildLlama2Prompt(cohereMessage),
118-
// temperature: 0.9,
119-
// max_tokens: 500,
120-
// p: 1,
121-
// }),
122-
// });
123-
124-
// const bedrockResponse = await bedrockClient.send(cohere);
125-
// const stream = AWSBedrockCohereStream(bedrockResponse); // Convert the response into a friendly text-stream
126-
// console.log("bedrockResponse", bedrockResponse)
127-
// console.log("stream",stream)
128-
// console.log("new StreamingTextResponse(stream)",new StreamingTextResponse(stream))
129-
// return new StreamingTextResponse(stream); // Respond with the stream
79+
// modelId: "cohere.command-text-v14",
80+
// contentType: "application/json",
81+
// accept: "application/json",
82+
// body: JSON.stringify({
83+
// prompt: experimental_buildLlama2Prompt(cohereMessage),
84+
// temperature: 0.9,
85+
// max_tokens: 500,
86+
// p: 1,
87+
// }),
88+
// });
89+
13090
}

pages/api/holder.ts

-158
This file was deleted.

0 commit comments

Comments
 (0)