ChatGPT avatar
ChatGPT
Try for free

No credit card required

View all Actors
ChatGPT

ChatGPT

pertosh/chatgpt
Try for free

No credit card required

You can use this Actor to transform scraped results, such as reviews from restaurants, by rephrasing the sentences. Additionally, translation is also supported. You can also use it to generate new website descriptions, keywords, and other similar metadata.

.actor/Dockerfile

1# First, specify the base Docker image.
2# You can see the Docker images from Apify at https://hub.docker.com/r/apify/.
3# You can also use any other image from Docker Hub.
4FROM apify/actor-python:3.9
5
6# Second, copy just requirements.txt into the actor image,
7# since it should be the only file that affects the dependency install in the next step,
8# in order to speed up the build
9COPY requirements.txt ./
10
11# Install the packages specified in requirements.txt,
12# Print the installed Python version, pip version
13# and all installed packages with their versions for debugging
14RUN echo "Python version:" \
15 && python --version \
16 && echo "Pip version:" \
17 && pip --version \
18 && echo "Installing dependencies:" \
19 && pip install -r requirements.txt \
20 && echo "All installed Python packages:" \
21 && pip freeze
22
23# Next, copy the remaining files and directories with the source code.
24# Since we do this after installing the dependencies, quick build will be really fast
25# for most source file changes.
26COPY . ./
27
28# Specify how to launch the source code of your actor.
29# By default, the "python3 -m src" command is run
30CMD ["python3", "-m", "src"]

.actor/README.md

1# Getting started
2
3If you are new to ChatGPT, you can sign up at https://platform.openai.com/signup to get your API-KEY.
4You can use this Actor to transform scraped results, such as reviews from restaurants, by rephrasing the sentences. Additionally, translation is also supported.
5
6
7## ChatGPT 3.5 Turbo Announced!
8
9###ChatGPT API 
10The new Chat API calls gpt-3.5-turbo, the same model used in the ChatGPT product. It’s also our best model for many non-chat use cases; we’ve seen early testers migrate from text-davinci-003 to gpt-3.5-turbo with only a small amount of adjustment needed to their prompts. Learn more about the Chat API in our documentation.
11
12###Pricing
13It’s priced at $0.002 per 1K tokens, which is 10x cheaper than the existing GPT-3.5 models.
14
15###Model updates
16We are constantly improving our Chat models, and want to make these improvements available to developers as well. Developers who use the gpt-3.5-turbo model will always get our recommended stable model, while still having the flexibility to opt for a specific model version.
17 
18For example, today we’re releasing “gpt-3.5-turbo-0301”, which will be supported through at least June 1st, and we’ll update gpt-3.5-turbo to a new stable release in April. The models page will provide switchover updates.

.actor/actor.json

1{
2    "actorSpecification": 1,
3    "name": "chatgpt",
4    "title": "ChatGPT Actor",
5    "description": "The ChatGPT Actor for your integrations.",
6    "version": "0.1",
7    "input": "./input-schema.json",
8    "readme": "./README.md",
9    "dockerfile": "./Dockerfile",
10    "storages": {
11        "dataset": {
12            "actorSpecification": 1,
13            "title": "Question and Answers",
14            "views": {
15                "Answers": {
16                    "title": "Answers",
17                    "transformation": {
18                        "fields": [
19                            "answer"
20                        ]
21                    },
22                    "display": {
23                        "component": "table",
24                        "properties": {
25                            "question": {
26                                "label": "Question",
27                                "format": "textarea"
28                            },
29                            "answer": {
30                                "label": "Answer",
31                                "format": "textarea"
32                            }
33                        }
34                    }
35                }
36            }
37        }
38    }
39}

.actor/input-schema.json

1{
2  "title": "Ask to ChatGPT",
3  "type": "object",
4  "schemaVersion": 1,
5  "properties": {
6    "openai_token": {
7      "title": "OpenAI Token",
8      "type": "string",
9      "description": "You can get an API key from https://platform.openai.com/signup",
10      "editor": "textfield"
11    },
12    "question": {
13      "title": "Question?",
14      "type": "string",
15      "description": "Create one paragraph crime story.",
16      "editor": "textarea"
17    }
18  },
19  "required": ["openai_token", "question"]
20}

src/__init__.py

src/__main__.py

1from .main import main
2
3main()

src/main.py

1import os
2import openai
3from apify_client import ApifyClient
4
5def main():
6    # Initialize the main ApifyClient instance
7    client = ApifyClient(os.environ['APIFY_TOKEN'], api_url=os.environ['APIFY_API_BASE_URL'])
8
9    # Get the resource subclient for working with the default key-value store of the actor
10    default_kv_store_client = client.key_value_store(os.environ['APIFY_DEFAULT_KEY_VALUE_STORE_ID'])
11
12    # Get the value of the actor input and print it
13    actor_input = default_kv_store_client.get_record(os.environ['APIFY_INPUT_KEY'])['value']
14
15    # Structure of input is defined in INPUT_SCHEMA.json
16    openai.api_key = actor_input["openai_token"]
17    question = actor_input["question"]
18    try:
19        response = openai.ChatCompletion.create(
20        model="gpt-3.5-turbo",
21        messages=[
22                {"role": "user", "content": question},
23            ]
24        )
25        answer = response.choices[0]["message"]["content"]
26    except:
27        answer = ""
28    
29    # Get the resource subclient for working with the default dataset of the actor
30    default_dataset_client = client.dataset(os.environ['APIFY_DEFAULT_DATASET_ID'])
31
32    # Structure of output is defined in .actor/actor.json
33    default_dataset_client.push_items([
34        {
35            'question': question,
36            'answer': answer
37        },
38    ])

.dockerignore

1# configurations
2.idea
3
4# crawlee and apify storage folders
5apify_storage
6crawlee_storage
7storage
8
9# installed files
10.venv
11
12# git folder
13.git

.editorconfig

1root = true
2
3[*]
4indent_style = space
5indent_size = 4
6charset = utf-8
7trim_trailing_whitespace = true
8insert_final_newline = true
9end_of_line = lf

.gitignore

1# This file tells Git which files shouldn't be added to source control
2
3.idea
4.DS_Store
5
6apify_storage
7storage
8
9.venv/
10.env/
11__pypackages__
12dist/
13build/
14*.egg-info/
15*.egg
16
17__pycache__
18
19.mypy_cache
20.dmypy.json
21dmypy.json
22
23.pytest_cache
24
25
26.scrapy

requirements.txt

1# Add your dependencies here.
2# See https://pip.pypa.io/en/latest/reference/requirements-file-format/
3# for how to format them
4apify-client~=0.6.0
5openai
Developer
Maintained by Community
Actor metrics
  • 5 monthly users
  • 1 star
  • 100.0% runs succeeded
  • Created in Mar 2023
  • Modified over 1 year ago