OpenAI
This component uses OpenAI’s advanced language models to create text based on your instructions. You can customize the output by adjusting various settings. It’s perfect for tasks like writing summaries, creating different kinds of content, or answering questions.
Relationship with OpenAI API
This component connects directly to the OpenAI API, which provides the underlying language models. You’ll need to provide your OpenAI API credentials to use this component.
Inputs
- Max Tokens: This sets the maximum length of the generated text. A higher number means longer text. Set to 0 for no limit (though be mindful of costs!). The maximum allowed is 128,000.
- Model Kwargs: (Advanced) Allows you to fine-tune the model’s behavior using additional technical parameters. Leave this blank unless you have specific needs.
- JSON Mode: If turned on, the output will always be in JSON format, regardless of other settings. Useful for structured data.
- Schema: (Advanced) Defines the structure of the JSON output. You need to include the word “JSON” in your prompt to activate this.
- Model Name: Choose the OpenAI language model you want to use from a list of available options. The default is usually the best option to start with.
- OpenAI API Base: (Advanced) The web address of the OpenAI API. Usually, you don’t need to change this. It’s set to
https://api.openai.com/v1
by default. - Temperature: Controls how creative the generated text is. A lower value (e.g., 0.1) makes the text more focused and predictable, while a higher value (e.g., 0.8) makes it more creative and unpredictable. The default is 0.1.
- Seed: (Advanced) Use this number to get the same results each time you run the component with the same inputs. This is useful for testing and reproducibility. The default is 1.
- Credential: Select your OpenAI API key from the list of saved credentials. This is essential for accessing OpenAI’s services.
Outputs
The component doesn’t have explicit outputs in the traditional sense. Instead, it generates text based on your input and sends it to the next component in your Nappai workflow. The text can be plain text or JSON, depending on your settings.
Usage Example
Let’s say you want to summarize a news article. You would:
- Feed the article text to the OpenAI component.
- Set the
Model Name
to a suitable model (e.g.,text-davinci-003
). - Set
Max Tokens
to a reasonable number (e.g., 150) for a concise summary. - The OpenAI component will generate a summary, which will then be passed to the next component in your workflow (e.g., a display component to show the summary).
Templates
This component is used in many Nappai templates, including: Vector Store RAG
, Complex Agent
, Blog Writer
, Document QA
, Hierarchical Tasks Agent
, Sequential Tasks Agent
, CV Scorer
, CV Match
, Stock chat
, URL content to X
, Document Insights
, Create Questions and Answers from Documents
, Reasoning Prompts
, TicketToJSON
, Load Cloud DatA
, Audio and Video Transcriber
, Eurocup 2024
, Chat with GMail
, Prompt Chaining
, Search Tools
, Book Recommendator
, Cuisine Recommendator
, Ask your Database
, SqlAgent
.
Related Components
Many components work well with the OpenAI component. For example:
- Summarizer: Use this to shorten long texts before feeding them to the OpenAI component.
- Explain SQL results: Use this to get human-readable explanations of complex database queries.
- SQL Query Constructor: Create SQL queries to retrieve data for the OpenAI component to process.
Tips and Best Practices
- Start with the default settings. Adjust parameters gradually to fine-tune the output.
- Use clear and concise prompts for the best results.
- Be mindful of the
Max Tokens
setting to avoid exceeding OpenAI’s usage limits and incurring unexpected costs. - Experiment with different model names to find the best one for your task.
Security Considerations
Protect your OpenAI API key. Do not share it publicly or expose it in your Nappai workflow’s code. Use Nappai’s secure credential management system to store your API key.