Commit Graph

158 Commits

Author SHA1 Message Date
渡邉祐一 / Yuichi Watanabe
06b16a7281 fix json marshaling error response of azure openai (#343) (#345)
* fix json marshaling error response of azure openai (#343)

* add a test case for handleErrorResp func (#343)
2023-06-08 19:32:03 +04:00
Yuki Bobier Koshimizu
b8c13e4c01 Refactor streamReader: Replace goto Statement with Loop in Recv Method (#339)
* test: Add tests for improved coverage before refactoring

This commit adds tests to improve coverage before refactoring
to ensure that the changes do not break anything.

* refactor: replace goto statement with loop

This commit introduces a refactor to improve the clarity of the control flow within the method.
The goto statement can sometimes make the code hard to understand and maintain, hence this refactor aims to resolve that.

* refactor: extract for-loop from Recv to another method

This commit improves code readability and maintainability
by making the Recv method simpler.
2023-06-08 19:31:25 +04:00
渡邉祐一 / Yuichi Watanabe
6830e00406 Support Retrieve model API (#340) (#341)
* Support Retrieve model API (#340)

* Test for GetModel error cases. (#340)

* Reduce the cognitive complexity of TestClientReturnsRequestBuilderErrors (#340)
2023-06-05 18:37:08 +04:00
渡邉祐一 / Yuichi Watanabe
1394329e44 move error_accumulator into internal pkg (#304) (#335)
* move error_accumulator into internal pkg (#304)

* move error_accumulator into internal pkg (#304)

* add a test for ErrTooManyEmptyStreamMessages in stream_reader (#304)
2023-06-05 18:35:46 +04:00
Mariano Darc
fa694c61c2 Implement optional io.Reader in AudioRequest (#303) (#265) (#331)
* Implement optional io.Reader in AudioRequest (#303) (#265)

* Fix err shadowing

* Add test to cover AudioRequest io.Reader usage

* Add additional test cases to cover AudioRequest io.Reader usage

* Add test to cover opening the file specified in an AudioRequest
2023-06-05 10:07:13 +04:00
渡邉祐一 / Yuichi Watanabe
61ba5f3369 move request_builder into internal pkg (#304) (#329)
* move request_builder into internal pkg (#304)

* add some test for internal.RequestBuilder

* add a test for openai.GetEngine
2023-05-31 12:01:42 +04:00
渡邉祐一 / Yuichi Watanabe
62eb4beed2 move marshaller and unmarshaler into internal pkg (#304) (#325) 2023-05-28 05:51:07 +04:00
Bo-Yi Wu
980504b47e docs(readme): update format (#317) 2023-05-27 14:13:41 +04:00
Rich Coggins
a18c18d5e8 Update README.md with Azure OpenAI Embeddings example (#318) 2023-05-22 08:18:31 +04:00
Tom Hennessy
faae8b4b4b Update README.md (#319)
Added in `unofficial` to the README to make it clear it's not official.
2023-05-22 08:17:16 +04:00
Takahiro Ikeuchi
b62a325b0a Azure OpenAI API version 2023-05-15 (#316)
* chore(config.go): update Azure API version to 2023-05-15 to use the latest version available

* chore(api_internal_test.go): update Azure API version to 2023-05-15 to match the latest version
2023-05-19 12:04:16 -07:00
JoyShi
21eef5bc8d Move form_builder into internal pkg. (#311)
* Move form_uilder into internal pkg.

* Fix import of audio.go

* Reorganize.

* Fix import.

* Fix

---------

Co-authored-by: JoyShi <joy.shi@sap.com>
2023-05-16 13:38:09 -07:00
xuanming.zhang
83d03fca52 Adjust the azure model deployment name call corresponding to README (#309) 2023-05-14 21:29:28 -07:00
GargantuaX
be253c2d63 change azure engine config to modelMapper (#306)
* change azure engine config to azure modelMapper config

* Update go.mod

* Revert "Update go.mod"

This reverts commit 78d14c58f2a9ce668da43f6adbe20b60afcfe0d7.

* lint fix

* add test

* lint fix

* lint fix

* lint fix

* opt

* opt

* opt

* opt
2023-05-11 01:30:24 +04:00
Hoani Bryson
5f4ff3ebfa Add Readme example to example_test.go (#298)
* Add speech to text example in docs

* Add caption formats for audio transcription

* Add caption example to README

* Address sanity check errors

* Add tests for decodeResponse

* Use typechecker for audio response format

* Decoding response refactors

* Migrated examples to example_test.go

* Add some executable examples

* Update error docs

* Avoid linting example files which break conventions

* Restore README examples

* Enable linting for example_test
2023-05-08 20:16:01 +04:00
Semenchenko Kirill
39abb5a4be add missing error processing for audio (#301)
Co-authored-by: Kirill Semenchenko <smoreg@mc2soft.ru>
2023-05-04 22:30:14 +04:00
Quest Henkart
a24581dce2 maintain underlying error structs to allow for type conversion (#293)
* maintain underlying error structs to allow for type conversion and
defensive error checking

* allow Error.Is for Azure responses

* update readme, add tests to ensure type conversion

* fix whitespacing

* read me

* add import to readme example
2023-05-03 22:48:59 +04:00
Yuki Bobier
24aa2005cc test: remove httpbin dependency (#297)
Replace the use of external httpbin service in TestRequestError
with a local HTTP server using the net/http/httptest package.
This change improves test reliability by eliminating the dependency
on an external service.
2023-05-03 20:20:32 +04:00
Juan
104c0c0b63 Azure openai list models (#290)
* feat(models): include flow for azure openai endpoint

* feat(models): include flow for azure openai endpoint

* feat(models): include flow for azure openai endpoint

* chore(fullURL): update logic to run in fullURL function

* chore(fullURL): update based on pr comments to use c.config.APIVersion
2023-05-03 13:02:35 +04:00
quzard
1b8feae0b6 Do not return when not present (#294) 2023-05-02 21:41:21 +04:00
sashabaranov
af9ff51077 fix expected error message (#289) 2023-05-01 02:41:40 +04:00
xuanming.zhang
67aef196d2 Fix OpenAI or Azure returns an undefined error message return (#283)
* Fix OpenAI or Azure returns an undefined error message return

* Fix: OpenAI or Azure returns an undefined error message return
#280

* Fix: OpenAI or Azure returns an undefined error message return
#280

* Fix: OpenAI or Azure returns an undefined error message return
#280

Handle long line

* Fix: OpenAI or Azure returns an undefined error message return
#280

Add unit test ErrorResponse nil pointer check

* Fix: OpenAI or Azure returns an undefined error message return
#280

Add unit test ErrorResponse nil pointer check

---------

Co-authored-by: zhangxm <xuanming_zhang@qingsongchou.com>
2023-05-01 01:21:15 +04:00
Liu Shuang
cacd976a0c feat: RequestError print status code (#285) 2023-05-01 01:18:43 +04:00
刘丹冰
2f008f7054 fix:model param type, add moderation Model Name const. (#270)
* add ImageEditRequest.ResponseFormat

* add ImageEditRequest/ImageVariRequest.ResponseFormat

* complete image_test

* delete var prompt param

* fix:model param type, add  moderation Model Name const.

* rename ModerationText001

---------

Co-authored-by: Aceld <liudanbing@tal.com>
2023-04-20 14:10:19 +01:00
biubiu7
c2b58e77ed Fixing missing OrgId assignment issue in the ChatCompletionStream (#268)
* Update client.go

* Add test

---------

Co-authored-by: panjiajia <panjiajia@haoshuo.com>
2023-04-20 14:08:29 +01:00
Hoani Bryson
ecdea45b67 Adds support for audio captioning with Whisper (#267)
* Add speech to text example in docs

* Add caption formats for audio transcription

* Add caption example to README

* Address sanity check errors

* Add tests for decodeResponse

* Use typechecker for audio response format

* Decoding response refactors
2023-04-20 14:07:04 +01:00
Liu Shuang
d6ab1b3a4f fix: chat stream resp error (#259) 2023-04-19 13:05:00 +01:00
刘丹冰
3b10c032b6 add ImageVariRequest/ImageEditRequest.ResponseFormat (#264)
* add ImageEditRequest.ResponseFormat

* add ImageEditRequest/ImageVariRequest.ResponseFormat

* complete image_test

* delete var prompt param

---------

Co-authored-by: Aceld <liudanbing@tal.com>
2023-04-18 11:23:29 +02:00
Stephen Young
061c97ef7e Implement Unmarshaller interface. Resolves #244 (#248) 2023-04-14 20:09:40 +02:00
sashabaranov
d94c5e7edd Test request builder + streams (#242)
* test request builder + streams

* provide prompt to test
2023-04-09 18:46:58 +04:00
sashabaranov
9a1ecf5f4a Add more tests (#241)
* add form builder tests

* lint

* add client tests

* lint

* add non-existent file test
2023-04-09 18:36:15 +04:00
Rich Coggins
334ee6dbdd Update README.md with Azure OpenAI ChatGPT example (#239)
Co-authored-by: coggsflod <richard.coggins@officedepot.com>
2023-04-08 22:42:55 +04:00
sashabaranov
33ca1dac95 Add files api tests (#238)
* drop support for downloading files

* use form builder to submit files

* update doc

* add form builder tests
2023-04-08 20:13:59 +04:00
sashabaranov
4dc1edac38 add embeddings tests (#237) 2023-04-08 19:49:27 +04:00
sashabaranov
89219e31b2 Update readme (#236)
* Update readme

* update ci names
2023-04-08 19:34:03 +04:00
sashabaranov
226ff328e2 Add form builder (#235)
* add form builder

* cover VariImage

* test for closing errors

* simplify tests

* add audio api test coverage

* don't leak authToken when printed

* rename api->client

* fix test
2023-04-08 19:26:26 +04:00
harry
2f3700f4c5 to fix v1.5.8 Usage return (#223)
* add ChatCompletionStream Usage return

* ChatCompletionStreamResponse will bot return Usage

* remove the Usage field from the response, it would not be there anyway.

---------

Co-authored-by: lihang <nasa.li@deepres.com>
2023-04-04 16:10:54 +04:00
ttys3
8677fb4bb4 feat: add azure openai support (#214)
* feat: add azure openai support

* chore: refine config

* chore: make config options like the python one

* chore: adjust config struct field order

* test: fix tests

* style: make the linter happy

* fix: support Azure API Key authentication in sendRequest

* chore: check error in CreateChatCompletionStream

* chore: pass tests

* chore: try pass tests again

* chore: change ClientConfig back due to this lib does not like WithXxx config style

* chore: revert fix to CreateChatCompletionStream() due to cause tests not pass

* chore: at least add some comment about the required fields

* chore: re order ClientConfig fields

* chore: add DefaultAzure()

* chore: set default api_version the same as py one "2023-03-15-preview"

* style: fixup typo

* test: add api_internal_test.go

* style: make lint happy

* chore: add constant AzureAPIKeyHeader

* chore: use AzureAPIKeyHeader for api-key header, fix azure base url auto trim suffix /

* test: add TestAzureFullURL, TestRequestAuthHeader and TestOpenAIFullURL

* test: simplify TestRequestAuthHeader

* test: refine TestOpenAIFullURL

* chore: refine comments

* feat: DefaultAzureConfig
2023-04-04 12:05:20 +04:00
NullpointerW
bee0656174 CompletionBatchingRequestSupport (#220)
* completionBatchingRequestSupport

* lint fix

* fix Run test fail

* fix TestClientReturnsRequestBuilderErrors fail

* fix Codecov  check

* ignore TestClientReturnsRequestBuilderErrors lint

* fix lint again

* lint again*2

* replace checkPromptType  implementation

* remove nil check

---------

Co-authored-by: W <825708370@qq.com>
2023-04-03 11:05:33 +04:00
harry
b542086cbb add ChatCompletionStream Usage return (#215)
Co-authored-by: lihang <nasa.li@deepres.com>
2023-04-01 20:06:22 +04:00
rex posadas
8e3a04664e Refactor/internal testing (#194)
* added NoError check

* corrected NoError

* has error checks

* replace more checks

* Used checks test helper

* Used checks test helper

* remove duplicate import

* fixed lint issues regarding length of messages

---------

Co-authored-by: Rex Posadas <rposadas@redwoodlogistics.com>
2023-03-24 21:55:25 +04:00
rex posadas
479dab3b69 fixed typo (#196) 2023-03-23 23:18:11 +04:00
Élison Gomes
dbb7829a9f fix: added defer to close audio file (#195)
Co-authored-by: Élison Gomes <elisongomes@users.noreply.github.com>
2023-03-23 23:17:35 +04:00
Jo
2ebb265e71 refactor: Refactor endpoint and model compatibility check (#180)
* Add model check for chat stream

* Sync model checks

* Fix typo

* Fix functino

* refactor: Refactor endpoint and model compatibility check

* apply review suggestions

* minor fix

* invert return boolean flag

* fix test
2023-03-22 17:46:08 +04:00
kotaro.yamazaki
428839400a Update README.md to rename the image file created to example.png (#192) 2023-03-22 16:04:09 +04:00
sashabaranov
eb68a72bcc simplify unmarshal (#191)
* simplify unmarshal

* simplify unmarshalError

* rename errorAccumulate -> defaultErrorAccumulator

* update converage
2023-03-22 09:56:05 +04:00
Liu Shuang
a5a945ad14 fix: stream return EOF when openai return error (#184)
* fix: stream return EOF when openai return error

* perf: add error accumulator

* fix: golangci-lint

* fix: unmarshal error possibly null

* fix: error accumulator

* test: error accumulator use interface and add test code

* test: error accumulator add test code

* refactor: use stream reader to re-use stream code

* refactor: stream reader use generics
2023-03-22 09:32:47 +04:00
itegel
aa149c1bf8 add optional params for audio api, e.g. prompt (#183)
* Compatible with the situation where the mask is empty in CreateEditImage.

* Fix the test for the unnecessary removal of the mask.png file.

* add image variation implementation

* fix image variation bugs

* fix ci-lint problem with max line character limit

* add offitial doc link

* just for codeball test

* fix lint problem

* add optional params for audio api, e.g. prompt

* add comment for new args in translation
2023-03-20 14:02:19 +04:00
Ryuichi Maeda
d529d13ba1 Add readme example of ChatGPT streaming completion (#177) 2023-03-19 18:01:51 +04:00
sashabaranov
a6b35c3ab5 Check for Stream parameter usage (#174)
* check for stream:true usage

* lint
2023-03-18 19:31:54 +04:00