Skip to content

Commit

Permalink
refactor: update message param types for beta caching ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 9, 2024
1 parent 31ba629 commit 3c324a5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/core/src/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const adjustUsage = (

const convertMessages = (
messages: ChatCompletionMessageParam[]
): Array<Anthropic.Messages.MessageParam> => {
): Array<Anthropic.Beta.PromptCaching.PromptCachingBetaMessageParam> => {
return messages.map(convertSingleMessage)
}

Expand Down Expand Up @@ -93,7 +93,7 @@ const convertSingleMessage = (

const convertToolCallMessage = (
msg: ChatCompletionAssistantMessageParam
): Anthropic.Messages.MessageParam => {
): Anthropic.Beta.PromptCaching.PromptCachingBetaMessageParam => {
return {
role: "assistant",
content: msg.tool_calls.map((tool) => ({
Expand All @@ -107,7 +107,7 @@ const convertToolCallMessage = (

const convertToolResultMessage = (
msg: ChatCompletionToolMessageParam
): Anthropic.Messages.MessageParam => {
): Anthropic.Beta.PromptCaching.PromptCachingBetaMessageParam => {
return {
role: "user",
content: [
Expand All @@ -125,7 +125,7 @@ const convertStandardMessage = (
| ChatCompletionSystemMessageParam
| ChatCompletionAssistantMessageParam
| ChatCompletionUserMessageParam
): Anthropic.Messages.MessageParam => {
): Anthropic.Beta.PromptCaching.PromptCachingBetaMessageParam => {
const role = msg.role === "assistant" ? "assistant" : "user"
if (Array.isArray(msg.content)) {
return {
Expand Down Expand Up @@ -159,7 +159,7 @@ const convertStandardMessage = (

const convertImageUrlBlock = (
block: ChatCompletionContentPartImage
): Anthropic.Messages.ImageBlockParam => {
): Anthropic.Beta.PromptCaching.PromptCachingBetaImageBlockParam => {
return {
type: "image",
source: {
Expand Down Expand Up @@ -219,14 +219,14 @@ export const AnthropicChatCompletion: ChatCompletionHandler = async (
const toolCalls: ChatCompletionToolCall[] = []

try {
const stream = anthropic.messages.stream({
const stream = anthropic.beta.promptCaching.messages.stream({
model,
tools: convertTools(req.tools),
messages,
max_tokens: req.max_tokens || ANTHROPIC_MAX_TOKEN,
temperature: req.temperature,
top_p: req.top_p,
stream: true,
tools: convertTools(req.tools),
...headers,
})

Expand Down

0 comments on commit 3c324a5

Please sign in to comment.