Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic implementation of an plugin system for OA #2765

Merged
merged 19 commits into from
May 2, 2023

Conversation

draganjovanovich
Copy link
Collaborator

@draganjovanovich draganjovanovich commented Apr 19, 2023

the plugins

Hi, this is my first PR here, but I was somewhat active on other fronts of OA development.

This pr will bring some basic plugin functionality to the Open Assistant, and as discussed with @yk @andreaskoepf
there are quite a few directions for something like this to be integrated with OA, but this should serve a purpose as some initial proof-of-concept and exploratory feature for 3rd party integrations with OA.

I also included a small calculator plugin as a possible candidate for the OA internal plugin, which would be like the default one, for people to try out and also as an example, of how one could implement own plugins.

If we decide to include this plugin, there should be added a deployment/hosting mechanism for it.

I will push a separate branch in the next couple of days, that will serve as an alternative to the approach, so we can A/B test it along with the new models (SFT-s/RLHF-s)

I also tried to comment on every weird quirk or decision in code, so one could easily understand, and change it, but there are quite a few places, where a simple new line char or like " char in specific strings, could affect LLM performance in the plugin usage scenario.

Will also try to push some documentation regarding plugin development, but there are already some useful comments in calculator plugin on what should be paid attention to.

Here are some of the current UI changes introduced with this PR.

Plugin chooser component Screenshot 2023-04-20 at 00 55 38
Plugin execution details component Screenshot 2023-04-19 at 21 40 38 Screenshot 2023-04-19 at 21 40 56 Screenshot 2023-04-19 at 21 30 18
Plugin assisted answer Screenshot 2023-04-19 at 21 29 52 Screenshot 2023-04-21 at 18 28 45
Verified plugin usage UI look Screenshot 2023-04-20 at 15 08 36
Some plugin usage examples Screenshot 2023-04-18 at 01 57 33 Screenshot 2023-04-17 at 23 17 35
Mixed usage example where model chooses not to use plugin on its own Screenshot 2023-04-20 at 21 31 46

@draganjovanovich draganjovanovich added feature New feature or request needs discussion labels Apr 19, 2023
- added mussing types
- fixed typos in react imports
Copy link
Contributor

@pevogam pevogam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @draganjovanovich, first and foremost kudos for the great effort here!

@andrewm4894
Copy link
Collaborator

So cool! if possible can you add some docstrings to some of the important functions to make it easier to try just jump in and understand them? I'm not 100% sure if we have any standards etc around this yet in the repo - but was thinking if thinking about some docs maybe starting there might be least painful for now potentially as such a big PR.

- swaped "Question" from prompt with "New Input", works better with llama-SFT-7E3
- seed -> 43
- similarity coef for tool selection reduced
currently testing: llama-sft-7-e3 and small fixes
- small prompt composition tweaks
- fix for chat memory deletion
- tweaking of sampling parameters
- increased limit of request result truncation
@andrewm4894
Copy link
Collaborator

What would be a good way to try help test this out?

Would it be feasible for me to try this "locally" in some way?

@draganjovanovich
Copy link
Collaborator Author

I can tell you how I ran this "locally" if it helps.

I used docker for the complete OA stack on my local server like:
docker compose --profile frontend-dev --profile inference up --build --attach-dependencies
and the inference server was run on a remote server. (4XA100 80gb) sharded with https://github.com/huggingface/text-generation-inference
You can than point worker to that inference server with editing of worker_full_main.sh, but I am not sure that is the easiest way, however, that is how I did it.
You can easily fit it in single A100 or even weaker gpu with half precision, but if you want to do prompt engineering which requires multiple re-runs of generations over and over again, you will give up soon, because of slowness... at least i did lol.

As for requirements for the model, there are some details in readme.md files inside of inference and worker folders.

@pevogam
Copy link
Contributor

pevogam commented Apr 21, 2023

I used docker for the complete OA stack on my local server like:
docker compose --profile frontend-dev --profile inference up --build --attach-dependencies

Strangely I keep encountering

Error response from daemon: network 102b7c8cf4e45cd48696f81aaef73b33e88df2d979cdad8ca372c911c9753b7b not found

with the frontend. Can you also elaborate more on how to run it using just the inference text client and reducing the number of container services we need? For instance what docker container command line do you use to start the calculator plugin service?

EDIT: I cleaned up the issue there but the above is more about ways to set up a service like the calculator and possibly reduce the service dependencies to just a text client. In both cases we will need to start the plugin service as it won't be available from a GUI frontend as well.

@draganjovanovich
Copy link
Collaborator Author

Hi,

Plugin is not included in docker containers, as its just example for now, there is no internal agreement yet, how we would go about default 'out-of-the-box' plugins.

You can for now just run this command from the plugin folder: uvicorn main:app --reload --port 8085 --host 0.0.0.0

And update IP of the plugin in inference/server/oaast_inference_server/routes/configs.py the accordingly to your network environment.

@pevogam
Copy link
Contributor

pevogam commented Apr 21, 2023

Hi,

Plugin is not included in docker containers, as its just example for now, there is no internal agreement yet, how we would go about default 'out-of-the-box' plugins.

That's ok. The idea however is to spin it up so that we can experiment with a plugin in general and the changes here.

You can for now just run this command from the plugin folder: uvicorn main:app --reload --port 8085 --host 0.0.0.0

And update IP of the plugin in inference/server/oaast_inference_server/routes/configs.py the accordingly to your network environment.

Not sure if all of this is enough:

image

I did

pip install uvicorn starlette
/mnt/local/notebooks/Open-Assistant/inference/worker/plugins/calculator> uvicorn main:app --reload --port 8085 --host 0.0.0.0
INFO:     Will watch for changes in these directories: ['/mnt/local/notebooks/Open-Assistant/inference/worker/plugins/calculator']
INFO:     Uvicorn running on http://0.0.0.0:8085 (Press CTRL+C to quit)
INFO:     Started reloader process [29640] using statreload
INFO:     Started server process [29642]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     172.20.0.12:42990 - "GET /ai-plugin.json HTTP/1.1" 200 OK
INFO:     172.20.0.10:44318 - "GET /ai-plugin.json HTTP/1.1" 200 OK
INFO:     192.168.40.1:46356 - "GET / HTTP/1.1" 404 Not Found
INFO:     172.20.0.10:51110 - "GET /ai-plugin.json HTTP/1.1" 200 OK

and adapted the IP in

diff --git a/inference/server/oasst_inference_server/routes/configs.py b/inference/server/oasst_inference_server/routes/configs.py
index 46a8ff99..7c0f2a0e 100644
--- a/inference/server/oasst_inference_server/routes/configs.py
+++ b/inference/server/oasst_inference_server/routes/configs.py
@@ -12,7 +12,7 @@ from oasst_shared.schemas import inference
 # NOTE: Replace this with plugins that we will provide out of the box
 DUMMY_PLUGINS = [
     inference.PluginEntry(
-        url="http://192.168.0.35:8085/ai-plugin.json",
+        url="http://192.168.0.31:8085/ai-plugin.json",
         enabled=False,
         trusted=True,
     ),

then tested the port opening via telnet and it is there. The web UI shows the borked menu you can see above and the logs don't show the plugins list being populated with everything.

@draganjovanovich
Copy link
Collaborator Author

All that you have done seems about right.
I am not sure, why is not working for you, do you have errors on the docker logger?

@draganjovanovich
Copy link
Collaborator Author

It would be cool if you or someone can make some automated "dev" chat sessions like:
I or any dev, provide input messages as JSON files, drag over chat UI, and it automatically sends one message, waits for an answer, and then continues with a second message, etc
For now, I do that manually.

@pevogam
Copy link
Contributor

pevogam commented Apr 21, 2023

All that you have done seems about right. I am not sure, why is not working for you, do you have errors on the docker logger?

Unfortunately no error of any kind (also no Failed to fetch plugin config logging messages from the server), do the logs contain useful debugging information if the plugin was detected and loaded in some way? I can see the initial GET request for the service

INFO:     172.20.0.10:37900 - "GET /ai-plugin.json HTTP/1.1" 200 OK

and I can see the minimal plugin being listed in the work request:

plugins=[PluginEntry(url='Test', enabled=True, plugin_config=None, trusted=False)]

Perhaps the plugin_config should be populated and values here should be different?

@draganjovanovich
Copy link
Collaborator Author

Yes there are some logs, like:
Screenshot 2023-04-21 at 12 30 46

in routes/config.py

- tweaked sampling settings for plugin usage
- tweaked prompting templage
- fix for tool extraction function
- fix in final prompt when plugin is not used
legal_info_url: str | None = None
endpoints: List[PluginOpenAPIEndpoint] | None = None

def __getitem__(self, key: str) -> Any:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure these are working as wanted? pydantic does quite a bit of magic, I'm particularly worried about the use of setattr here, but it's just a feeling, no particular knowledge

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, It works. but could be that I am misusing it?



class PluginUsed(pydantic.BaseModel):
name: str | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why could name or url be none here? does it make sense ot have a PluginUsed with only execution details and nothing else?

Copy link
Collaborator Author

@draganjovanovich draganjovanovich Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that I had some misconfigured plugins while developing it, and then got the error with name cant be None, just added None, so it can be deleted. But regarding plugins and parsing, there are quite a few weak points, i will address them soon, as i found them while trying various other plugins...

For example this one will fail:
https://chatgpt-plugin-ts.transitive-bullshit.workers.dev/.well-known/ai-plugin.json

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it just half hour ago, will push it later then.

deleted package-lock.json in the root of the repo
Copy link
Collaborator

@AbdBarho AbdBarho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Web stuff LGTM.

Still needs a clean up but we can do that in another PR, this one is getting way too big.

Copy link
Collaborator

@yk yk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except the small part on storing used plugins with work parameters. maybe fix that, then good to merge

@olliestanley
Copy link
Collaborator

olliestanley commented May 1, 2023

Hmm, seems like the merge of main into PR branch has caused some mess in the PR history

@draganjovanovich
Copy link
Collaborator Author

I reverted it, will try rebase, to fix conflicts

@LAION-AI LAION-AI deleted a comment from github-actions bot May 1, 2023
@LAION-AI LAION-AI deleted a comment from github-actions bot May 1, 2023
@LAION-AI LAION-AI deleted a comment from github-actions bot May 1, 2023
@github-actions
Copy link

github-actions bot commented May 1, 2023

pre-commit failed.
Please run pre-commit run --all-files locally and commit the changes.
Find more information in the repository's CONTRIBUTING.md

- fixed conflicts with frontend part of the app
Copy link
Collaborator

@olliestanley olliestanley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server/worker stuff LGTM with latest changes!

@draganjovanovich draganjovanovich merged commit c871915 into LAION-AI:main May 2, 2023
layterz pushed a commit to layterz/Open-Assistant that referenced this pull request May 11, 2023
# the plugins
Hi, this is my first PR here, but I was somewhat active on other fronts
of OA development.

This pr will bring some basic plugin functionality to the Open
Assistant, and as discussed with @yk @andreaskoepf
there are quite a few directions for something like this to be
integrated with OA, but this should serve a purpose as some initial
proof-of-concept and exploratory feature for 3rd party integrations with
OA.

I also included a small **calculator** plugin as a possible candidate
for the OA internal plugin, which would be like the default one, for
people to try out and also as an example, of how one could implement own
plugins.

If we decide to include this plugin, there should be added a
deployment/hosting mechanism for it.

I will push a separate branch in the next couple of days, that will
serve as an alternative to the approach, so we can A/B test it along
with the new models (SFT-s/RLHF-s)

I also tried to comment on every weird quirk or decision in code, so one
could easily understand, and change it, but there are quite a few
places, where a simple new line char or like " char in specific strings,
could affect LLM performance in the plugin usage scenario.

Will also try to push some documentation regarding plugin development,
but there are already some useful comments in **calculator** plugin on
what should be paid attention to.

Here are some of the current UI changes introduced with this PR.
<details>
  <summary>Plugin chooser component</summary>
<img width="854" alt="Screenshot 2023-04-20 at 00 55 38"
src="https://user-images.githubusercontent.com/13547364/233217078-d2e4e28f-36eb-451e-a655-1679188aed52.png">
</details>
<details>
  <summary>Plugin execution details component</summary>
<img width="824" alt="Screenshot 2023-04-19 at 21 40 38"
src="https://user-images.githubusercontent.com/13547364/233216884-e69bcf9c-707f-43de-a52d-41db5d92c504.png">
<img width="744" alt="Screenshot 2023-04-19 at 21 40 56"
src="https://user-images.githubusercontent.com/13547364/233217161-c114f5b9-881f-4476-a2b1-459179a9353e.png">
<img width="545" alt="Screenshot 2023-04-19 at 21 30 18"
src="https://user-images.githubusercontent.com/13547364/233217187-17fb87e5-e4be-43e4-96ac-7cdd84223147.png">
</details>
<details open>
 <summary>Plugin assisted answer</summary>
<img width="837" alt="Screenshot 2023-04-19 at 21 29 52"
src="https://user-images.githubusercontent.com/13547364/233217260-4986f456-efa5-47a5-aabc-926a8a5a9a2f.png">
<img width="943" alt="Screenshot 2023-04-21 at 18 28 45"
src="https://user-images.githubusercontent.com/13547364/233687877-0d0f9ffb-b16a-48de-96ad-e4c3a02f4c66.png">
</details>
<details>
 <summary>Verified plugin usage UI look</summary>
<img width="864" alt="Screenshot 2023-04-20 at 15 08 36"
src="https://user-images.githubusercontent.com/13547364/233376402-52ed5a3d-631a-4350-9130-61548a8d7b02.png">
</details>
<details>
 <summary>Some plugin usage examples</summary>
<img width="1048" alt="Screenshot 2023-04-18 at 01 57 33"
src="https://user-images.githubusercontent.com/13547364/233217685-79b262bd-81fd-4641-9ad9-110e8b689e42.png">
<img width="993" alt="Screenshot 2023-04-17 at 23 17 35"
src="https://user-images.githubusercontent.com/13547364/233217687-561773a1-b16a-49f5-bdbc-f30b46bed33d.png">
</details>
<details open>
<summary>Mixed usage example where model chooses not to use plugin on
its own</summary>
<img width="690" alt="Screenshot 2023-04-20 at 21 31 46"
src="https://user-images.githubusercontent.com/13547364/233469420-25c72893-7c7a-426c-9f4b-ce9144d643ae.png">
</details>

---------

Co-authored-by: agi <you@example.com>
Co-authored-by: Yannic Kilcher <yk@users.noreply.github.com>
Co-authored-by: Oliver Stanley <olivergestanley@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request needs discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.