Skip to content

Commit

Permalink
Merge branch 'main' into #10-support-vertex-ai
Browse files Browse the repository at this point in the history
  • Loading branch information
flexchar committed Apr 10, 2024
2 parents d774ee9 + 25709cf commit f82669e
Show file tree
Hide file tree
Showing 33 changed files with 2,182 additions and 128 deletions.
4 changes: 4 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<p align="right">
<strong>English</strong>|<a href="https://github.com/Portkey-AI/gateway/blob/main/CODE_OF_CONDUCT.cn.md">中文</a>
</p>

# Contributor Covenant Code of Conduct

## Our Pledge
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ build
.DS_Store

# Wrangler temp directory
.wrangler
.wrangler

# IntelliJ Idea
.idea
92 changes: 92 additions & 0 deletions CODE_OF_CONDUCT.cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<p align="right">
<a href=".github\CODE_OF_CONDUCT.md">English</a>|<strong>中文</strong>
</p>

# 贡献者公约行为准则

## 我们的承诺

我们作为成员、贡献者和领导者,承诺参与我们的
社区对每个人来说是一个无骚扰的体验,无论他们的年龄、体型、可见或不可见的残疾、种族、性特征、性别认同和表达、经验水平、教育、社会经济地位、国籍、个人外表、种族、宗教或性别认同和取向。

我们承诺以促进开放、欢迎、多元、包容和健康的社区的方式行动和互动。

## 我们的标准

对于有助于我们社区积极环境的行为举例包括:

* 对他人表现出同理心和善意
* 尊重不同的意见、观点和经验
* 优雅地给予并接受建设性反馈
* 承担责任并向受我们错误影响的人道歉,
并从经验中学习
* 关注的不仅是我们作为个体的最佳利益,而是整个社区的最佳利益

不可接受的行为举例包括:

* 使用性语言或图像,以及任何形式的性关注或
进步
* 恶意挑衅、侮辱性或贬损性评论,以及个人或政治攻击
* 公开或私下骚扰
* 在未经明确许可的情况下发布他人的私人信息,如实际地址或电子邮件地址
* 其他在专业环境中可能被合理视为不适当的行为

## 执行责任

社区领导者负责澄清和执行我们可接受行为的标准,并将采取适当和公平的纠正措施以响应他们认为不当、威胁性、冒犯性或有害的任何行为。

社区领导者有权利和责任移除、编辑或拒绝不符合本行为准则的评论、提交、代码、wiki编辑、问题以及其他贡献,并在适当时候沟通调节决策的原因。

## 范围

本行为准则适用于所有社区空间,并且当个人在公共空间正式代表社区时也适用。代表我们的社区的例子包括使用官方电子邮件地址、通过官方社交媒体账户发布,或者在在线或离线活动中担任指定代表。

## 执行

滥用、骚扰或以其他方式不可接受的行为可向负责执行的社区领导者报告到
[email protected]
所有投诉将进行及时和公正的审查和调查。

所有社区领导者都有义务尊重任何事件报告者的隐私和安全。

## 执行指南

社区领导者将根据以下社区影响指南确定他们认为违反本行为准则的任何行为的后果:

### 1. 更正

**社区影响**:使用不当的语言或其他在社区中被认为不专业或不受欢迎的行为。

**后果**:社区领导者将发出私人书面警告,提供违规行为的性质的清晰说明以及解释为什么行为不当。可能会要求公开道歉。

### 2. 警告

**社区影响**:通过单一事件或一系列行动的违规行为。

**后果**:警告连同持续行为的后果。不得与涉事人员进行互动,包括与执行行为准则的人进行未经请求的互动,在指定时间内。这包括避免在社区空间以及像社交媒体这样的外部渠道的互动。违反这些条款可能会导致临时或永久禁止。

### 3. 临时禁止

**社区影响**:严重违反社区标准,包括持续不当行为。

**后果**:在指定时间内禁止与社区进行任何形式的互动或公开沟通。在此期间,不允许与涉事人员进行公开或私下互动,包括与执行行为准则的人进行未经请求的互动。违反这些条款可能会导致永久禁止。

### 4. 永久禁止

**社区影响**:展现违反社区标准的行为模式,包括持续不当行为,骚扰个体,或对个体或群体的侵犯性或贬低性行为。

**后果**:永久禁止在社区内进行任何形式的公共互动。

## 归属

本行为准则改编自 [Contributor Covenant][homepage]
2.0版本,可在
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html 查看。

社区影响指南的灵感来自 [Mozilla 的行为准则执行阶梯](https://github.com/mozilla/diversity)

[homepage]: https://www.contributor-covenant.org

有关本行为准则的常见问题解答,请参见
https://www.contributor-covenant.org/faq。翻译版本可在
https://www.contributor-covenant.org/translations 查看。
40 changes: 40 additions & 0 deletions CONTRIBUTING.cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## 🎉 欢迎
你好,感谢你考虑为Portkey的AI网关做出贡献!无论你是在报告一个bug,建议一个功能,改进文档,还是编写代码,你的贡献对我们来说都是非常宝贵的。

## 🚀 快速开始
1. 在Github上Fork仓库。
2. 将你fork的仓库克隆到你的机器上。
```sh
$ git clone https://github.com/YOUR_USERNAME/gateway.git
```

## 🖋 贡献类型
1. 新的集成:为其他LLM供应商或总体供应商创建集成。
2. Bug修复
3. 增强
4. 文档
5. **Hacktoberfest** 提交!


## 🗓️ Hacktoberfest
[Hacktoberfest 月](https://hacktoberfest.com/)期间,从10月1日到31日,您被接受的 PR 将计入您的 Hacktoberfest 参与度!🚀
✅ 要获得接受,您的 PR 必须被合并、批准或贴上 `hacktoberfest-accepted` 标签。
🧐 记得遵守 [质量标准](https://hacktoberfest.digitalocean.com/resources/qualitystandards)以避免您的 PR 被标记为 `垃圾邮件``无效`
## 🔄 提交 PR
1. 完成您的更改后,通过运行以下命令来格式化和 Lint 您的代码:
```sh
make format; make lint
```
2. 在提交 PR 时,请在标题前添加以下任何一个:
* `provider:` 添加新的 LLM 提供商。
* `integration:` 新的集成。
* `docs:` 新的指南、文档添加等。
* `improvement:` 改进或增强。
* `bug:` 修复错误。
* `hacktoberfest:` Hacktoberfest 贡献。
## 🤔 寻求帮助
遇到问题或有疑问?请毫不犹豫地在我们的 [Discord 社区](https://discord.com/invite/DD7vgKK299) 分享您的疑问或问题 - 这是获得支持和与其他贡献者联系的最快方式。
## 🚧 发布流程
我们尽快进行发布,以确保新功能和修复能快速地到达用户手中。我们遵循无缝的 CI/CD 流水线,以确保代码从开发到生产的平稳过渡。
## 🎊 您的 PR 被合并了!
所有成功的 PR 都会在我们的 [Discord](https://discord.com/invite/DD7vgKK299) 上庆祝,并在发布说明中提及,重大贡献将在我们的 [Twitter](https://twitter.com/PortkeyAI) 上突出显示。请继续关注,未来我们将为贡献者提供更多奖金和礼品!
219 changes: 219 additions & 0 deletions README.cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
<div align="center">
<img src="/docs/images/gateway-border.png" width=350>

<p align="right">
<a href="./README.md">English</a>|<strong>中文</strong>
</p>

# AI Gateway

### 通过一个快速友好的API链接超过100个大型语言模型。

[![License](https://img.shields.io/github/license/Ileriayo/markdown-badges)](./LICENSE)
[![Discord](https://img.shields.io/discord/1143393887742861333)](https://portkey.ai/community)
[![Twitter](https://img.shields.io/twitter/url/https/twitter/follow/portkeyai?style=social&label=Follow%20%40PortkeyAI)](https://twitter.com/portkeyai)
[![npm version](https://badge.fury.io/js/%40portkey-ai%2Fgateway.svg)](https://www.npmjs.com/package/@portkey-ai/gateway)
<!-- ![example workflow](https://github.com/github/docs/actions/workflows/main.yml/badge.svg) -->

</div>
<br><br>

[Portkey的AI网关](https://portkey.ai/features/ai-gateway) 是您的应用程序与托管的大型语言模型(LLMs)之间的接口。它通过统一的API简化了对OpenAI、Anthropic、Mistral、LLama2、Anyscale、Google Gemini等的API请求。

✅ 极速响应(快9.9倍),占用空间极小(安装后约45kb)<br>✅ 跨多个模型、提供商和密钥进行**负载均衡**<br>✅ 通过**备用方案**确保应用程序的稳定性<br>✅ 默认提供具有指数级备用方案的**自动重试**<br>✅ 根据需要插入中间件<br>✅ 经过超过**1000亿令牌**的实战测试<br> <br>

## 入门指南

### 安装

如果您熟悉Node.js和`npx`,您可以在本地运行您的私有AI网关。([其它部署选项](#deploying-ai-gateway))

```
npx @portkey-ai/gateway
```

> 您的AI网关现在运行在 [http://localhost:8787](http://localhost:8787/) 🚀 <br>
### 使用方法

让我们尝试通过AI网关向OpenAI发起一个**聊天**请求:

```
bashCopy codecurl '127.0.0.1:8787/v1/chat/completions' \
-H 'x-portkey-provider: openai' \
-H "Authorization: Bearer $OPENAI_KEY" \
-H 'Content-Type: application/json' \
-d '{"messages": [{"role": "user","content": "Say this is test."}], "max_tokens": 20, "model": "gpt-4"}'
```

[支持的SDK完整列表](#supported-sdks)

<br>


## 支持的AI厂商

|| AI厂商 | 支持 | 流式 | 支持的端点 |
|---|---|---|---|--|
| <img src="docs/images/openai.png" width=25 />| OpenAI ||| `/completions`, `/chat/completions`,`/embeddings`, `/assistants`, `/threads`, `/runs` |
| <img src="docs/images/azure.png" width=25>| Azure OpenAI ||| `/completions`, `/chat/completions`,`/embeddings` |
| <img src="docs/images/anyscale.png" width=25>| Anyscale ||| `/chat/completions` |
| <img src="https://upload.wikimedia.org/wikipedia/commons/2/2d/Google-favicon-2015.png" width=25>| Google Gemini & Palm ||| `/generateMessage`, `/generateText`, `/embedText` |
| <img src="docs/images/anthropic.png" width=25>| Anthropic ||| `/messages`, `/complete` |
| <img src="docs/images/cohere.png" width=25>| Cohere ||| `/generate`, `/embed`, `/rerank` |
| <img src="https://assets-global.website-files.com/64f6f2c0e3f4c5a91c1e823a/654693d569494912cfc0c0d4_favicon.svg" width=25>| Together AI ||| `/chat/completions`, `/completions`, `/inference` |
| <img src="https://www.perplexity.ai/favicon.svg" width=25>| Perplexity ||| `/chat/completions` |
| <img src="https://docs.mistral.ai/img/favicon.ico" width=25>| Mistral ||| `/chat/completions`, `/embeddings` |

> [在这里查看支持的100多个模型的完整列表](https://portkey.ai/docs/welcome/what-is-portkey#ai-providers-supported)
<br />
## 特点

<table>
<tr>
<td>
<h4><a href="https://portkey.ai/docs/product/ai-gateway-streamline-llm-integrations/universal-api">统一API签名</a></h4>
使用OpenAI的API签名连接100多个LLM。AI网关处理请求、响应和错误转换,因此您无需对代码进行任何更改。您可以使用OpenAI SDK本身连接到任何支持的LLM。
<br><br>
<img src="docs/images/openai.png" height=40 />&nbsp;&nbsp;&nbsp;<img src="docs/images/azure.png" height=40 />&nbsp;&nbsp;&nbsp;
<img src="docs/images/anyscale.png" height=40 />&nbsp;&nbsp;&nbsp;
<img src="https://upload.wikimedia.org/wikipedia/commons/2/2d/Google-favicon-2015.png" height=40 />&nbsp;&nbsp;&nbsp;<br><br>
<img src="docs/images/anthropic.png" height=40 />&nbsp;&nbsp;&nbsp;
<img src="docs/images/cohere.png" height=40 />&nbsp;&nbsp;&nbsp;
<img src="https://assets-global.website-files.com/64f6f2c0e3f4c5a91c1e823a/654693d569494912cfc0c0d4_favicon.svg" height=40 />&nbsp;&nbsp;&nbsp;<br><br>
<img src="https://www.perplexity.ai/favicon.svg" height=40 />&nbsp;&nbsp;&nbsp;
<img src="https://docs.mistral.ai/img/favicon.ico" height=40 />&nbsp;&nbsp;&nbsp;
<img src="https://1000logos.net/wp-content/uploads/2021/10/logo-Meta.png" height=40 />
<br><br>
</td>
<td>
<h4><a href="https://portkey.ai/docs/product/ai-gateway-streamline-llm-integrations/fallbacks">备用方案</a></h4>
不要让失败阻止您。备用功能允许您按优先顺序指定语言模型API(LLMs)列表。如果主LLM无法响应或遇到错误,Portkey将自动备用到列表中的下一个LLM,确保您的应用程序的稳定性和可靠性。
<br><br>
<img src="https://framerusercontent.com/images/gmlOW8yeKP2pGuIsObM6gKLzeMI.png" height=200 />
</td>
</tr>
</table>
<table>
<tr>
<td>
<h4><a href="https://portkey.ai/docs/product/ai-gateway-streamline-llm-integrations/automatic-retries">自动重试</a></h4>
临时问题不应该意味着手动重新运行。AI网关可以自动重试失败的请求多达5次。我们采用指数退避策略,间隔重试尝试以防止网络过载。
<br><br>
<img src="https://github.com/roh26it/Rubeus/assets/971978/8a6e653c-94b2-4ba7-95c7-93544ee476b1" height=200 />
</td>
<td>
<h4><a href="https://portkey.ai/docs/product/ai-gateway-streamline-llm-integrations/load-balancing">负载均衡</a></h4>
根据自定义权重在多个API密钥或提供商之间有效分配负载。这确保了您的生成式AI应用程序的高可用性和最佳性能,防止任何单一LLM成为性能瓶颈。
<br><br>
<img src="https://framerusercontent.com/images/6EWuq3FWhqrPe3kKLqVspevi4.png" height=200 />
</td>
</tr>
</table>

<br>

## 配置 AI 网关
AI 网关支持[配置](https://portkey.ai/docs/api-reference/config-object),以实现如**后备(fallbacks)****负载均衡(load balancing)****重试(retries)**等多样化的路由策略。
<br><br>
您可以在通过 `x-portkey-config` 头部进行 OpenAI 调用时使用这些配置
```js
// 使用 OpenAI JS SDK
const client = new OpenAI({
baseURL: "http://127.0.0.1:8787", // 网关 URL
defaultHeaders: {
'x-portkey-config': {.. 你的配置在这里 ..},
}
});
```
<br>
<details><summary>这里有一个示例配置,在回退到 Gemini Pro 之前会重试 OpenAI 请求 5 次</summary>

```js
{
"retry": { "count": 5 },
"strategy": { "mode": "fallback" },
"targets": [{
"provider": "openai",
"api_key": "sk-***"
},{
"provider": "google",
"api_key": "gt5***",
"override_params": {"model": "gemini-pro"}
}]
}
```
</details> <details> <summary>此配置将使得在 2 个 OpenAI 密钥之间实现等量的负载均衡</summary>

```js
{
"strategy": { "mode": "loadbalance" },
"targets": [{
"provider": "openai",
"api_key": "sk-***",
"weight": "0.5"
},{
"provider": "openai",
"api_key": "sk-***",
"weight": "0.5"
}
]
}
```
</details>
了解更多关于配置对象。
<br>

## 支持的SDKs

| 语言 | 支持的SDKs |
|---|---|
| Node.js / JS / TS | [Portkey SDK](https://www.npmjs.com/package/portkey-ai) <br> [OpenAI SDK](https://www.npmjs.com/package/openai) <br> [LangchainJS](https://www.npmjs.com/package/langchain) <br> [LlamaIndex.TS](https://www.npmjs.com/package/llamaindex) |
| Python | [Portkey SDK](https://pypi.org/project/portkey-ai/) <br> [OpenAI SDK](https://pypi.org/project/openai/) <br> [Langchain](https://pypi.org/project/langchain/) <br> [LlamaIndex](https://pypi.org/project/llama-index/) |
| Go | [go-openai](https://github.com/sashabaranov/go-openai) |
| Java | [openai-java](https://github.com/TheoKanning/openai-java) |
| Rust | [async-openai](https://docs.rs/async-openai/latest/async_openai/) |
| Ruby | [ruby-openai](https://github.com/alexrudall/ruby-openai) |

<br>



## 部署 AI 网关

[查看文档](docs/installation-deployments.md)了解如何在本地安装 AI 网关或者在流行的平台上部署它。

<br>

## 路线图

1. 支持更多的提供商。如果缺少某个提供商或 LLM 平台,请[提出功能请求](https://github.com/Portkey-AI/gateway/issues)
2. 增强的负载均衡功能,以优化不同模型和提供商之间的资源使用。
3. 更加健壮的后备和重试策略,以进一步提高请求的可靠性。
4. 增加统一 API 签名的可定制性,以满足更多样化的使用案例。

[💬 在这里参与路线图讨论。](https://github.com/Portkey-AI/gateway/projects/)

<br>

## 贡献

最简单的贡献方式是选择任何带有 `good first issue` 标签的问题 💪。在[这里](/CONTRIBUTING.cn.md.md)阅读贡献指南。

发现 Bug?[在这里提交](https://github.com/Portkey-AI/gateway/issues) | 有功能请求?[在这里提交](https://github.com/Portkey-AI/gateway/issues)

<br>

## 社区

加入我们不断增长的全球社区,寻求帮助,分享想法,讨论 AI。

- 查看我们的官方[博客](https://portkey.ai/blog)
-[Discord](https://portkey.ai/community) 上与我们实时交流
-[Twitter](https://twitter.com/PortkeyAI) 上关注我们
-[LinkedIn](https://www.linkedin.com/company/portkey-ai/) 上与我们建立联系

<!-- - 在 [YouTube](https://www.youtube.com/channel/UCZph50gLNXAh1DpmeX8sBdw) 上访问我们 --> <!-- - 加入我们的 [Dev 社区](https://dev.to/portkeyai) --> <!-- - 在 [Stack Overflow](https://stackoverflow.com/questions/tagged/portkey) 上查看标记为 #portkey 的问题 -->

![Rubeus Social Share (4)](https://github.com/Portkey-AI/gateway/assets/971978/89d6f0af-a95d-4402-b451-14764c40d03f)
Loading

0 comments on commit f82669e

Please sign in to comment.