-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from intelligentnode/110-add-anthropic-model
110 add anthropic model
- Loading branch information
Showing
11 changed files
with
176 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require('dotenv').config(); | ||
const assert = require('assert'); | ||
const AnthropicWrapper = require('../../wrappers/AnthropicWrapper'); | ||
|
||
// initiate anthropic object | ||
const anthropic = new AnthropicWrapper(process.env.ANTHROPIC_API_KEY); | ||
|
||
async function testAnthropicGenerate() { | ||
try { | ||
const params = { | ||
"model": "claude-3-sonnet-20240229", | ||
"messages": [ | ||
{ | ||
"role": "user", | ||
"content": "Who is the most renowned French painter? Provide a single direct short answer." | ||
} | ||
], | ||
"max_tokens": 256 | ||
}; | ||
|
||
const result = await anthropic.generateText(params); | ||
console.log('Anthropic Language Model Result:', result.content[0].text); | ||
} catch (error) { | ||
console.error('Anthropic Language Model Error:', error); | ||
} | ||
} | ||
|
||
(async () => { | ||
await testAnthropicGenerate(); | ||
})(); |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Apache License | ||
Copyright 2023 Github.com/Barqawiz/IntelliNode | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
const axios = require('axios'); | ||
const config = require('../config.json'); | ||
const connHelper = require('../utils/ConnHelper'); | ||
|
||
class AnthropicWrapper { | ||
constructor(apiKey) { | ||
this.API_BASE_URL = config.url.anthropic.base; | ||
this.API_VERSION = config.url.anthropic.version; | ||
this.httpClient = axios.create({ | ||
baseURL: this.API_BASE_URL, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json', | ||
'x-api-key': apiKey, | ||
'anthropic-version': this.API_VERSION | ||
} | ||
}); | ||
} | ||
|
||
async generateText(params) { | ||
const url = config.url.anthropic.messages; | ||
try { | ||
const response = await this.httpClient.post(url, params); | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(connHelper.getErrorMessage(error)); | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = AnthropicWrapper; |