Skip to content

Commit

Permalink
Fixing Bugs (#181)
Browse files Browse the repository at this point in the history
* Fixing Bugs

* Fixing Bugs
  • Loading branch information
EmadHanif01 authored Aug 4, 2023
1 parent 728bd57 commit 53895b0
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 35 deletions.
6 changes: 6 additions & 0 deletions FlySpring/edgechain-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
<version>2.0.1.Final</version>
</dependency>

<dependency>
<groupId>com.github.f4b6a3</groupId>
<artifactId>uuid-creator</artifactId>
<version>5.2.0</version>
</dependency>

<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class PineconeRetrieval extends Retrieval {

private final Logger logger = LoggerFactory.getLogger(getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class RedisRetrieval extends Retrieval {

private final Logger logger = LoggerFactory.getLogger(getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
Expand All @@ -10,6 +11,7 @@
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import redis.clients.jedis.JedisPooled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.edgechain.lib.endpoint.impl.PostgresEndpoint;
import com.edgechain.lib.index.enums.PostgresDistanceMetric;
import com.edgechain.lib.utils.FloatUtils;
import com.github.f4b6a3.uuid.UuidCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void upsertEmbeddings(
+ " '%s', '%s', '%s', '%s', '%s') ON CONFLICT (raw_text) DO UPDATE SET embedding ="
+ " EXCLUDED.embedding;",
tableName,
UUID.randomUUID(),
UuidCreator.getTimeOrderedEpoch().toString(),
input,
Arrays.toString(FloatUtils.toFloatArray(wordEmbeddings.getValues())),
LocalDateTime.now(),
Expand All @@ -64,7 +65,7 @@ public List<Map<String, Object>> query(

return jdbcTemplate.queryForList(
String.format(
"SELECT id, raw_text, namespace, timestamp FROM %s WHERE namespace='%s' ORDER BY"
"SELECT id, raw_text, namespace, filename, timestamp FROM %s WHERE namespace='%s' ORDER BY"
+ " embedding %s '%s' LIMIT %s;",
tableName,
namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
Expand All @@ -31,7 +30,6 @@ public class JwtFilter extends OncePerRequestFilter {

@Autowired private SecurityUUID securityUUID;

@Autowired private Environment env;

@Override
protected void doFilterInternal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public Jws<Claims> parseToken(String accessToken) {
new SecretKeySpec(
env.getProperty("jwt.secret").getBytes(), SignatureAlgorithm.HS256.getJcaName());


return Jwts.parser().setSigningKey(hmacKey).parseClaimsJws(accessToken);

} catch (MalformedJwtException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ public class AuthUtils {

public static String extractToken(HttpServletRequest request) {
String header = request.getHeader("Authorization");
if (header != null && header.startsWith("Bearer")) return header.replace("Bearer ", "");
if (header != null && header.startsWith("Bearer"))
return header.replace("Bearer ", "");

return null;
}


public static String extractToken(ArkRequest request) {
String header = request.getHeader("Authorization");
if (header != null && header.startsWith("Bearer")) return header.replace("Bearer ", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
@RequestMapping(value = WebConfiguration.CONTEXT_PATH + "/index/pinecone")
public class PineconeController {

@Autowired private PineconeClient pineconeClient;
@Autowired
private PineconeClient pineconeClient;

@PostMapping("/upsert")
public Single<StringResponse> upsert(@RequestBody PineconeEndpoint pineconeEndpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
@RequestMapping(value = WebConfiguration.CONTEXT_PATH + "/index/postgres")
public class PostgresController {

@Autowired @Lazy private PostgresClient postgresClient;
@Autowired
@Lazy
private PostgresClient postgresClient;

@PostMapping("/upsert")
public Single<StringResponse> upsert(@RequestBody PostgresEndpoint postgresEndpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,42 @@
@RequestMapping(value = WebConfiguration.CONTEXT_PATH + "/index/redis")
public class RedisController {

@Autowired @Lazy private RedisClient redisClient;
@Autowired
@Lazy
private RedisClient redisClient;

@PostMapping("/upsert")
public Single<StringResponse> upsert(@RequestBody RedisEndpoint redisEndpoint) {
@PostMapping("/upsert")
public Single<StringResponse> upsert(@RequestBody RedisEndpoint redisEndpoint) {

this.redisClient.setEndpoint(redisEndpoint);
this.redisClient.setEndpoint(redisEndpoint);

EdgeChain<StringResponse> edgeChain =
this.redisClient.upsert(
redisEndpoint.getWordEmbeddings(),
redisEndpoint.getDimensions(),
redisEndpoint.getMetric());
EdgeChain<StringResponse> edgeChain =
this.redisClient.upsert(
redisEndpoint.getWordEmbeddings(),
redisEndpoint.getDimensions(),
redisEndpoint.getMetric());

return edgeChain.toSingle();
}
return edgeChain.toSingle();
}

@PostMapping("/query")
public Single<List<WordEmbeddings>> query(@RequestBody RedisEndpoint redisEndpoint) {
@PostMapping("/query")
public Single<List<WordEmbeddings>> query(@RequestBody RedisEndpoint redisEndpoint) {

this.redisClient.setEndpoint(redisEndpoint);
this.redisClient.setEndpoint(redisEndpoint);

EdgeChain<List<WordEmbeddings>> edgeChain =
this.redisClient.query(redisEndpoint.getWordEmbeddings(), redisEndpoint.getTopK());
EdgeChain<List<WordEmbeddings>> edgeChain =
this.redisClient.query(redisEndpoint.getWordEmbeddings(), redisEndpoint.getTopK());

return edgeChain.toSingle();
}
return edgeChain.toSingle();
}

@DeleteMapping("/delete")
public Completable deleteByPattern(
@RequestParam("pattern") String pattern, @RequestBody RedisEndpoint redisEndpoint) {
@DeleteMapping("/delete")
public Completable deleteByPattern(
@RequestParam("pattern") String pattern, @RequestBody RedisEndpoint redisEndpoint) {

this.redisClient.setEndpoint(redisEndpoint);
this.redisClient.setEndpoint(redisEndpoint);

EdgeChain<StringResponse> edgeChain = this.redisClient.deleteByPattern(pattern);
return edgeChain.await();
}
EdgeChain<StringResponse> edgeChain = this.redisClient.deleteByPattern(pattern);
return edgeChain.await();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Single<ChatCompletionResponse> chatCompletion(@RequestBody OpenAiEndpoint
EdgeChain<ChatCompletionResponse> edgeChain =
openAiClient.createChatCompletion(chatCompletionRequest);

if (Objects.nonNull(env.getProperty("postgres.db.host"))) {
if (Objects.nonNull(env.getProperty("postgres.db.host"))) {

ChatCompletionLog chatCompletionLog = new ChatCompletionLog();
chatCompletionLog.setName(openAiEndpoint.getChainName());
Expand Down Expand Up @@ -119,7 +119,7 @@ public SseEmitter chatCompletionStream(@RequestBody OpenAiEndpoint openAiEndpoin

AtomInteger chunks = AtomInteger.of(0);

if (Objects.nonNull(env.getProperty("postgres.db.host"))) {
if (Objects.nonNull(env.getProperty("postgres.db.host"))) {

ChatCompletionLog chatCompletionLog = new ChatCompletionLog();
chatCompletionLog.setName(openAiEndpoint.getChainName());
Expand Down Expand Up @@ -224,7 +224,7 @@ public Single<OpenAiEmbeddingResponse> embeddings(@RequestBody OpenAiEndpoint op
openAiClient.createEmbeddings(
new OpenAiEmbeddingRequest(openAiEndpoint.getModel(), openAiEndpoint.getInput()));

if (Objects.nonNull(env.getProperty("postgres.db.host"))) {
if (Objects.nonNull(env.getProperty("postgres.db.host"))) {

EmbeddingLog embeddingLog = new EmbeddingLog();
embeddingLog.setCreatedAt(LocalDateTime.now());
Expand Down

0 comments on commit 53895b0

Please sign in to comment.