-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a custom task for downloading the API
- Loading branch information
1 parent
11c9eba
commit 028454e
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5c1857ea865e74e45e3b12064e0cc2396ef64be1 |
38 changes: 38 additions & 0 deletions
38
openai-client/generator/src/main/java/ai/xef/openai/generator/DownloadOpenAIAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ai.xef.openai.generator; | ||
|
||
import java.io.*; | ||
import java.net.URL; | ||
import java.nio.channels.Channels; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.channels.ReadableByteChannel; | ||
|
||
public class DownloadOpenAIAPI { | ||
public static void main(String[] args) { | ||
try { | ||
String commit = readCommit(); | ||
downloadAPI(commit); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static String readCommit() throws IOException { | ||
StringBuilder resultStringBuilder = new StringBuilder(); | ||
try (BufferedReader br = new BufferedReader(new FileReader("config/openai-api-commit"))) { | ||
String line; | ||
while ((line = br.readLine()) != null) { | ||
resultStringBuilder.append(line).append("\n"); | ||
} | ||
} | ||
return resultStringBuilder.toString().trim(); | ||
} | ||
|
||
private static void downloadAPI(String commit) throws IOException { | ||
URL url = new URL("https://raw.githubusercontent.com/openai/openai-openapi/%s/openapi.yaml".formatted(commit)); | ||
ReadableByteChannel readableByteChannel = Channels.newChannel(url.openStream()); | ||
try (FileOutputStream fileOutputStream = new FileOutputStream("config/openai-api.yaml")) { | ||
FileChannel fileChannel = fileOutputStream.getChannel(); | ||
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE); | ||
} | ||
} | ||
} |