04-17-2024 7:46 PM - edited 04-19-2024 10:25 AM
I'm currently working on a project using SAPUI5, and I need to integrate models from SAP AI Core, like GPT-3 5-Turbo, GPT-16K, and GPT-4 32K. I already have the model configurations set up, but I'm not sure how to end this single trace when the inputs and outputs are visible on Langsmith Dashboard.
export const sendPromptToAiCore = async (prompt: any, enrichedPrompt: any, destinationDetailsObj: any) => {
let parsedPrompt = '';
if (prompt) {
const { prompt: question } = prompt;
parsedPrompt = createPrompt({ ...enrichedPrompt, question });
console.log(' ~ ChatPromptService ~ sendPromptToAiCore ~ parsedPrompt:', parsedPrompt);
} else {
parsedPrompt = enrichedPrompt;
}
const destinationDetailsAI = destinationDetailsObj;
const modelConfiguration = destinationDetailsAI?.originalProperties.destinationConfiguration;
const { 'gpt-35-turbo': turbo, 'gpt-4': gpt4, 'gpt-4-32k': gpt432k } = modelConfiguration || {};
const chatModelDeploymentId = turbo || gpt4 || gpt432k;
const { 'api-version': apiVersion, 'ai-resource-group': aiResourceGroup } = modelConfiguration || {};
try {
if (destinationDetailsAI && chatModelDeploymentId && apiVersion && aiResourceGroup) {
const response = await executeHttpRequest(
{
url: `${destinationDetailsAI.url}/deployments/${chatModelDeploymentId}/chat/completions?api-version=${apiVersion}`,
},
{
method: 'POST',
headers: {
'AI-Resource-Group': aiResourceGroup,
'Content-Type': 'application/json',
Authorization: `Bearer ${destinationDetailsAI.authTokens[0].value}`,
},
data: {
messages: [{ role: 'system', content: parsedPrompt }],
temperature: 0.7, // Adjust for creativity
frequency_penalty: 0,
presence_penalty: 0,
stop: null,
},
},
{
fetchCsrfToken: false,
},
);
return response.data.choices[0].message.content;
}
return 'No proper destination configured for AI Core Chat Model Service';
} catch (error) {
console.error('Error sending prompt to AI Core Service:', error);
throw error;
}
};
User | Count |
---|---|
80 | |
11 | |
10 | |
8 | |
8 | |
6 | |
6 | |
6 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.