Skip to content

Commit

Permalink
Commit from m3o/m3o action
Browse files Browse the repository at this point in the history
  • Loading branch information
m3o-actions committed Oct 7, 2023
1 parent 4eefd84 commit 1704d3c
Show file tree
Hide file tree
Showing 30 changed files with 1,254 additions and 1,254 deletions.
130 changes: 65 additions & 65 deletions examples/ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,154 +4,154 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Ai/api](https:

Endpoints:

## Chat
## Edit

Make a request to ChatGPT
Edit or edit prompt/code


[https://m3o.com/ai/api#Chat](https://m3o.com/ai/api#Chat)
[https://m3o.com/ai/api#Edit](https://m3o.com/ai/api#Edit)

```js
const { AiService } = require('m3o/ai');

const aiService = new AiService(process.env.M3O_API_TOKEN)

// Make a request to ChatGPT
async function chatWithChatGpt() {
const rsp = await aiService.chat({
"context": [
{
"prompt": "who is leonardo davinci",
"reply": "Leonardo da Vinci was an Italian polymath during the Renaissance period. He was born in 1452 in Vinci, Italy, and is renowned for his contributions to various fields such as science, engineering, art, and anatomy. Da Vinci's most famous works include the Mona Lisa and The Last Supper. He is often considered one of the greatest artists and thinkers of all time."
},
{
"prompt": "where is he from?",
"reply": "Leonardo da Vinci was from Vinci, a town in Tuscany, Italy."
}
],
"model": "gpt-3.5-turbo",
"prompt": "when did he die?"
// Edit or edit prompt/code
async function editText() {
const rsp = await aiService.edit({
"text": "What day of the wek is it?"
})
console.log(rsp)

}

chatWithChatGpt()
editText()
```
## Stream
## Generate

Stream a response from chatgpt
Generate an image from prompt


[https://m3o.com/ai/api#Stream](https://m3o.com/ai/api#Stream)
[https://m3o.com/ai/api#Generate](https://m3o.com/ai/api#Generate)

```js
const { AiService } = require('m3o/ai');

const aiService = new AiService(process.env.M3O_API_TOKEN)

// Stream a response from chatgpt
async function streamResponseFromChatGpt() {
const rsp = await aiService.stream({
"model": "gpt-3.5-turbo",
"prompt": "write helloworld in node.js"
// Generate an image from prompt
async function generateImage() {
const rsp = await aiService.generate({
"text": "a cat on a ball"
})
rsp.onMessage(msg => {
console.log(msg)
})
console.log(rsp)

}

streamResponseFromChatGpt()
generateImage()
```
## Complete
## Moderate

Make a request to the AI
Moderate hate speech


[https://m3o.com/ai/api#Complete](https://m3o.com/ai/api#Complete)
[https://m3o.com/ai/api#Moderate](https://m3o.com/ai/api#Moderate)

```js
const { AiService } = require('m3o/ai');

const aiService = new AiService(process.env.M3O_API_TOKEN)

// Make a request to the AI
async function completeTheText() {
const rsp = await aiService.complete({
"text": "who is leonardo davinci"
// Moderate hate speech
async function moderateHateSpeech() {
const rsp = await aiService.moderate({
"text": "I want to kill him"
})
console.log(rsp)

}

completeTheText()
moderateHateSpeech()
```
## Edit
## Chat

Edit or edit prompt/code
Make a request to ChatGPT


[https://m3o.com/ai/api#Edit](https://m3o.com/ai/api#Edit)
[https://m3o.com/ai/api#Chat](https://m3o.com/ai/api#Chat)

```js
const { AiService } = require('m3o/ai');

const aiService = new AiService(process.env.M3O_API_TOKEN)

// Edit or edit prompt/code
async function editText() {
const rsp = await aiService.edit({
"text": "What day of the wek is it?"
// Make a request to ChatGPT
async function chatWithChatGpt() {
const rsp = await aiService.chat({
"context": [
{
"prompt": "who is leonardo davinci",
"reply": "Leonardo da Vinci was an Italian polymath during the Renaissance period. He was born in 1452 in Vinci, Italy, and is renowned for his contributions to various fields such as science, engineering, art, and anatomy. Da Vinci's most famous works include the Mona Lisa and The Last Supper. He is often considered one of the greatest artists and thinkers of all time."
},
{
"prompt": "where is he from?",
"reply": "Leonardo da Vinci was from Vinci, a town in Tuscany, Italy."
}
],
"model": "gpt-3.5-turbo",
"prompt": "when did he die?"
})
console.log(rsp)

}

editText()
chatWithChatGpt()
```
## Generate
## Stream

Generate an image from prompt
Stream a response from chatgpt


[https://m3o.com/ai/api#Generate](https://m3o.com/ai/api#Generate)
[https://m3o.com/ai/api#Stream](https://m3o.com/ai/api#Stream)

```js
const { AiService } = require('m3o/ai');

const aiService = new AiService(process.env.M3O_API_TOKEN)

// Generate an image from prompt
async function generateImage() {
const rsp = await aiService.generate({
"text": "a cat on a ball"
// Stream a response from chatgpt
async function streamResponseFromChatGpt() {
const rsp = await aiService.stream({
"model": "gpt-3.5-turbo",
"prompt": "write helloworld in node.js"
})
console.log(rsp)

rsp.onMessage(msg => {
console.log(msg)
})
}

generateImage()
streamResponseFromChatGpt()
```
## Moderate
## Complete

Moderate hate speech
Make a request to the AI


[https://m3o.com/ai/api#Moderate](https://m3o.com/ai/api#Moderate)
[https://m3o.com/ai/api#Complete](https://m3o.com/ai/api#Complete)

```js
const { AiService } = require('m3o/ai');

const aiService = new AiService(process.env.M3O_API_TOKEN)

// Moderate hate speech
async function moderateHateSpeech() {
const rsp = await aiService.moderate({
"text": "I want to kill him"
// Make a request to the AI
async function completeTheText() {
const rsp = await aiService.complete({
"text": "who is leonardo davinci"
})
console.log(rsp)

}

moderateHateSpeech()
completeTheText()
```
Loading

0 comments on commit 1704d3c

Please sign in to comment.