OpenAI icon indicating copy to clipboard operation
OpenAI copied to clipboard

feat(basePath): enable base path for configuration

Open metrue opened this issue 1 year ago • 17 comments

What

This MR is to resolve the issue https://github.com/MacPaw/OpenAI/issues/68#issuecomment-1548221958

Why

When we set up a proxy for OpenAI API, sometimes we enable a custom endpoint for it, so enabling a base path for the configuration would be helpful when we have something like 'my.host.com/openai/api' proxying OpenAI API.

Affected Areas

Configuration to initialize the OpenAI API instance but it's backward compatible.

metrue avatar May 16 '23 02:05 metrue

Let's improve paths logic 🙏

Done refactoring and unit tests added.

metrue avatar May 30 '23 06:05 metrue

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Aug 06 '23 10:08 sonarqubecloud[bot]

The functionality of this PR is needed, but it seems like Merge is stuck @metrue @Krivoblotsky

WalterZou avatar Aug 22 '23 09:08 WalterZou

Hey, everyone! Thanks a lot for the contribution, I'll review the next batch of PRs today (including this one) and publish a new release.

Krivoblotsky avatar Aug 22 '23 09:08 Krivoblotsky

Also, I need to check why the build is failing ⚠️

Krivoblotsky avatar Aug 22 '23 09:08 Krivoblotsky

Hey, everyone! Thanks a lot for the contribution, I'll review the next batch of PRs today (including this one) and publish a new release.

Cool, thanks so much 🙏

WalterZou avatar Aug 22 '23 09:08 WalterZou

Hey, @metrue. Could you please fix the build? 🙏

Krivoblotsky avatar Aug 22 '23 11:08 Krivoblotsky

hey @Krivoblotsky

I checked the CI log, it does tell why it failed,

2023-06-20T16:21:08.9885513Z Build complete! (4.18s)
2023-06-20T16:21:09.5590135Z error: Exited with signal code 4
2023-06-20T16:21:09.5631060Z Test Suite 'All tests' started at 2023-06-20 16:21:09.008
2023-06-20T16:21:09.5631973Z Test Suite 'debug.xctest' started at 2023-06-20 16:21:09.317
2023-06-20T16:21:09.5632912Z Test Suite 'OpenAITests' started at 2023-06-20 16:21:09.317
2023-06-20T16:21:09.5633428Z Test Case 'OpenAITests.testAudioTranscriptions' started at 2023-06-20 16:21:09.317
2023-06-20T16:21:09.5698541Z ##[error]Process completed with exit code 1.
2023-06-20T16:21:09.5791394Z Post job cleanup.
2023-06-20T16:21:09.7007792Z [command]/usr/bin/git version

And I run swift test locally, it works well, anyone can advice would be great.

Test Case '-[OpenAITests.OpenAITestsDecoder testModerations]' started.
Test Case '-[OpenAITests.OpenAITestsDecoder testModerations]' passed (0.000 seconds).
Test Suite 'OpenAITestsDecoder' passed at 2023-08-23 22:47:56.335.
	 Executed 10 tests, with 0 failures (0 unexpected) in 0.003 (0.003) seconds
Test Suite 'OpenAIPackageTests.xctest' passed at 2023-08-23 22:47:56.335.
	 Executed 46 tests, with 0 failures (0 unexpected) in 0.029 (0.030) seconds
Test Suite 'All tests' passed at 2023-08-23 22:47:56.335.
	 Executed 46 tests, with 0 failures (0 unexpected) in 0.029 (0.033) seconds

metrue avatar Aug 23 '23 14:08 metrue

@metrue, thanks! CI runs build and test on Linux, maybe this is the cause. I'll try to run it once again and check.

Krivoblotsky avatar Aug 23 '23 15:08 Krivoblotsky

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 8 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Nov 15 '23 14:11 sonarqubecloud[bot]

Hi, how is this PR coming along? Customizing the endpoints is necessary and I'm looking forward to this feature.

tisfeng avatar Jan 01 '24 03:01 tisfeng

Going a step further, we can customize the entire endpoint, not just the base path, because sometimes we build the OpenAI service locally, when it's an http request instead of an https, e.g. http://localhost:3000/v1/chat/completions

Therefore, I hope to provide an endPoint property that allows the user to freely configure the request URL.

image

tisfeng avatar Jan 01 '24 03:01 tisfeng

I need this

snake302 avatar Jan 05 '24 19:01 snake302

Hi, how's this going?

tisfeng avatar Feb 16 '24 02:02 tisfeng

还没搞定吗?

qaz1991815 avatar Feb 21 '24 08:02 qaz1991815

Quality Gate Passed Quality Gate passed

Issues
8 New issues

Measures
0 Security Hotspots
No data about Coverage
1.3% Duplication on New Code

See analysis details on SonarCloud

sonarqubecloud[bot] avatar Feb 27 '24 07:02 sonarqubecloud[bot]

Due to the lack of developers handling this issue, I added a new public API myself to make it easier to support user-defined request URLs, just for my own convenience, and also submitted a PR https://github.com/MacPaw/OpenAI/pull/204 .

Can be used simply as follows:

openAI.chatsStream(query: query, url:"http://localhost:11434/v1/chat/completions")

tisfeng avatar May 11 '24 13:05 tisfeng