Skip to content

Commit

Permalink
update: OpenAi API
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTeida committed Jan 20, 2024
1 parent eb18f96 commit 4fc61b8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Description soon

* React
* React Router
* OpenAI API
* JS
* Sass
* Joy UI
* OpenAI API
* Material Icons
2 changes: 0 additions & 2 deletions src/components/Input.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {Button, Card, CardActions, CardContent, Input as JoyInput} from "@mui/joy";
import EditIcon from '@mui/icons-material/Edit';
import SendIcon from '@mui/icons-material/Send';
import TouchAppIcon from '@mui/icons-material/TouchApp';
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';

function Input() {
Expand Down
4 changes: 3 additions & 1 deletion src/components/Output.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Box, Card, Sheet, Stack, Typography} from "@mui/joy";
import {sendMessage} from '../lib/OpenAi.jsx'

function Output() {

return (
<Card sx={{
display: 'flex',
Expand Down Expand Up @@ -35,7 +37,7 @@ function Output() {
</Stack>
<Sheet variant="outlined" sx={{p: 1, borderRadius: "sm", backgroundColor: "background.level1"}}>
<Typography component="p" fontSize={{xs: "sm", sm: "md"}} sx={{ wordBreak: "break-word" }}>
MessageeeeeeeeMessageeeeeeeeMessageeeeeeeeMessageeeeeeee
Messageeeeeeee
</Typography>
</Sheet>
</Box>
Expand Down
18 changes: 16 additions & 2 deletions src/lib/OpenAi.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import {Configuration, OpenAIApi} from 'openai'

const configuration = new Configuration() ({
const configuration = new Configuration({
apiKey: import.meta.env.VITE_OPENAI_API_KEY
})
})
const openai = new OpenAIApi(configuration)

export async function sendMessage(message) {
const response = await openai.createCompletion({
model: 'text-davinci-002',
prompt: message,
temperature: 0.5, // how creative OpenAi should be (0 - 1)
max_tokens: 400,
frequency_penalty: 0.01, // parametr frequency_penalty pozwala sterować różnorodnością generowanego tekstu przez model GPT, modyfikując rozkład prawdopodobieństwa, aby rzadziej generować słowa, które model częściej widział podczas treningu.
presense_penalty: 0.01, // parametr presence_penalty zniechęca model GPT do generowania słów, które już wystąpiły w tekście wejściowym (input), poprzez modyfikację rozkładu prawdopodobieństwa.
top_p: 1, // shrinks or grows the “pool” of available tokens to choose from, the domain to select over. 1=big pool, 0=small pool
})
return response.data.choices[0].text
}

0 comments on commit 4fc61b8

Please sign in to comment.