on-demand.io give 150 USD free credit anything can be done here? #589
fortunamagix
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
// Function to create a chat session
async function createChatSession(apiKey, externalUserId) {
const response = await fetch('https://api.on-demand.io/chat/v1/sessions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'apikey': apiKey
},
body: JSON.stringify({
pluginIds: [],
externalUserId: externalUserId
})
});
if (response.status === 201) {
const data = await response.json();
return data.data.id; // Extract session ID
} else {
throw new Error('Failed to create chat session');
}
}
// Function to submit a query using the session ID
async function submitQuery(apiKey, sessionId, query) {
const url =
https://api.on-demand.io/chat/v1/sessions/${sessionId}/query
;const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'apikey': apiKey
},
body: JSON.stringify({
endpointId: 'predefined-claude-3-5-sonnet-v2',
query: query,
pluginIds: ['plugin-1712327325', 'plugin-1713962163'],
responseMode: 'sync'
})
});
if (response.status === 200) {
const data = await response.json();
return data;
} else {
throw new Error('Failed to submit query');
}
}
// Example usage
(async () => {
try {
const apiKey = '<replace_api_key>';
const externalUserId = '<replace_external_user_id>';
const query = 'Put your query here';
} catch (error) {
console.error(error);
}
})();
Beta Was this translation helpful? Give feedback.
All reactions