Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Add CONTRIBUTING.md and pull request template (#429)
Browse files Browse the repository at this point in the history
This should make adding new APIs clearer
  • Loading branch information
TheoKanning authored Dec 2, 2023
1 parent 41c14c6 commit 84d2af1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Thanks for submitting a pull request! Please check CONTRIBUTING.md for style guidelines.

### Changes
Describe your changes here

### New API Checklist
See CONTRIBUTING.md for more info.

1. [ ] Documentation for every variable
2. [ ] Class-level documentation
3. [ ] POJO JSON parsing tests
4. [ ] Service integration tests
27 changes: 27 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# How to Contribute

## How to Add a New API

### Add POJOs to API library
I usually have ChatGPT write them for me by copying and pasting from teh OpenAI API reference ([example chat](https://chat.openai.com/share/af48ef11-0354-40b2-a8e2-3bf8e93a94a3)), but double check everything because Chat always makes mistakes, especially around adding `@JsonProperty` annotations.

- Make all java variables camel case, and use `@JsonProperty` for fields that OpenAI returns as snake case
- Include comments for each variable, I take these directly from the OpenAI website
- Include `@Data` on every response class, and `@Builder @NoArgsConstructor @AllArgsConstructor @Data` on every request
- Include basic class-level documentation and a link to the OpenAI reference page, [example](api/src/main/java/com/theokanning/openai/threads/Thread.java)
- Add a JSON test for every new java object, this ensures that your definition and variable name overrides are correct.
- Copy the sample response from OpenAI into an api test [fixture](api/src/test/resources/fixtures)
- Add any missing fields to the JSON file (OpenAI doesn't always include everything)
- Add the class name to the test cases here [JSON test](api/src/test/java/com/theokanning/openai/JsonTest.java)

### Add to [OpenAiApi](client/src/main/java/com/theokanning/openai/client/OpenAiApi.java)
This is usually straightforward, use [OpenAiResponse](api/src/main/java/com/theokanning/openai/OpenAiResponse.java) for endpoints that return lists.

### Add to [OpenAiService](service/src/main/java/com/theokanning/openai/OpenAiService.java)

### Add an Integration Test
Since 99% of the work of this library is done on OpenAI's servers, the objective of these tests is to call each endpoint at least once.
Specify every available parameter to make sure that OpenAI accepts everything, but don't create extra test cases unless a parameter drastically affects the results.
For example, [CompletionTest](service/src/test/java/com/theokanning/openai/service/CompletionTest.java) has one test for normal completions, and one for streaming.

If your test relies on creating and retrieving external resources, [FineTuningTest](service/src/test/java/com/theokanning/openai/service/FineTuningTest.java) is a good example of how to share resources between tests and clean up afterwards.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
![Maven Central](https://img.shields.io/maven-central/v/com.theokanning.openai-gpt3-java/client?color=blue)

> ⚠️ Please switch to using the new 'service' library if you need to use OpenAiService. The old 'client' OpenAiService is deprecated as of 0.10.0.
> ⚠️OpenAI has deprecated all Engine-based APIs. See [Deprecated Endpoints](https://github.com/TheoKanning/openai-java#deprecated-endpoints) below for more info.
# OpenAI-Java
Expand All @@ -24,6 +23,7 @@ as well as an example project using the service.
- [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning)
- [Images](https://platform.openai.com/docs/api-reference/images)
- [Moderations](https://platform.openai.com/docs/api-reference/moderations)
- [Assistants](https://platform.openai.com/docs/api-reference/assistants)

#### Deprecated by OpenAI
- [Engines](https://platform.openai.com/docs/api-reference/engines)
Expand Down

0 comments on commit 84d2af1

Please sign in to comment.