import OpenAI from "openai";
const openAISecretKey = "<OPENAI_SECRET_KEY>";
const openai = new OpenAI({ apiKey: openAISecretKey });
const messageHistory = [
{
role: "system",
content:
"You are a helpful assistant. Please provide short, concise answers.",
},
];
async function getCompletion() {
const completion = await openai.chat.completions.create({
messages: messageHistory,
model: "gpt-4o-mini",
});
const reply = completion.choices[0].message.content;
return reply;
}
function App() {
const me = {
id: "79302",
name: "Nina Caldwell",
email: "nina.caldwell@example.com", // for offline
};
const botUser = {
id: "bot",
name: "Helpful Bot",
};
const syncUser = useCallback(() => {
return new Talk.User(me);
}, []);
const syncConversation = useCallback((session) => {
// Add users to the conversation
const conversation = session.getOrCreateConversation(
Talk.oneOnOneId(me, botUser)
);
conversation.setParticipant(session.me);
conversation.setParticipant(new Talk.User(botUser));
return conversation;
}, []);
return (
<Session appId="<APP_ID>" syncUser={syncUser}>
<Chatbox syncConversation={syncConversation} className="chat-container" />
</Session>
);
}