Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add anthropic models #788

Merged
merged 2 commits into from
Oct 21, 2024
Merged

Add anthropic models #788

merged 2 commits into from
Oct 21, 2024

Conversation

waltoss
Copy link
Contributor

@waltoss waltoss commented Oct 19, 2024

Integrate Anthropic Models

  • 🚀 Added support for Anthropic models in the application.
  • 🔧 Introduced @anthropic-ai/sdk as a dependency.
  • 📄 Defined new model connections for Anthropic in prompt_template.d.ts.
  • 🌐 Configured environment variables for Anthropic API integration.
  • 🛠 Extended constants and model providers with Anthropic support.
  • 📈 Implemented functionality for handling Anthropic chat completions.

@waltoss
Copy link
Contributor Author

waltoss commented Oct 19, 2024

@microsoft-github-policy-service agree

prompt_tokens: usage.input_tokens,
completion_tokens: usage.output_tokens,
total_tokens: usage.input_tokens + usage.output_tokens,
} satisfies OpenAI.ChatCompletionUsage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, i should start using this one

import * as OpenAI from "./chattypes"

import { logError } from "./util"
import { ChatCompletionMessageToolCall } from "openai/resources/index.mjs"
Copy link
Member

@pelikhan pelikhan Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the openai types are redefined in "chattypes.ts"

historical reasons: genaiscript used to crossbuild for vscode and the openai sdk was node only so we do import type on their interfaces.

}

const convertToolCallMessage = (
msg: OpenAI.ChatCompletionMessageParam & {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want ChatCompletionAssistantMessageParam

content: msg.tool_calls.map((tool) => ({
type: "tool_use",
id: tool.id,
input: JSON.parse(tool.function.arguments),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChatCompletionToolCall arguments is a string. The parsing happens later and handles malformed JSON.

const version = env.ANTHROPIC_API_VERSION || undefined
const source = "env: ANTHROPIC_API_..."
const modelKey = "ANTHROPIC_API_KEY"
const type = "anthropic"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MODEL_PROVIDER_ANTHROPIC ?

| "azure"
| "localai"
| "azure_serverless"
| "anthropic"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the apitype is really only used for variants of openai; since we have a specific provider here, i think we don't need this one.

@pelikhan
Copy link
Member

Looks good to me. THere's a few minor comments and if you could add a section in Configuration.mdx (run yarn docs to render docs locally).

@pelikhan pelikhan merged commit 41bcad7 into microsoft:main Oct 21, 2024
4 of 7 checks passed
@pelikhan
Copy link
Member

I'll patch up the types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants