-
-
Save deepakness/d8ae6ba14b751f61a96f02c04b452758 to your computer and use it in GitHub Desktop.
Connect Anthropic Claude API to Google Sheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callClaude(promptText) { | |
// Your API key should be specified here. | |
const apiKey = 'your_api_key'; | |
// Set necessary parameters for your request. | |
const requestBody = { | |
prompt: "\n\nHuman: " + promptText + "\n\nAssistant: ", | |
model: "claude-v1", | |
max_tokens_to_sample: 100, | |
stop_sequences: ["\n\nHuman:"] | |
}; | |
// Configure the options for your request. | |
const requestOptions = { | |
method: 'post', | |
contentType: 'application/json', | |
payload: JSON.stringify(requestBody), | |
headers: { | |
'x-api-key': apiKey, | |
}, | |
}; | |
// Make the request and parse the response. | |
const apiResponse = UrlFetchApp.fetch('https://api.anthropic.com/v1/complete', requestOptions); | |
const responseText = JSON.parse(apiResponse.getContentText()); | |
// Extract the Assistant's response and return it. | |
const assistantResponse = responseText.completion.trim(); | |
return assistantResponse; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment