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

feat(AI-proxy-plugin): support the new /v1/messages API provided by Anthropic #12699

Merged
merged 5 commits into from
Apr 9, 2024

Conversation

liverpool8056
Copy link
Contributor

Summary

Support the newly provided API /v1/messages of Anthropic in AI-proxy plugin.
In this PR, the upstream path of Anthropic for llm/v1/chat route type is changed from pointing to /v1/complete to now pointing to the new API path /v1/messages.

A doc page PR is needed correspondingly for this update.

Checklist

  • The Pull Request has tests
  • A changelog file has been added to CHANGELOG/unreleased/kong or adding skip-changelog label on PR if unnecessary. README.md
  • The Pull Request has backports to all the versions it needs to cover
  • There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - PUT DOCS PR HERE

Issue reference

FTI-5770

@ttyS0e
Copy link
Contributor

ttyS0e commented Mar 13, 2024

I think you have got this bang on, looks good. I think you're right that we don't need to support both old and new Claude.

@locao locao requested a review from flrgh March 19, 2024 20:32
@@ -0,0 +1,5 @@
"message": "**AI-Proxy**: To support the new messages API of `Anthropic`, the upstream path of the `Anthropic` for `llm/v1/chat` route type is changed from `/v1/complete` to `/v1/messages`"
Copy link
Contributor

Choose a reason for hiding this comment

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

would this be a breaking change to mention in changelog?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fffonion Let me mention it in changelog, thanks!

@github-actions github-actions bot added the cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee label Mar 25, 2024
@liverpool8056
Copy link
Contributor Author

@ttyS0e Could you give this a review please? Thanks!

@tysoekong
Copy link
Contributor

Yes this is fantastic, if possible please merge so I can then add the "Streaming" transformation over the top for my PR.

@tysoekong
Copy link
Contributor

@liverpool8056

Copy link
Contributor

@tysoekong tysoekong left a comment

Choose a reason for hiding this comment

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

Yes this is great, I need to add streaming support too so if any bug is found I will just roll up the fixes into the next commit.

if response_table.completion then
local function extract_text_from_content(content)
local buf = buffer:new()
buf:reset()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to reset the buffer? it was created in the previous line

Copy link
Contributor

@brentos brentos left a comment

Choose a reason for hiding this comment

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

Just a couple things, otherwise LGTM

@liverpool8056 liverpool8056 force-pushed the ai-plugin-anthropic-messages-api branch from 7e9821b to ef0ec90 Compare April 1, 2024 03:23
@liverpool8056 liverpool8056 force-pushed the ai-plugin-anthropic-messages-api branch from ef0ec90 to 90f8410 Compare April 1, 2024 03:41
liverpool8056 and others added 4 commits April 8, 2024 14:35
Anthropic.

In this PR, the upstream path of Anthropic for `llm/v1/chat`
route type is changed, pointing to the new API path: `/v1/messages`.

According to the docs of Anthropic, the `text completion` API has been deprecated.

FTI-5770
Co-authored-by: Brent Yarger <brent.yarger@konghq.com>
@tysoekong tysoekong force-pushed the ai-plugin-anthropic-messages-api branch from 90f8410 to 429bfa8 Compare April 8, 2024 13:35
@tysoekong
Copy link
Contributor

#12792 depends on this too. I can finish off the comments here today.

@RobSerafini RobSerafini added this to the 3.7.0 milestone Apr 8, 2024
@kikito kikito merged commit d7f0b16 into master Apr 9, 2024
25 checks passed
@kikito kikito deleted the ai-plugin-anthropic-messages-api branch April 9, 2024 08:46
@team-gateway-bot
Copy link
Collaborator

Successfully created cherry-pick PR for master:

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

Successfully merging this pull request may close these issues.

9 participants