echo"Python 3 support is required for ChatGPT plugin"
finish
endif
if!exists("g:gpt_openai_api_key")
echo"g:gpt_openai_api_key is not set. Please set it to your OpenAI API key."
finish
endif
if!exists("g:gpt_max_tokens")
letg:gpt_max_tokens=2000
endif
@ -13,10 +18,6 @@ if !exists("g:gpt_temperature")
letg:gpt_temperature=0.7
endif
if!exists("g:gpt_model")
letg:gpt_model='gpt-4o'
endif
if!exists("g:gpt_lang")
letg:gpt_lang='English'
endif
@ -33,23 +34,42 @@ if !exists("g:gpt_persona")
letg:gpt_persona='default'
endif
letg:gpt_templates= {
\ 'Rewrite': 'Rewrite this more idiomatically',
\ 'Review': 'Review this code',
\ 'Document': 'Return documentation following language pattern conventions',
\ 'Explain': 'Explain how this works',
\ 'Test': 'Write a test',
\ 'Fix': 'Fix this error',
\}
letg:gpt_keys=keys(g:gpt_templates)
letg:gpt_personas= {
\ "default": '',
\ "bob": 'You are a helpful expert programmer we are working together to solve complex coding challenges, and I need your help. Please make sure to wrap all code blocks in ``` annotate the programming language you are using.',
print("Error: openai module not found. Please install with Pip and ensure equality of the versions given by :!python3 -V, and :python3 import sys; print(sys.version)")
assertazure_endpointandazure_api_versionandazure_deployment,"azure_endpoint, azure_api_version and azure_deployment not set property, please check your settings in `vimrc` or `enviroment`."
assertapi_key,"api_key not set, please configure your `openai_api_key` in your `vimrc` or `enviroment`"
client=AzureOpenAI(
azure_endpoint=azure_endpoint,
azure_deployment=azure_deployment,
api_key=api_key,
api_version=azure_api_version,
)
else:
client=OpenAI(
base_url=openai_base_url,
api_key=api_key,
@ -39,7 +24,7 @@ def create_client():
returnclient
defchat_gpt(prompt,persist=0):
defchat_gpt(prompt,persist=0)
token_limits={
"gpt-3.5-turbo":4097,
"gpt-3.5-turbo-16k":16385,
@ -54,6 +39,7 @@ def chat_gpt(prompt, persist=0):
max_tokens=int(vim.eval('g:gpt_max_tokens'))
model=str(vim.eval('g:gpt_model'))
token_limit=vim.eval('g:gpt_models[g:gpt_model]')
temperature=float(vim.eval('g:gpt_temperature'))
lang=str(vim.eval('g:gpt_lang'))
resp=f" And respond in {lang}."iflang!='None'else""
@ -80,7 +66,7 @@ def chat_gpt(prompt, persist=0):
history.reverse()
# Adding messages to history until token limit is reached