Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
sugarforever authored Jan 8, 2024
1 parent 888f905 commit 31c72bd
Showing 1 changed file with 45 additions and 101 deletions.
146 changes: 45 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,107 +131,6 @@ curl --location 'https://api.openai.com/v1/chat/completions' \
}'
```

Spark API Gateway的图片理解 `curl` 示例:

```shell
curl --location 'http://localhost:8000/v1/chat/completions' \
-H 'X_APP_ID: 123456' \
-H 'X_API_SECRET: 123456' \
-H 'X_API_KEY: 123456' \
-H "Content-Type: application/json" \
-d '{
"model": "spark-chat-vision",
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://pbs.twimg.com/media/F_c_hrGWcAA3w0p?format=jpg&name=medium"
}
},
{
"type": "text",
"text": "这张图里的标志是什么?"
}
]
}
],
"max_tokens": 300
}'
```

您应该期望类似如下输出:

```json
{
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "这张图里的标志是宝马的logo。"
},
"finish_reason": "stop"
}
],
"usage": {
"question_tokens": 11,
"prompt_tokens": 51,
"completion_tokens": 10,
"total_tokens": 61
},
"version": "v1.1",
"domain": "general"
}
```

## 使用方式

### Docker

### docker-compose

1. 克隆本代码仓库

2. (可选步骤) 复制.env.example为.env,并根据您的星火应用配置,设置APP_ID,API_SECRET,API_KEY。

3. 通过 `docker-compose up` 启动服务。您将看到类似如下输出:

```shell
[+] Running 1/0
✔ Container spark-api-gateway-spark-api-gateway-1 Created 0.0s
Attaching to spark-api-gateway-spark-api-gateway-1
spark-api-gateway-spark-api-gateway-1 | INFO: Started server process [1]
spark-api-gateway-spark-api-gateway-1 | INFO: Waiting for application startup.
spark-api-gateway-spark-api-gateway-1 | INFO: Application startup complete.
spark-api-gateway-spark-api-gateway-1 | INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
```
4. 通过 `curl` 命令测试

```shell
curl --location 'http://localhost:8000/v1/chat/completions' \
--header 'X_APP_ID: 123456' \
--header 'X_API_SECRET: 123456' \
--header 'X_API_KEY: 123456' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{
"role": "user",
"content": "大语言模型的理论基础是什么?"
}
],
"model": "spark-api",
"max_tokens": null,
"stream": false,
"n": 1,
"temperature": 0.7,
"version": "v2.1"
}'
```

#### Spark API Gateway

Spark API Gateway用户可以使用与OpenAI相同的消息体,基于科大讯飞的星火认知大模型实现图片理解。注,使用图片理解功能,请使用模型名 `spark-chat-vision`
Expand Down Expand Up @@ -314,6 +213,51 @@ curl --location 'http://localhost:8000/v1/chat/completions' \
1. HTTP头 `X_APP_ID``X_API_SECRET``X_API_KEY` 用于指定请求中期望使用的讯飞应用的密钥信息。
2. 对于 `X_APP_ID``X_API_SECRET``X_API_KEY` ,在HTTP头中未指定时,将使用环境变量中的值。

## 使用方式

### Docker

### docker-compose

1. 克隆本代码仓库

2. (可选步骤) 复制.env.example为.env,并根据您的星火应用配置,设置APP_ID,API_SECRET,API_KEY。

3. 通过 `docker-compose up` 启动服务。您将看到类似如下输出:

```shell
[+] Running 1/0
✔ Container spark-api-gateway-spark-api-gateway-1 Created 0.0s
Attaching to spark-api-gateway-spark-api-gateway-1
spark-api-gateway-spark-api-gateway-1 | INFO: Started server process [1]
spark-api-gateway-spark-api-gateway-1 | INFO: Waiting for application startup.
spark-api-gateway-spark-api-gateway-1 | INFO: Application startup complete.
spark-api-gateway-spark-api-gateway-1 | INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
```
4. 通过 `curl` 命令测试

```shell
curl --location 'http://localhost:8000/v1/chat/completions' \
--header 'X_APP_ID: 123456' \
--header 'X_API_SECRET: 123456' \
--header 'X_API_KEY: 123456' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{
"role": "user",
"content": "大语言模型的理论基础是什么?"
}
],
"model": "spark-api",
"max_tokens": null,
"stream": false,
"n": 1,
"temperature": 0.7,
"version": "v2.1"
}'
```

## 云端部署

该项目已部署在Vercel平台。大家可以通过[https://sparkai-gateway.vercel.app/v1/chat/completions](https://sparkai-gateway.vercel.app/v1/chat/completions)免费使用。
Expand Down

0 comments on commit 31c72bd

Please sign in to comment.