Last change of this documentation page: 2024-11-09 of SolidGeometry 5.5
OpenAIrequest(Userinp,AIhistory,RequestHistory)- returns the openAI Chat anwer for a single question

OpenAIrequest(Userinp,AIhistory,RequestHistory)% OpenAIrequest(Userinp,AIhistory,RequestHistory) - returns the openAI Chat anwer for a single question
% (by Tim Lueth, VLFL-Lib, 2024-NOV-09 as class: ARTIFICIAL INTELLIGENCE)
%
% if called without an input the fnctn will establish a conversation
% until "Cntr-C" is used (Status of: 2024-11-09)
%
% Introduced first in SolidGeometry 5.5
%
% See also: jarvisChatSGLib, json2matlab, jsonplansequence, OpenAIcostAPI
%
% [AIansw,AIhistory,RequestHistory]=OpenAIrequest([Userinp,AIhistory,Requ
% estHistory])
% === INPUT PARAMETERS ===
% Userinp: A charcter chain as input; default is empty
% AIhistory: the struct that is used by addResponseMessage, to maintain a
% chat history; default ist empty
% RequestHistory: a cell list that describes the history of Userinp in
% case of a conversation
% === OUTPUT RESULTS ======
% AIansw: Answer to the last Userinp
% AIhistory: AI history of response messages if a conversion is planned
% RequestHistory: The history of Userinp if a a conversion is planned
%
% EXAMPLE:
% OpenAIrequest('What is the core diameter of a DIN13 M4 nut') % return a text answer
% OpenAIrequest % start a conversation loop
%
% See also: jarvisChatSGLib, json2matlab, jsonplansequence, OpenAIcostAPI
%
%
% Copyright 2024 Tim C. Lueth

jsonplansequence(Userinp,AIchat,AIhistory)- returns a plan step sequence from a single chat task

jsonplansequence(Userinp,AIchat,AIhistory)% jsonplansequence(Userinp,AIchat,AIhistory) - returns a plan step sequence from a single chat task
% (by Tim Lueth, VLFL-Lib, 2024-NOV-07 as class: ARTIFICIAL INTELLIGENCE)
%
% The original openAI/matlab interface is able to create sequences of
% tasks, but the argument references are faulty, which is why a complex
% task has to be explicitly broken down into a sequence and then
% processed as a series of requests. (Status of: 2024-11-09)
%
% Introduced first in SolidGeometry 5.5
%
% See also: jarvisChatSGLib, json2matlab, OpenAIrequest, OpenAIcostAPI
%
% [Userscript,AIhistory]=jsonplansequence(Userinp,AIchat,AIhistory)
% === INPUT PARAMETERS ===
% Userinp: User input as one string
% AIchat: AIchat
% AIhistory: AI History
% === OUTPUT RESULTS ======
% Userscript: plan sequence as single string
% AIhistory: modified AI History
%
% EXAMPLE:
% jarvisChatSGLib
% what is typical diameter and height of coffe mug, create zylinder with this dimensions
%
% See also: jarvisChatSGLib, json2matlab, OpenAIrequest, OpenAIcostAPI
%
%
% Copyright 2024 Tim C. Lueth

json2matlab(SGfuncname,SGfuncargs,Variables)- convertes a json reaction of an openAI-Chat into a matlab code line

json2matlab(SGfuncname,SGfuncargs,Variables)% json2matlab(SGfuncname,SGfuncargs,Variables) - convertes a json reaction of an openAI-Chat into a matlab code line
% (by Tim Lueth, VLFL-Lib, 2024-NOV-06 as class: ARTIFICIAL INTELLIGENCE)
%
% Robin Schregle used a switch structure with matlab code to implement
% the SG-Lib fnctn calls. This requires the maintenance of the json code
% for fnctns f..... and in addition the code for the fnctn calls in the
% matlab code (see SGlib_Fnctn_Calling_OpenAI). Tim Lueth's solution uses
% the JSON code of the answer directly to create the matlab code to be
% executed by eval.
% This fnctn is this decoding and evaluation of the matlab code,
% extracted from the json answer.
%
%
% % AIchat = openAIChat("gpt-4o",Temperature=0,
% Tools=[f0,f1,f2,f3,f4,f5]); % SGlib fnctns f0..f5 as JSON
% % AIhistory = messageHistory();
% % AIhistory = addUserMessage(AIhistory, Userinp); % Add a user
% request as string
% % [AItextansw, AIexecplan] = generate(AIchat, AIhistory); % generate
% the chat answer
% % AIhistory = addResponseMessage(AIhistory, AIexecplan); % add the
% answer to the chat history
% % SGlibcalls = AIexecplan.tool_calls; % find the
% appropriate SGlib calls in the answer
% % SGfuncname = SGlibcalls(k).fnctn.name; % can be an
% array therefor use index k
% % SGfuncargs = SGlibcalls(k).fnctn.arguments; % can be an
% array therefor use index k
% % SGresult=
% % SGresultname = SGfuncname + string(length(AIhistory.Messages)); % One
% possibility for naming
% % Variables.(SGresultname) = SGResult; % create a
% list of results for referencing
%
%
% (Status of: 2024-11-09)
%
% Introduced first in SolidGeometry 5.5
%
% See also: jarvisChatSGLib, jsonplansequence, OpenAIrequest,
% OpenAIcostAPI
%
% [SGansw,cmdstr]=json2matlab(SGfuncname,SGfuncargs,Variables)
% === INPUT PARAMETERS ===
% SGfuncname: Name of the current SG fnctn extracted from the AIexecplan
% SGfuncargs: Struct containing the parameternames as fields and expected
% values extracted from the AIexecplan
% Variables: History of already used SGresults as cell list of
% SGfuncnames with the call number
% === OUTPUT RESULTS ======
% SGansw: evaluated result from the matlab code extracted from the json
% answer.
% cmdstr: the command string executed within json2matlab to create res
%
% See also: jarvisChatSGLib, jsonplansequence, OpenAIrequest,
% OpenAIcostAPI
%
%
% Copyright 2024 Tim C. Lueth

OpenAIcostAPI- opens the web page of company openAI to show the users expenses

OpenAIcostAPI% OpenAIcostAPI - opens the web page of company openAI to show the users expenses
% (by Robin Schregle & Tim Lueth, VLFL-Lib, 2024-NOV-04 as class:
% ARTIFICIAL INTELLIGENCE)
%
% 1) Download from Gitgub (see link below) the Large Language Model (LMM)
% fnctns of Matlab and store the files in a folder in your Matlab code
% directory using the
% folder name [pwd filesep 'llms-with-matlab']
% 2) add this path to your main directory using
% addpath([pwd filesep 'llms-with-matlab'])
% 3) create an API account at openAI
% you have to start an account store your credit card info (see link
% below)
% 4) create an environment ascii file with name "OPENAI_API_KEY.env" that
% contains a single line
% OPENAI_API_KEY=""
% 5) load this environmentfile by
% loadenv("OPENAI_API_KEY.env")
% 6) set the model to
% modelName = "gpt-4o";
% (Status of: 2024-11-09)
%
% Introduced first in SolidGeometry 5.5
%
% See also: jarvisChatSGLib, json2matlab, jsonplansequence, OpenAIrequest
%
% OpenAIcostAPI
%
% Additional Hyperlinks:
% Matlab's LLM at Github, OpenAI API-Key Generation
%
% EXAMPLE:
% OpenAIcostAPI
%
% See also: jarvisChatSGLib, json2matlab, jsonplansequence, OpenAIrequest
%
%
% Copyright 2024 Tim C. Lueth

jarvisChatSGLib- this fnct/script is a ChatGPT based control of the SGLib and defines the development start of SGLib 6.0

jarvisChatSGLib% jarvisChatSGLib - this fnct/script is a ChatGPT based control of the SGLib and defines the development start of SGLib 6.0
% (by Robin Schregle & Tim Lueth, VLFL-Lib, 2024-NOV-04 as class:
% ARTIFICIAL INTELLIGENCE)
%
% At the end of October 2024, Tim Lueth encouraged his team to work with
% the Matlab/ChatGPT API interface, and Felix Pancheri and Robin Schregle
% started to use it. Robin Schregle implemented a first version called
% “SGlib_Fnctn_Calling_OpenAI”. This fnctn “jarvisChatSGLib” is an
% improved version of “SGlib_Fnctn_Calling_OpenAI” to achieve similar
% results to the already existing SGLib fnctn “jarvis” from January 2022,
% which was programmed by Tim Lueth on the recommendation of Franz
% Irlinger.The original fnctn "jarvis" was based on the use von Apple's
% Siri and the SGLib's parser "siri2jarvis"
% 1) Download from Gitgub (see link below) the Large Language Model (LMM)
% fnctns of Matlab and store the files in a folder in your Matlab code
% directory using the
% folder name [pwd filesep 'llms-with-matlab']
% 2) add this path to your main directory using
% addpath([pwd filesep 'llms-with-matlab'])
% 3) create an API account at openAI
% you have to start an account store your credit card info (see link
% below)
% 4) create an environment ascii file with name "OPENAI_API_KEY.env" that
% contains a single line
% OPENAI_API_KEY=""
% 5) load this environmentfile by
% loadenv("OPENAI_API_KEY.env")
% 6) set the model to
% modelName = "gpt-4o";
% (Status of: 2024-11-09)
%
% Introduced first in SolidGeometry 5.5
%
% See also: chat, jarvis, SGlib_Fnctn_Calling_OpenAI, OpenAIcostAPI
%
% jarvisChatSGLib
%
% Additional Hyperlinks:
% Matlab's LLM at Github, OpenAI API-Key Generation
%
% EXAMPLE:
% jarvisChatSGLib
%
% See also: chat, jarvis, SGlib_Fnctn_Calling_OpenAI, OpenAIcostAPI
%
%
% Copyright 2024 Tim C. Lueth
RapidWeaver Icon

Last Change Oct 2023 for SG-Lib 5.3