Skip to content

Instantly share code, notes, and snippets.

@zabirauf
Created March 7, 2024 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zabirauf/b5cb44ae879ad05eac36ae55de589109 to your computer and use it in GitHub Desktop.
Save zabirauf/b5cb44ae879ad05eac36ae55de589109 to your computer and use it in GitHub Desktop.
async function anthropicReproducable(content: string): Promise<string> {
try {
let apiKey = 'Add API key'
const data = {
model: 'claude-3-sonnet-20240229',
system: "You are helpful assistant and your name it Le'Claude. Always add your name in response",
messages: [
{
role: 'user',
content: content,
},
],
temperature: 1,
max_tokens: 2048,
};
const response = await fetch('https://api.anthropic.com/v1/messages', {
method: 'POST',
headers: {
'x-api-key': `${apiKey}`,
'anthropic-version': '2023-06-01',
'content-type': 'application/json',
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const responseData = await response.json();
return responseData['content'][0]['text'];
} catch (error) {
console.error('Error calling Anthropic API:', error);
throw error;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment