chat1
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Artificial Intelligence
Introduced first in SolidGeometry 5.5, Creation date: 2024-11-11, Last change: 2025-08-19
single line communication with openAI's chat gpt
Description
chat1 - sends a single line to openAI API without history
chat - opens a single line conversation using the chat history
chatGPT - opens the chatGPT web browser interface
chatweb - opens the chatGPT web browser interface
Uses OpenAIrequest. Make sure that your openAI API secret key is stored in a file called "OPENAI_API_KEY.env"
See Also: OpenAIcostAPI
, chat
, chatweb
, chatGPT
, OpenAIrequest
Example Illustration
Syntax
y=chat1([])
Output Parameter
y: | | Response from openAI when using your paid openAI API account |
Examples
% Difference between chat and chath
chat1 what is the age of joe biden
chat1 what ist the age of his wife
chat what is the age of joe biden
chat what ist the age of his wife
Copyright 2024-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, chat1, is designed to interact with OpenAI's API by sending a single line of text and receiving a response. It is part of a library related to artificial intelligence and was developed by Tim Lueth.
Input Parameters
varargin: This allows the function to accept a variable number of input arguments. These arguments are expected to be strings that will be joined and sent to the OpenAI API.
Algorithm Steps
- The function begins by joining all input arguments into a single string using
join(elem2cell(varargin{:})).
- If no arguments are provided (
nargin==0), the function calls chathist and exits. This is a fallback mechanism when no input is given.
- If arguments are provided, the function sends the joined string to the OpenAI API using
OpenAIrequest(x) and stores the response in y.
- The response from the API is trimmed of any leading or trailing whitespace using
strtrim.
- If there is no output argument specified (
nargout==0), the response is formatted to have a maximum line length of 80 characters using strbreaklines(y,80).
Output
y: The response from the OpenAI API, formatted as specified.
Additional Information
The function relies on an external function OpenAIrequest to handle the API communication. It assumes that the OpenAI API key is stored in a file named OPENAI_API_KEY.env.
Algorithm explaination created using ChatGPT on 2025-08-19 06:57. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21