-
Notifications
You must be signed in to change notification settings - Fork 138
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
docs/remote_inference_blueprints/cohere_connector_embedding_blueprint.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` |
103 changes: 103 additions & 0 deletions
103
docs/remote_inference_blueprints/cohere_connector_rerank_blueprint.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` |
93 changes: 93 additions & 0 deletions
93
docs/remote_inference_blueprints/open_ai_connector_chat_blueprint.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
### OpenAI connector blueprint example for chat: | ||
|
||
#### 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 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` |
86 changes: 86 additions & 0 deletions
86
docs/remote_inference_blueprints/open_ai_connector_completion_blueprint.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 .