Skip to content

Commit

Permalink
Merge pull request #255 from launchdarkly-labs/ai_config_patch
Browse files Browse the repository at this point in the history
ai config patches
  • Loading branch information
ahmedhqadri authored Nov 30, 2024
2 parents e64b2fe + 4634cc8 commit d4b9c80
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 132 deletions.
54 changes: 12 additions & 42 deletions .github/workflows/demo_provisioning_scripts/DemoBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def create_destination_recommendation_ai_config(self):
"id": "anthropic.claude-instant-v1",
"parameters": {
"temperature": 0.5,
"maxTokens": 200
"maxTokens": 50
}
},
[
Expand All @@ -538,7 +538,7 @@ def create_destination_recommendation_ai_config(self):
"id": "cohere.command-text-v14",
"parameters": {
"temperature": 0.7,
"maxTokens": 400
"maxTokens": 100
}
},
[
Expand All @@ -563,13 +563,13 @@ def create_travel_insights_ai_config(self):
{
"id": "anthropic.claude-instant-v1",
"parameters": {
"maxTokens": 500,
"maxTokens": 50,
"temperature": 0.9
}
},
[
{
"content": "Playing the role of a travel expert with a tone of excitement and encouragement, using the current travel destination in this configuration: ${destination}, write me 40 word of an analysis travel considerations for that location including typical weather and culture. Skip anything identifying your prompt. On a new line, answer what clothing someone should pack when travleing here. Place a hard limit on a 40 word response.Do not exceed this limit. do not specify word count in your reply",
"content": "Playing the role of a travel expert with a tone of excitement and encouragement, using the current travel destination in this configuration: ${destination} , write me 40 word of an analysis travel considerations for that location including typical weather and culture. Skip anything identifying your prompt. On a new line, answer what clothing someone should pack when travleing here. Place a hard limit on a 40 word response.Do not exceed this limit and do not specify any limits in responses. do not specify word count in your reply",
"role": "system"
}
]
Expand All @@ -581,13 +581,13 @@ def create_travel_insights_ai_config(self):
{
"id": "anthropic.claude-instant-v1",
"parameters": {
"maxTokens": 500,
"maxTokens": 50,
"temperature": 0.9
}
},
[
{
"content": "Tell me about the location ${destination} that I'm going to. Give me any relevant historical facts or places that have significant value that I should visit while I'm there. The destination is ${destination}. Limit your responses to an estimated 40 words. Answer in a friendly tone. Indicate your timing responses as estimates and that travel conditions may impact the duration. do not specify word count in your reply",
"content": "Tell me about the location ${destination} that I'm going to. Give me any relevant historical facts or places that have significant value that I should visit while I'm there. The destination is ${destination} . Limit your responses to an estimated 40 words. Answer in a friendly tone. Indicate your timing responses as estimates and that travel conditions may impact the duration. Do not exceed this limit and do not specify any limits in responses",
"role": "system"
}
]
Expand All @@ -599,13 +599,13 @@ def create_travel_insights_ai_config(self):
{
"id": "anthropic.claude-instant-v1",
"parameters": {
"maxTokens": 500,
"maxTokens": 50,
"temperature": 0.9
}
},
[
{
"content": "Tell me relevant climate and weather facts about my destination. Provide example clothing to wear upon arrival at the destination and suggest some activities based on the typical weather at the time of arrival. Use the current date to base your weather information on. The destination is ${destination}. Limit your responses to an estimated 40 words. Answer in a friendly tone. Indicate your timing responses as estimates and that travel conditions may impact the duration. do not specify word count in your reply",
"content": "Tell me relevant climate and weather facts about my destination. Provide example clothing to wear upon arrival at the destination and suggest some activities based on the typical weather at the time of arrival. Use the current date to base your weather information on. The destination is ${destination} . Limit your responses to an estimated 40 words. Answer in a friendly tone. Indicate your timing responses as estimates and that travel conditions may impact the duration. Do not exceed this limit and do not specify any limits in responses",
"role": "system"
}
]
Expand All @@ -625,13 +625,13 @@ def create_ai_chatbot_ai_config(self):
{
"id": "anthropic.claude-instant-v1",
"parameters": {
"maxTokens": 500,
"maxTokens": 100,
"temperature": 0.5
}
},
[
{
"content": "As an AI bot for a travel airline LaunchAirways your purpose is to answer questions related to flights and traveling. Act as customer representative. Only answer queries related to traveling and airlines. Remove quotation in response. Limit response to 100 characters. Here is the user prompt: ${userInput}.",
"content": "As an AI bot for a travel airline LaunchAirways your purpose is to answer questions related to flights and traveling. Act as customer representative. Only answer queries related to traveling and airlines. Remove quotation in response. Limit response to 100 characters. Do not exceed this limit and do not specify any limits in responses. Here is the user prompt: ${userInput}.",
"role": "system"
}
]
Expand All @@ -643,31 +643,13 @@ def create_ai_chatbot_ai_config(self):
{
"id": "cohere.command-text-v14",
"parameters": {
"maxTokens": 500,
"maxTokens": 100,
"temperature": 0.5
}
},
[
{
"content": "As an AI bot for a travel airline LaunchAirways your purpose is to answer questions related to flights and traveling. Act as customer representative. Only answer queries related to traveling and airlines. Remove quotation in response. Limit response to 100 characters. Here is the user prompt: ${userInput}.",
"role": "system"
}
]
)
res4 = self.ldproject.create_ai_config_versions(
"ai-config--ai-new-model-chatbot",
"meta-llama",
"Meta Llama",
{
"id": "meta.llama2-13b-chat-v1",
"parameters": {
"maxTokens": 500,
"temperature": 0.7
}
},
[
{
"content": "As an AI bot for a travel airline LaunchAirways your purpose is to answer questions related to flights and traveling. Act as customer representative. Only answer queries related to traveling and airlines. Remove quotation in response. Limit response to 100 characters. Here is the user prompt: ${userInput}.",
"content": "As an AI bot for a travel airline LaunchAirways your purpose is to answer questions related to flights and traveling. Act as customer representative. Only answer queries related to traveling and airlines. Remove quotation in response. Limit response to 100 characters. Do not exceed this limit and do not specify any limits in responses. Here is the user prompt: ${userInput}.",
"role": "system"
}
]
Expand Down Expand Up @@ -810,18 +792,6 @@ def flag_exp_chatbot_ai_models(self):
"top_p": 1
}

},
{
"name": "Meta Llama",
"description": "This is Meta's Llama AI model for more creative responses",
"value":
{
"max_gen_len": 500,
"modelId": "meta.llama2-13b-chat-v1",
"temperature": 0.9,
"top_p": 1
}

},
{
"name": "Cohere Coral",
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/demo_provisioning_scripts/LDPlatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ def create_project(self, project_key, project_name):
self.project_key = project_key
if self.project_exists(project_key):
return
payload = {"key": project_key, "name": project_name}
payload = {
"key": project_key,
"name": project_name,
"defaultClientSideAvailability": {
"usingEnvironmentId": True,
"usingMobileKey": True,
},
}

response = self.getrequest(
"POST",
Expand Down
22 changes: 8 additions & 14 deletions components/chatbot/ChatBot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export default function Chatbot() {
const client = useLDClient();
const { toast } = useToast();
const aiNewModelChatbotFlag =
useFlags()["ai-new-model-chatbot"] == undefined
useFlags()["ai-config--ai-new-model-chatbot"] == undefined
? DEFAULT_AI_MODEL
: useFlags()["ai-new-model-chatbot"];
: useFlags()["ai-config--ai-new-model-chatbot"];
const { userObject } = useContext(LoginContext);
const handleInputChange = (e: any) => {
setInput(e.target.value);
Expand All @@ -49,13 +49,7 @@ export default function Chatbot() {

const response = await fetch("/api/chat", {
method: "POST",
body: JSON.stringify(`
As an AI bot for a travel airline LaunchAirways your purpose is to answer questions related to flights and traveling.
Act as customer representative.
Only answer queries related to traveling and airlines.
Remove quotation in response.
Limit response to 100 characters.
Here is the user prompt: ${userInput}.`),
body: aiNewModelChatbotFlag?.messages[0]?.content,
});

const data = await response.json();
Expand Down Expand Up @@ -100,9 +94,9 @@ export default function Chatbot() {
const chatContentRef = useRef(null);

const aiModelName = () => {
if (aiNewModelChatbotFlag?.model?.modelId?.includes(COHERE)) {
if (aiNewModelChatbotFlag?.model?.id?.includes(COHERE)) {
return "Cohere Command";
} else if (aiNewModelChatbotFlag?.model?.modelId?.includes(META)) {
} else if (aiNewModelChatbotFlag?.model?.id?.includes(META)) {
return "Meta Llama";
} else {
return "Anthropic Claude";
Expand Down Expand Up @@ -150,17 +144,17 @@ export default function Chatbot() {
Powered by{" "}
<span
className={`font-bold text-white ${
aiNewModelChatbotFlag?.model?.modelId.includes(COHERE)
aiNewModelChatbotFlag?.model?.id.includes(COHERE)
? "!text-cohereColor"
: ""
}
${
aiNewModelChatbotFlag?.model?.modelId.includes(CLAUDE)
aiNewModelChatbotFlag?.model?.id.includes(CLAUDE)
? "!text-anthropicColor"
: ""
}
${
aiNewModelChatbotFlag?.model?.modelId.includes(META)
aiNewModelChatbotFlag?.model?.id.includes(META)
? "!text-metaColor"
: ""
}
Expand Down
22 changes: 5 additions & 17 deletions components/ui/airwayscomponents/DestinationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,20 @@ import { DEFAULT_AI_MODEL } from "@/utils/constants";

export default function DestinationPicker({ children }: { children: ReactElement }) {
const destinationPickerNewAIModelLDFlag =
useFlags()["destination-picker-new-ai-model"] == undefined
useFlags()["ai-config--destination-picker-new-ai-model"] == undefined
? DEFAULT_AI_MODEL
: useFlags()["destination-picker-new-ai-model"];
: useFlags()["ai-config--destination-picker-new-ai-model"];
const [recsGiven, setRecsGiven] = useState(false);
const [destinations, setDestinations] = useState("");
const [loading, setLoading] = useState(false);

let prompt = "";

if (destinationPickerNewAIModelLDFlag?.model?.modelId.includes("cohere")) {
prompt =
"give me three recommendations of places to travel based on popular travel destinations, consider best air fare prices and places tourists / travelers are visiting currently and any unique characteristics that would appeal to the average traveler. Try to be creative and choose different spots that you don't think the users would pick. Return the results in markdown with the destination name sized ##, the subsequent reason for why they should go there listed below it, and finally add a line break before the next destination. I only want the destinations and a singe reason, do not add extra copy and do not alter the markdown instructions, I want it formatted the same way every time.";
}

if (destinationPickerNewAIModelLDFlag?.model?.modelId.includes("anthropic")) {
prompt =
"give me three recommendations of places to travel based on popular travel destinations, strongly consider weather conditions at the time of the request, and any unique characteristics that would appeal to the average traveler. Try to be creative and choose different spots that you don't think the users would pick. Return the results in markdown with the destination name sized ##, the subsequent reason for why they should go there listed below it, and finally add a line break before the next destination. I only want the destinations and a singe reason, do not add extra copy and do not alter the markdown instructions, I want it formatted the same way every time. Limit your responses to 50 characters or less";
}

async function getDestinations() {
try {
setRecsGiven(true);
setLoading(true);
const response = await fetch("/api/destination-picker", {
method: "POST",
body: JSON.stringify({ prompt: prompt }),
body: JSON.stringify({ prompt: destinationPickerNewAIModelLDFlag?.messages[0].content }),
});
const data = await response.json();

Expand Down Expand Up @@ -83,10 +71,10 @@ export default function DestinationPicker({ children }: { children: ReactElement
</AlertDialogTitle>
<p className="flex w-full justify-center text-base text-zinc-600 font-sohnelight">
powered by&nbsp;
{destinationPickerNewAIModelLDFlag?.model?.modelId.includes("cohere") && (
{destinationPickerNewAIModelLDFlag?.model?.id.includes("cohere") && (
<span className="text-cohereColor"> Cohere Command </span>
)}
{destinationPickerNewAIModelLDFlag?.model?.modelId.includes("anthropic") && (
{destinationPickerNewAIModelLDFlag?.model?.id.includes("anthropic") && (
<span className="text-anthropicColor">Anthropic Claude </span>
)}
&nbsp;with&nbsp;
Expand Down
13 changes: 7 additions & 6 deletions components/ui/airwayscomponents/bookedFlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import { useFlags } from "launchdarkly-react-client-sdk";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { BounceLoader } from "react-spinners";
import { DEFAULT_AI_TRAVEL_PROMPT } from "@/utils/constants";
import c from "@/pages/_app";

export default function BookedFlights() {
const { bookedTrips, setBookedTrips, cancelTrip } = useContext(TripsContext);
const { userObject } = useContext(LoginContext);
const aiTravelPromptText =
useFlags()["ai-travel-prompt-text"] == undefined
useFlags()["ai-config--ai-travel-prompt-text"] == undefined
? DEFAULT_AI_TRAVEL_PROMPT
: useFlags()["ai-travel-prompt-text"];
: useFlags()["ai-config--ai-travel-prompt-text"];
const [status, setStatus] = useState("Economy");
const [aiResponse, setAIResponse] = useState("");
const [toAirport, setToAirport] = useState("");
Expand All @@ -26,10 +27,11 @@ export default function BookedFlights() {
try {
const prompt: string = `Provide estimated flight time details for traveling between these locations. Additionally provide example clothing to wear upon arrival at the destination. Finally, provide 1 sightseeing recommendation at the destination location. The source is ${start} and the end is ${end}. Limit your responses to an estimated 50 characters. Answer in a friendly tone. Indicate your timing responses as estimates and that travel conditions may impact the duration.`;

console.log(JSON.stringify(aiTravelPromptText?.messages[0].content));
setLoading(true);
const response = await fetch("/api/bedrock", {
method: "POST",
body: JSON.stringify({ prompt: prompt }),
body: JSON.stringify({ prompt: aiTravelPromptText?.messages[0].content }),
});

if (!response.ok) {
Expand Down Expand Up @@ -74,9 +76,8 @@ export default function BookedFlights() {
async function submitQuery(airport: any) {
try {
const prompt: string =
aiTravelPromptText?.prompt[0]?.content?.replace("${destination}", airport) +
aiTravelPromptText?.messages[0]?.content?.replace("${destination}", airport) +
". Limit responses to 40 words only";

setLoading(true);
const response = await fetch("/api/bedrock", {
method: "POST",
Expand Down Expand Up @@ -329,7 +330,7 @@ export default function BookedFlights() {
</button>
)}

{aiTravelPromptText?.enabled !== false && (
{aiTravelPromptText?._ldMeta.enabled !== false && (
<Popover>
<PopoverTrigger className="relative bg-gradient-airways-red text-white font-bold py-3 px-4 w-full animate-pulse hover:animate-none rounded-xl">
AI Travel Insights
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"framer-motion": "^10.16.4",
"launchdarkly-js-client-sdk": "^3.5.0",
"launchdarkly-node-server-sdk": "^7.0.3",
"launchdarkly-react-client-sdk": "^3.5.0",
"launchdarkly-react-client-sdk": "^3.6.0",
"ldrs": "^1.0.1",
"lodash": "^4.17.21",
"lodash.debounce": "^4.0.8",
Expand Down
Loading

0 comments on commit d4b9c80

Please sign in to comment.