You can communicate with ChatGPT using this Clarion code and integrate it into your software. However, please remember that the application requires Nettalk and StringTheory templates developed by Capesoft to function properly. Additionally, please be reminded that you need to generate an API key from the following link: OpenAI Platform and input this key into the software. I hope this is helpful.
ChatGPT.zip (3.0 MB)
Nice âGelen cevapâ translate to Incoming replyâŚ
The inclusion of LLMâs in applications going forward where the app can be recognised and driven by AI is surely next.
And products with this in mind where its internal structures are command friendly is surely the way forward. It might be a decade away but the pace of change is always surprising and we changed to command drive a decade ago instead of GUI operator driven.
Nice demo of using Cape softs web client in a clarion app.
Thanks for thatâŚ
Philosophically speaking; everything began on the day when writing was invented. The knowledge accumulated over thousands of years is now being presented to humanity, blended according to our needs. The momentum of progress with artificial intelligence will elevate this further and make the growth of the human population unnecessary. More importantly, we are no longer limited by a human lifespan.
I hope the tool serves your needs.
Indeed may save the planet!
MS office Open AI Turbo outâŚ
Surely Office suite will one day come with Office AI 64 Bit engine that you run locally on your home business server creating a private data model that sync to the cloud.
You wont have to buy a separate license and it will come in the bundle.
It will surely become an operating system tool (not an office part) one day, but until then, it will help you to use it in your applications
Hi Nikola,
This line doesnât seem too long. If you give me your AnyDesk ID, I can connect remotely to understand your issue and suggest a solution.
Regards,
Serhat
check this
looks like you need just double some chars
You need to double up the { characters.
You may need to double up the < character, if the character following is numeric.
I was about to say the same as Rick and Guennadi about doubling up â{â.
It depends which version of Clarion you have as some of the recent builds were more âfussyâ or âstrictâ about getting strings correct.
Anyway change that string to be
Loc:PostString='{{"model": "gpt-3.5-turbo","messages": [{{"role": "user", "content": "'&st.GetValue()&'"}],"temperature": 0.7}'
in fact looking at that code there appears to be a memory leak of the value returned from st.AnsiToUtf8 so suggest instead of:
ReformatQuestion ROUTINE
st.SetValue(CLIP(MyQuestion))
st.JsonEncode()
Loc:PostString='{"model": "gpt-3.5-turbo","messages": [{"role": "user", "content": "'&st.GetValue()&'"}],"temperature": 0.7}'
Loc:PostString=st.AnsiToUtf8(Loc:PostString,uz#,st:CP_ISO_8859_9)
I suggest you instead try something like:
ReformatQuestion ROUTINE
data
myStr &string
code
st.SetValue(MyQuestion,st:clip)
st.JsonEncode()
st.prepend('{{"model": "gpt-3.5-turbo","messages": [{{"role": "user", "content": "')
st.append('"}],"temperature": 0.7}')
myStr &= st.AnsiToUtf8(st.getValuePtr(),uz#,st:CP_ISO_8859_9)
Loc:PostString=myStr
dispose(myStr)
there is actually a âneaterâ way to do this so you donât have to define myStr or remember to dispose it, cunningly using st._stealValue:
ReformatQuestion ROUTINE
st.SetValue(MyQuestion,st:clip)
st.JsonEncode()
st.prepend('{{"model": "gpt-3.5-turbo","messages": [{{"role": "user", "content": "')
st.append('"}],"temperature": 0.7}')
st._StealValue(st.AnsiToUtf8(st.getValuePtr(),uz#,st:CP_ISO_8859_9))
Loc:PostString=st.getValue()
the fact that â_stealValueâ has an underscore at the front tells you it is really an internal method and not documented, but it is really handy for situations like this as it means you donât run the risk of a memory leak (as you donât have to dispose the returned value).
in fact I notice a similar memory leak in ReformatAnswer so again, instead of:
ReformatAnswer ROUTINE
ChatGPTResponse=st.Utf8ToAnsi(Loc:GetString,uz#,st:CP_ISO_8859_9)
baslangic#=INSTRING('"content": "',ChatGPTResponse,1,1)
bitis#=INSTRING('"finish_reason": "',ChatGPTResponse,1,1)
IF baslangic#=0 OR bitis#=0 THEN
!ChatGPTResponse=''
Loc:Status='Couldn''t get legal response from ChatGPT'
EXIT
END
st.SetValue(SUB(ChatGPTResponse,baslangic#+12,bitis#-baslangic#-29))
st.Replace('\n','<13,10>')
st.JsonDecode()
ChatGPTResponse=st.GetValue()
I suggest instead:
ReformatAnswer ROUTINE
st._StealValue(st.Utf8ToAnsi(Loc:GetString,uz#,st:CP_ISO_8859_9))
if st.setBetween('"content": "', '"finish_reason": "') = st:notFound
!ChatGPTResponse=''
Loc:Status='Couldn''t get legal response from ChatGPT'
EXIT
end
st.Replace('\n','<13,10>')
st.JsonDecode()
ChatGPTResponse=st.GetValue()
also note the use there of st.setBetween which simplifies the code (and writing less code means less chance of introducing a bug, so always a win in my book).
hth and cheers
Geoff R
Thank you very much for the improvements, Geoff.
Hi again. You can download the latest versions from my Github address. The code is publicly available. Local GPT (Ollama) & ChatGPT voice added to source.
serhatsatir/Clarion-AI: Connect to ChatGPT, Ollama or Gemini (github.com)
See earlier in this thread.
If your string contains { < or â then you need to double them up.
hth
Geoff R
Thanks, have downloaded the new version. That worksâŚonly: I get âyour request has been completedâ , but do not see the text in the response field. The api_key field = 80 char. âŚthe key is much longer. Is that right? I made that field longer, but same result.
Piet
Hi Piet,
Sorry for the late reply. In addition to Geoffâs warnings; the API key I use is 51 digits, so I donât think it will be caused by that. I suggest you make sure that there are no special characters etc. in it. Also, please make sure that your account is active on the OpenAI side. I tried it for today and it worked again. We use it constantly in our own CRM application.
The model used in the ReformatTextCompletion ROUTINE is written. Can you check that too? Maybe you may be trying to access a model that has been discontinued.
- The model I use; st.Prepend(â{{âmodelâ: âgpt-4oâ, âmessagesâ: [{{âroleâ: âuserâ, âcontentâ: ââ)
Kind Regards,
Serhat
I would like to make an addition. If you use Debugview++ you can monitor what is sent to the server and what is returned. I just ran into a problem similar to yours when I was modeling for DeepSeek. The response it returned was as follows.
[st][1] Response: (976 bytes) HTTP/1.1 402 Payment Required
- I wanted to try it out before I gave them my credit card.
fyiâŚ
Thanks Serhat,
You wrote your key = 51 char. Mine is more thean 2000 digits. I followed the link you supplied to make that API key, loggin in an made a new key. I must be doing something wrong.
The error I see (dbgView) = message": "The model gpt-4o
does not exist or you do not have access to itâŚ
Regards, Piet Bouma
seems that flash 2.0 just goes into repeat context mode⌠Claude as held its context better than the others and we have used it to generate a lot of CPP code for bindables. Auto COM CPP and QT Widgets wrapped classes for Bindables. Wonder if SV will have problems training there models and that is why the delays could be longer than expected.