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 Aug 30, 2023
1 parent f3b0d21 commit 085261a
Show file tree
Hide file tree
Showing 35 changed files with 1,402 additions and 1,402 deletions.
118 changes: 59 additions & 59 deletions examples/ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,65 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Ai/api](https:

Endpoints:

## Chat

Make a request to ChatGPT


[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)

// 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)

}

chatWithChatGpt()
```
## Stream

Stream a response from chatgpt


[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)

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

streamResponseFromChatGpt()
```
## Complete

Make a request to the AI
Expand Down Expand Up @@ -96,62 +155,3 @@ async function moderateHateSpeech() {

moderateHateSpeech()
```
## Chat

Make a request to ChatGPT


[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)

// 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)

}

chatWithChatGpt()
```
## Stream

Stream a response from chatgpt


[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)

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

streamResponseFromChatGpt()
```
Loading

0 comments on commit 085261a

Please sign in to comment.