-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add sonnet model, opus model + fix chat action status infinite loop a…
…fter error
- Loading branch information
Showing
7 changed files
with
94 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import axios from 'axios' | ||
import config from '../../../config' | ||
import { type ChatConversation } from '../../types' | ||
import { type LlmCompletion } from './llmApi' | ||
import { LlmsModelsEnum } from '../types' | ||
|
||
const API_ENDPOINT = config.llms.apiEndpoint | ||
|
||
export const anthropicCompletion = async ( | ||
conversation: ChatConversation[], | ||
model = LlmsModelsEnum.CLAUDE_OPUS | ||
): Promise<LlmCompletion> => { | ||
const data = { | ||
model, | ||
stream: false, | ||
system: config.openAi.chatGpt.chatCompletionContext, | ||
max_tokens: +config.openAi.chatGpt.maxTokens, | ||
messages: conversation | ||
} | ||
const url = `${API_ENDPOINT}/anthropic/completions` | ||
const response = await axios.post(url, data) | ||
const respJson = JSON.parse(response.data) | ||
if (response) { | ||
const totalInputTokens = respJson.usage.input_tokens | ||
const totalOutputTokens = respJson.usage.output_tokens | ||
const completion = respJson.content | ||
|
||
return { | ||
completion: { | ||
content: completion[0].text, | ||
role: 'assistant', | ||
model | ||
}, | ||
usage: totalOutputTokens + totalInputTokens, | ||
price: 0 | ||
} | ||
} | ||
return { | ||
completion: undefined, | ||
usage: 0, | ||
price: 0 | ||
} | ||
} |
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