Skip to content

Conversation

nsarrazin
Copy link
Contributor

@nsarrazin nsarrazin commented Nov 1, 2023

This PR adds support for openAI endpoint with a refactor that make it easier to handle adding independent backends with library dependencies in the future. For example if you want to add gpt-3.5-turbo:

Add to your MODELS :

{
      "name": "gpt-3.5-turbo",
      "displayName": "ChatGPT",
      "preprompt": "",
      "parameters": {
        "temperature": 0.1,
        "top_p": 0.95,
        "repetition_penalty": 1.2,
        "top_k": 50,
        "truncate": 1000,
        "max_new_tokens": 2048
      },
      "endpoints" : [{
        "type": "openai"
      }]
}

and add OPENAI_API_KEY to your .env.local

Closes #452
Closes #428

chenhunghan and others added 28 commits September 19, 2023 15:28
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
@nsarrazin nsarrazin added enhancement New feature or request back This issue is related to the Svelte backend or the DB labels Nov 1, 2023
nsarrazin and others added 2 commits November 3, 2023 08:54
Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>
@nsarrazin
Copy link
Contributor Author

Tested this locally with openAI, the llama.cpp local server with openAI adapter and also plain TGI and everything works great.

I think this is good to go imo!

@nsarrazin
Copy link
Contributor Author

cc @coyotte508 if you want to take a quick peek, especially in endpoints.ts and models.ts

Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>
@wdhorton
Copy link
Contributor

wdhorton commented Nov 8, 2023

I've been testing this branch and from what I've seen, it seems to break the LLM Summarization for the conversation title

Copy link

@Maemol Maemol left a comment

Choose a reason for hiding this comment

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

I'm using mostly Azure Open AI so I tested this branch with an Azure Endpoint. With some minor tweaks it works well so thanks for this PR!

I also tested the websearch but I had some issues with the GenerateQuery that didn't understand the preprompt (system prompt) correctly.

Appart from that, it's working well for me.

@Fadude
Copy link

Fadude commented Nov 12, 2023

Looking forward for this PR 👀

@nsarrazin
Copy link
Contributor Author

I was on holiday last week, I'll be back Tuesday and implement the feedback/merge this then!

@nsarrazin
Copy link
Contributor Author

I also just added support directly for the llama.cpp API server directly since the protocol is a bit different!

@nsarrazin nsarrazin merged commit 9db8ced into main Nov 15, 2023
@nsarrazin nsarrazin deleted the refacto/backend_openai branch November 15, 2023 09:11
ice91 pushed a commit to ice91/chat-ui that referenced this pull request Oct 30, 2024
* Fix the response

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Should use /completions

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Use async generator

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Use openai npm

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix generateFromDefaultEndpoint

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix last char become undefined

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Better support for system prompt

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Updates

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Revert

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Update README

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Default system prompt

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* remove sk-

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fixing types

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix lockfile

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Move .optional

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Add try...catch and controller.error(error)

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* baseURL

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Format

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix types

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix again

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Better error message

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Update README

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Refactor backend to add support for modular backends

* readme fix

* readme update

* add support for lambda on aws endpoint

* upsate doc for lambda support

* fix typecheck

* make imports really optional

* readme fixes

* make endpoint creator async

* Update README.md

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* Update README.md

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* Update src/lib/server/endpoints/openai/endpointOai.ts

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* trailing comma

* Update README.md

Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>

* change readme example name

* Update src/lib/server/models.ts

Co-authored-by: Eliott C. <coyotte508@gmail.com>

* fixed preprompt to use conversation.preprompt

* Make openAI endpoint compatible with Azure OpenAI

* surface errors in generation

* Added support for llamacpp endpoint

* fix llamacpp endpoint so it properly stops

* Add llamacpp example to readme

* Add support for legacy configs

---------

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Co-authored-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>
Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>
Co-authored-by: Eliott C. <coyotte508@gmail.com>
maksym-work pushed a commit to siilats/chat-ui that referenced this pull request Jul 2, 2025
* Fix the response

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Should use /completions

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Use async generator

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Use openai npm

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix generateFromDefaultEndpoint

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix last char become undefined

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Better support for system prompt

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Updates

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Revert

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Update README

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Default system prompt

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* remove sk-

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fixing types

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix lockfile

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Move .optional

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Add try...catch and controller.error(error)

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* baseURL

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Format

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix types

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix again

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Better error message

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Update README

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Refactor backend to add support for modular backends

* readme fix

* readme update

* add support for lambda on aws endpoint

* upsate doc for lambda support

* fix typecheck

* make imports really optional

* readme fixes

* make endpoint creator async

* Update README.md

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* Update README.md

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* Update src/lib/server/endpoints/openai/endpointOai.ts

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* trailing comma

* Update README.md

Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>

* change readme example name

* Update src/lib/server/models.ts

Co-authored-by: Eliott C. <coyotte508@gmail.com>

* fixed preprompt to use conversation.preprompt

* Make openAI endpoint compatible with Azure OpenAI

* surface errors in generation

* Added support for llamacpp endpoint

* fix llamacpp endpoint so it properly stops

* Add llamacpp example to readme

* Add support for legacy configs

---------

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Co-authored-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>
Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>
Co-authored-by: Eliott C. <coyotte508@gmail.com>
Matsenas pushed a commit to Matsenas/chat-ui that referenced this pull request Jul 4, 2025
* Fix the response

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Should use /completions

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Use async generator

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Use openai npm

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix generateFromDefaultEndpoint

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix last char become undefined

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Better support for system prompt

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Updates

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Revert

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Update README

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Default system prompt

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* remove sk-

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fixing types

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix lockfile

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Move .optional

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Add try...catch and controller.error(error)

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* baseURL

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Format

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix types

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix again

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Better error message

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Update README

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Refactor backend to add support for modular backends

* readme fix

* readme update

* add support for lambda on aws endpoint

* upsate doc for lambda support

* fix typecheck

* make imports really optional

* readme fixes

* make endpoint creator async

* Update README.md

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* Update README.md

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* Update src/lib/server/endpoints/openai/endpointOai.ts

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* trailing comma

* Update README.md

Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>

* change readme example name

* Update src/lib/server/models.ts

Co-authored-by: Eliott C. <coyotte508@gmail.com>

* fixed preprompt to use conversation.preprompt

* Make openAI endpoint compatible with Azure OpenAI

* surface errors in generation

* Added support for llamacpp endpoint

* fix llamacpp endpoint so it properly stops

* Add llamacpp example to readme

* Add support for legacy configs

---------

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Co-authored-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>
Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>
Co-authored-by: Eliott C. <coyotte508@gmail.com>
gary149 pushed a commit to gary149/chat-ui that referenced this pull request Aug 29, 2025
* Fix the response

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Should use /completions

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Use async generator

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Use openai npm

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix generateFromDefaultEndpoint

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix last char become undefined

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Better support for system prompt

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Updates

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Revert

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Update README

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Default system prompt

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* remove sk-

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fixing types

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix lockfile

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Move .optional

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Add try...catch and controller.error(error)

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* baseURL

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Format

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix types

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix again

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Better error message

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Update README

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Refactor backend to add support for modular backends

* readme fix

* readme update

* add support for lambda on aws endpoint

* upsate doc for lambda support

* fix typecheck

* make imports really optional

* readme fixes

* make endpoint creator async

* Update README.md

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* Update README.md

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* Update src/lib/server/endpoints/openai/endpointOai.ts

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* trailing comma

* Update README.md

Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>

* change readme example name

* Update src/lib/server/models.ts

Co-authored-by: Eliott C. <coyotte508@gmail.com>

* fixed preprompt to use conversation.preprompt

* Make openAI endpoint compatible with Azure OpenAI

* surface errors in generation

* Added support for llamacpp endpoint

* fix llamacpp endpoint so it properly stops

* Add llamacpp example to readme

* Add support for legacy configs

---------

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Co-authored-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>
Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>
Co-authored-by: Eliott C. <coyotte508@gmail.com>
gary149 pushed a commit to gary149/chat-ui that referenced this pull request Aug 29, 2025
* Fix the response

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Should use /completions

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Use async generator

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Use openai npm

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix generateFromDefaultEndpoint

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix last char become undefined

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Better support for system prompt

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Updates

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Revert

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Update README

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Default system prompt

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* remove sk-

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fixing types

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix lockfile

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Move .optional

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Add try...catch and controller.error(error)

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* baseURL

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Format

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix types

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Fix again

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Better error message

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Update README

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Refactor backend to add support for modular backends

* readme fix

* readme update

* add support for lambda on aws endpoint

* upsate doc for lambda support

* fix typecheck

* make imports really optional

* readme fixes

* make endpoint creator async

* Update README.md

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* Update README.md

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* Update src/lib/server/endpoints/openai/endpointOai.ts

Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>

* trailing comma

* Update README.md

Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>

* change readme example name

* Update src/lib/server/models.ts

Co-authored-by: Eliott C. <coyotte508@gmail.com>

* fixed preprompt to use conversation.preprompt

* Make openAI endpoint compatible with Azure OpenAI

* surface errors in generation

* Added support for llamacpp endpoint

* fix llamacpp endpoint so it properly stops

* Add llamacpp example to readme

* Add support for legacy configs

---------

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Co-authored-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com>
Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>
Co-authored-by: Eliott C. <coyotte508@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back This issue is related to the Svelte backend or the DB enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants