yaroslavyaroslav / OpenAI-sublime-text

First class Sublime Text AI assistant with GPT-4o and llama.cpp support!
MIT License
130 stars 11 forks source link

ChatGPT support #9

Closed yaroslavyaroslav closed 1 year ago

yaroslavyaroslav commented 1 year ago

OpenAI released API for their new models, they should be added here.

https://platform.openai.com/docs/guides/chat/introduction?utm_medium=email&_hsmi=248340301&_hsenc=p2ANqtz-_-za1TjjgJAe2CzALsgxI35o1gymBzWLE0iy3Q-F8V_beJmIK4-cqh4QQTJggsTTk_HrHi0g_s5ZmXyocedEPfsmocawRoimxC1khMSRIbCY7KiwQ&utm_content=248340301&utm_source=hs_email

yaroslavyaroslav commented 1 year ago

It would take some time to design this appropriately and to implement it then this way. Yet there’s absolutely outstanding telegram bot for chatgpt, that I’m using so far.

yaroslavyaroslav commented 1 year ago

All work related to Chat-GPT would be made within chat-gpt branch.

ps: Now there's just one commit, but it's working within a golden path: Output panel mode and only completion command.

ps2: It's hardcoded to gpt-4 model. Please update the source by yourself if required.

yaroslavyaroslav commented 1 year ago

Since this is self assigned journey of ChatGPT support implementation. The chat-gpt branch now contains fully supported ChatGPT API plugin version.

It's kinda golden path yet, but it's pretty usable at my taste. As I'm willing to release it as long as the end of April at soonest.

If you wan't some additional info about the feature current state, please take a look at this commit.

UPD: Almost forgot: at this point you have to have MarkdownEditing plugin installed, since its hardcoded as a markdown syntax highlighting. Sorry. It would be fixed at release.

hank-cp commented 1 year ago

@yaroslavyaroslav awesome job👍

Could you please add socks proxy support btw?

yaroslavyaroslav commented 1 year ago

Could you please add socks proxy support btw?

I could try if you throw to me a comprehensive code snippet for that.

And thanks

yaroslavyaroslav commented 1 year ago

Next bit of updates could be found here.

  1. It should work within a multiple windows, with a single session though. It's not that I'd liked this behaviour, it's a dumb one, but I see no simple options to make it better. So for 2.0 there's for sure would be just a single session with a hardcoded scroll to the end of the output for each window, yet someday with the version like 2.5 it could get some sessions with appropriate it's management.

  2. User should be able to use it without that md plugin installed and without a markdown syntax highlight though.

hank-cp commented 1 year ago

It could be simply done by openai.proxy:

import openai

openai.proxy = "http://<host>:<port>"

Looks openai python lib supports http proxy only, doesn't support socks proxy. Good enough already:)

Could you please add socks proxy support btw?

I could try if you throw to me a comprehensive code snippet for that.

And thanks

yaroslavyaroslav commented 1 year ago

@hank-cp Unfortunately it can't be done that way. Theirs is a very limited number of a Python libraries that could be used as a dependency for a Sublime package. And openai one in not in that list.

hank-cp commented 1 year ago

@hank-cp Unfortunately it can't be done that way. Theirs is a very limited number of a Python libraries that could be used as a dependency for a Sublime package. And openai one in not in that list.

I see. Here is another code snippet without additional dependencies:

conn = http.client.HTTPSConnection("<proxy.host>", proxy.port)
conn.set_tunnel("api.openai.com")
....
conn.request("POST", "/v1/completions", json_payload, headers)
yaroslavyaroslav commented 1 year ago

@hank-cp thanks, I'll add it to the plugin settings, and ping you if there would be any problems with that.

yaroslavyaroslav commented 1 year ago

@hank-cp Please check that commit https://github.com/yaroslavyaroslav/OpenAI-sublime-text/commit/f2e19ab5070d5ab5168a63813b5a3ef8a227d403 in the gpt branch and reach me back whether it's working as expected?

hank-cp commented 1 year ago

@yaroslavyaroslav I tried to test in on my local sublime but got below error:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python38/sublime_plugin.py", line 1697, in run_
    return self.run(edit, **args)
  File "/Users/hank/Library/Application Support/Sublime Text/Packages/OpenAI-sublime-text/openai.py", line 48, in run
    worker_thread = OpenAIWorker(edit, region, text, self.view, mode, "")
TypeError: __init__() takes 6 positional arguments but 7 were given

Did I miss something?

yaroslavyaroslav commented 1 year ago

@hank-cp Nope, it's a bug. Have to be fixed now with the last commit of this branch.

hank-cp commented 1 year ago

@hank-cp Please check that commit f2e19ab in the gpt branch and reach me back whether it's working as expected?

Tested, it works:) please also apply this update to other api request.

yaroslavyaroslav commented 1 year ago

Implemented in #10