Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
izzat5233 committed Jun 27, 2023
1 parent 5efaa8f commit cfc9f44
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.List;

/**
* OpenAI chat completion maps to this exact object.
*/
public record Response(
String id,
String object,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package com.izzatalsharif.openai.chatagent.config;

import com.izzatalsharif.openai.chatagent.util.FileUtility;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.ResourceLoader;

import java.io.IOException;
import java.nio.file.Files;

@RequiredArgsConstructor
@Configuration
@Import(FileUtility.class)
public class RequestsConfig {

@Autowired
private FileUtility fileUtility;
private final ResourceLoader resourceLoader;

private String readFile(String resourcePath) throws IOException {
var resource = resourceLoader.getResource("classpath:" + resourcePath);
var path = resource.getFile().toPath();
return Files.readString(path);
}

/**
* @return A simple invalid request that chat completion rejects.
Expand All @@ -28,7 +35,7 @@ public String badRequest() {
*/
@Bean
public String validRequest() throws IOException {
return fileUtility.readFile("agent/simpleRequest.json");
return readFile("agent/simpleRequest.json");
}

/**
Expand All @@ -38,7 +45,7 @@ public String validRequest() throws IOException {
*/
@Bean
public String testAgentRequest() throws IOException {
return fileUtility.readFile("agent/testAgent.json");
return readFile("agent/testAgent.json");
}

}

0 comments on commit cfc9f44

Please sign in to comment.