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

openai to text-generator.io migration #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

![](https://img.shields.io/github/license/jokenox/Goopt?color=blue) ![](https://img.shields.io/badge/PRs-welcome-orange)

**Search Engine** for a **Procedural Simulation** of the **Web** with **GPT-3**
**Search Engine** for a **Procedural Simulation** of the **Web** with **TextGenerator.io**

</div>

---

> **Web 4.0** could be the propitious evolution for the **procedural web**.

Goopt is an experiment in what the "**procedural web**" could be. This new web will use **procedural content generation** to create varied content, **completely synthetic**, since these are **generated by algorithms** and **artificial intelligence**. For now, the content is only text that is being generated automatically with **GPT-3**, the recent OpenAI model.
Goopt is an experiment in what the "**procedural web**" could be. This new web will use **procedural content generation** to create varied content, **completely synthetic**, since these are **generated by algorithms** and **artificial intelligence**. For now, the content is only text that is being generated automatically with **Text Generator.io**.

Goopt works as if it were a search engine, allowing us to search for any term, obtain related results and access their content. Simulating in this way the experience of browsing the web.

Expand All @@ -28,21 +28,21 @@ The procedural web is based on natural language processing (NLP) and procedural

## Usage

Being an experimental project there is no public access online version, you have to replicate the project yourself as a developer and use your own [OpenAI API Key](https://openai.com/api/).
Being an experimental project there is no public access online version, you have to replicate the project yourself as a developer and use your own [Text Generator API Key](https://text-generator.io/).

### Install

Clone the project:

```bash
$ git clone https://github.com/jokenox/Goopt.git
$ cd Goopt
$ git clone git@github.com:lee101/text-generator-search.git
$ cd text-generator-search
```

Make a file called ```.env.local``` in the root of the project and write a line with your OpenAI API Key to it:

```
REACT_APP_OPENAI_API_KEY=YOUR_API_KEY_HERE
REACT_APP_OPENAI_API_KEY=YOUR_TEXT_GENERATOR_API_KEY_HERE
```

And finally install the project and its dependencies and start it:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@craco/craco": "^6.4.3",
"autoprefixer": "^9",
"cra-template": "1.1.2",
"openai": "3.0.0",
"openai-api": "^1.2.6",
"postcss": "^7",
"react": "^17.0.2",
Expand Down
35 changes: 19 additions & 16 deletions src/contexts/AppContext/AppContext.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { createContext, useState, useRef } from 'react';
import { useNavigate } from "react-router-dom";
import OpenAI from 'openai-api';
import { Configuration, OpenAIApi } from "openai";

import formatResults from '../../utils/formatResults';
import { SearchTemplate, ArticleTemplate } from '../../utils/templates';
Expand All @@ -9,9 +9,12 @@ const AppContext = createContext();

const AppContextProvider = ({ children }) => {
const navigate = useNavigate();
const openai = new OpenAI(process.env.REACT_APP_OPENAI_API_KEY);

const [language, setLanguage] = useState((localStorage.getItem('language') || 'en'));
const configuration = new Configuration({
apiKey: process.env.REACT_APP_OPENAI_API_KEY,
basePath: "https://api.text-generator.io/v1",
});
const openai = new OpenAIApi(configuration);
const [language, setLanguage] = useState((localStorage.getItem('language') || 'en'));
const [searchTerm, setSearchTerm] = useState('');
const [searchResults, setSearchResults] = useState([]);
const [isLoadingResults, setIsLoadingResults] = useState(false);
Expand All @@ -25,12 +28,12 @@ const AppContextProvider = ({ children }) => {

const generateArticleText = async (text) => {
let gptResponse;

setIsLoadingArticle(true);

try {
gptResponse = await openai.complete({
engine: 'text-davinci-001',
gptResponse = await openai.createCompletion({
model: 'text-davinci-001',
prompt: text.trim(),
maxTokens: 500,
temperature: 0.7,
Expand All @@ -41,11 +44,11 @@ const AppContextProvider = ({ children }) => {
n: 1,
stream: false
});

console.log(gptResponse.data.choices[0].text);

setIsLoadingArticle(false);

return gptResponse.data.choices[0].text;
} catch (error) {
alert('There are problems accessing the API');
Expand All @@ -63,8 +66,8 @@ const AppContextProvider = ({ children }) => {
setIsLoadingResults(true);

try {
gptResponse = await openai.complete({
engine: 'text-davinci-001',
gptResponse = await openai.createCompletion({
model: 'text-davinci-001',
prompt: query,
maxTokens: 1000,
temperature: 1,
Expand All @@ -78,7 +81,7 @@ const AppContextProvider = ({ children }) => {
});

//console.log(gptResponse.data.choices[0].text);

lastResultsString.current = gptResponse.data.choices[0].text;

setIsLoadingResults(false);
Expand Down Expand Up @@ -113,7 +116,7 @@ const AppContextProvider = ({ children }) => {
const gooptSearch = (term) => {
if (term.trim().length > 0) {
navigate('/results?search=' + term.trim());

getResults(term.trim());
}
};
Expand All @@ -130,7 +133,7 @@ const AppContextProvider = ({ children }) => {
switch (lang) {
case 'en':
return SearchTemplate.en;

case 'es':
return SearchTemplate.es;

Expand All @@ -146,7 +149,7 @@ const AppContextProvider = ({ children }) => {
switch (lang) {
case 'en':
return ArticleTemplate.en;

case 'es':
return ArticleTemplate.es;

Expand Down
31 changes: 30 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,13 @@ axios@^0.21.1:
dependencies:
follow-redirects "^1.14.0"

axios@^0.26.0:
version "0.26.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
dependencies:
follow-redirects "^1.14.8"

axobject-query@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
Expand Down Expand Up @@ -3387,7 +3394,7 @@ colorette@^1.2.1:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==

combined-stream@^1.0.6, combined-stream@~1.0.6:
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
Expand Down Expand Up @@ -5139,6 +5146,11 @@ follow-redirects@^1.14.0:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.6.tgz#8cfb281bbc035b3c067d6cd975b0f6ade6e855cd"
integrity sha512-fhUl5EwSJbbl8AR+uYL2KQDxLkdSjZGR36xy46AO7cOMTrCMON6Sa28FmAnC2tRTDbd/Uuzz3aJBv7EBN7JH8A==

follow-redirects@^1.14.8:
version "1.15.1"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5"
integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==

for-in@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
Expand All @@ -5162,6 +5174,15 @@ fork-ts-checker-webpack-plugin@4.1.6:
tapable "^1.0.0"
worker-rpc "^0.1.0"

form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
Expand Down Expand Up @@ -7866,6 +7887,14 @@ openai-api@^1.2.6:
axios "^0.21.1"
dotenv "^8.2.0"

openai@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/openai/-/openai-3.0.0.tgz#0816f1d72ee37820c9ff14d93d597431489fec37"
integrity sha512-YNAPZKzBfE6MnR5Ro/z3uKbg7T3F3W1FoTCtYheKRdEjZeheMX49QYFeL990gBFAhuGziEZCUdhnNT+eIrxX/Q==
dependencies:
axios "^0.26.0"
form-data "^4.0.0"

opn@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/opn/-/opn-5.5.0.tgz#fc7164fab56d235904c51c3b27da6758ca3b9bfc"
Expand Down