Created
March 7, 2024 08:00
-
-
Save zabirauf/b5cb44ae879ad05eac36ae55de589109 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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