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

adding blueprint examples for remote inference #1155

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
### Cohere connector blueprint example for embedding:

#### this blueprint is created from Cohere doc: https://docs.cohere.com/reference/embed

```json
POST /_plugins/_ml/connectors/_create
{
"name": "<YOUR MODEL NAME>",
"description": "<YOUR MODEL DESCRIPTION>",
"version": "<YOUR MODEL VERSION>",
"protocol": "http",
"credential": {
"cohere_key": "<PLEASE ADD YOUR Cohere API KEY HERE>"
},
"actions": [
{
"action_type": "predict",
"method": "POST",
"url": "https://api.cohere.ai/v1/embed",
"headers": {
"Authorization": "Bearer ${credential.cohere_key}"
},
"request_body": "{ \"texts\": ${parameters.prompt}, \"truncate\": \"END\" }"
}
]
}
```
#### Sample response
```json
{
"connector_id": "XU5UiokBpXT9icfOM0vt"
}
```


### Corresponding Predict request example:

```json
POST /_plugins/_ml/models/<ENTER MODEL ID HERE>/_predict
{
"parameters": {
"prompt": ["Say this is a test"]
}
}
```

#### Sample response
```json
{
"inference_results": [
{
"output": [
{
"name": "response",
"dataAsMap": {
"id": "39097276-d926-4ca1-92e6-d54a3c969d42",
"texts": [
"Say this is a test"
],
"embeddings": [
[
-0.76953125,
-0.12731934,
-0.52246094,
-1.2714844,
........
........
]
],
"meta": {
"api_version": {
"version": "1"
}
}
}
}
]
}
]
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
### Cohere connector blueprint example for rerank:

#### this blueprint is created from Cohere doc: https://docs.cohere.com/reference/rerank-1

```json
POST /_plugins/_ml/connectors/_create
{
"name": "<YOUR MODEL NAME>",
"description": "<YOUR MODEL DESCRIPTION>",
"version": "<YOUR MODEL VERSION>",
"protocol": "http",
"parameters": {
"endpoint": "api.cohere.ai",
"model": "rerank-english-v2.0",
"top_n": 3,
"return_documents": true
},
"credential": {
"api_key": "<PLEASE ADD YOUR Cohere API KEY HERE>"
},
"actions": [
{
"action_type": "predict",
"method": "POST",
"url": "https://${parameters.endpoint}/v1/rerank",
"headers": {
"Authorization": "Bearer ${credential.api_key}"
},
"request_body": "{ \"model\": \"${parameters.model}\", \"query\" : \"${parameters.query}\", \"documents\" : ${parameters.documents}, \"top_n\" : ${parameters.top_n}, \"return_documents\" : ${parameters.return_documents} }"
}
]
}
```
#### Sample response
```json
{
"connector_id": "XU5UiokBpXT9icfOM0vt"
}
```


### Corresponding Predict request example:

```json
POST /_plugins/_ml/models/<ENTER MODEL ID HERE>/_predict
{
"parameters": {
"query": "What is the capital of the United States?",
"documents": [
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
"Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."
]
}
}
```

#### Sample response
```json
{
"inference_results": [
{
"output": [
{
"name": "response",
"dataAsMap": {
"id": "c536e12e-c7fe-414c-9a00-d1c5c6757b34",
"results": [
{
"document": {
"text": "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district."
},
"index": 2,
"relevance_score": 0.98005307
},
{
"document": {
"text": "Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."
},
"index": 3,
"relevance_score": 0.27904198
},
{
"document": {
"text": "Carson City is the capital city of the American state of Nevada."
},
"index": 0,
"relevance_score": 0.10194652
}
],
"meta": {
"api_version": {
"version": "1"
}
}
}
}
]
}
]
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
### OpenAI connector blueprint example for chat:
Copy link
Collaborator

@ylwu-amzn ylwu-amzn Jul 25, 2023

Choose a reason for hiding this comment

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

Explain that this blueprint is created from OpenAI doc,
and example is from OpenAI doc https://platform.openai.com/docs/api-reference/chat?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for other examples, we should use the exact same example from OpenAI and Cohere official document. And we should put their doc link here so community user can refer to .


#### this blueprint is created from OpenAI doc: https://platform.openai.com/docs/api-reference/chat
```json
POST /_plugins/_ml/connectors/_create
{
"name": "<YOUR MODEL NAME>",
"description": "<YOUR MODEL DESCRIPTION>",
"version": "<YOUR MODEL VERSION>",
"protocol": "http",
"parameters": {
"endpoint": "api.openai.com",
"model": "gpt-3.5-turbo"
},
"credential": {
"openAI_key": "<PLEASE ADD YOUR OPENAI API KEY HERE>"
},
"actions": [
{
"action_type": "predict",
"method": "POST",
"url": "https://${parameters.endpoint}/v1/chat/completions",
"headers": {
"Authorization": "Bearer ${credential.openAI_key}"
},
"request_body": "{ \"model\": \"${parameters.model}\", \"messages\": ${parameters.messages} }"
}
]
}
```

#### Sample response
```json
{
"connector_id": "XU5UiokBpXT9icfOM0vt"
}
```

### Corresponding Predict request example:

```json
POST /_plugins/_ml/models/<ENTER MODEL ID HERE>/_predict
{
"parameters": {
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}
}
```

#### Sample response
```json
{
"inference_results": [
{
"output": [
{
"name": "response",
"dataAsMap": {
"id": "chatcmpl-7g0QJH6nuFW94l8tDkJzxm0ntaPNd",
"object": "chat.completion",
"created": 1690245759,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 19,
"completion_tokens": 9,
"total_tokens": 28
}
}
}
]
}
]
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
### OpenAI connector blueprint example for completion:

#### this blueprint is created from OpenAI doc: https://platform.openai.com/docs/api-reference/completions

```json
POST /_plugins/_ml/connectors/_create
{
"name": "<YOUR MODEL NAME>",
"description": "<YOUR MODEL DESCRIPTION>",
"version": "<YOUR MODEL VERSION>",
"protocol": "http",
"parameters": {
"endpoint": "api.openai.com",
"max_tokens": 7,
"temperature": 0,
"model": "text-davinci-003"
},
"credential": {
"openAI_key": "<PLEASE ADD YOUR OPENAI API KEY HERE>"
},
"actions": [
{
"action_type": "predict",
"method": "POST",
"url": "https://${parameters.endpoint}/v1/completions",
"headers": {
"Authorization": "Bearer ${credential.openAI_key}"
},
"request_body": "{ \"model\": \"${parameters.model}\", \"prompt\": \"${parameters.prompt}\", \"max_tokens\": ${parameters.max_tokens}, \"temperature\": ${parameters.temperature} }"
}
]
}
```

#### Sample response
```json
{
"connector_id": "XU5UiokBpXT9icfOM0vt"
}
```

### Corresponding Predict request example:

```json
POST /_plugins/_ml/models/<ENTER MODEL ID HERE>/_predict
{
"parameters": {
"prompt": ["Say this is a test"]
}
}
```

#### Sample response
```json
{
"inference_results": [
{
"output": [
{
"name": "response",
"dataAsMap": {
"id": "cmpl-7g0NPOJd8IvXTdhecdlR0VGfrLMWE",
"object": "text_completion",
"created": 1690245579,
"model": "text-davinci-003",
"choices": [
{
"text": """

This is indeed a test""",
"index": 0,
"finish_reason": "length"
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 7,
"total_tokens": 12
}
}
}
]
}
]
}
```
Loading