Skip to content

Commit

Permalink
Fixing and improving...
Browse files Browse the repository at this point in the history
  • Loading branch information
mzattera committed May 13, 2024
1 parent 010d0be commit e6c9cae
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion eclipse/predictive-powers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<!-- Library versions -->
<jackson.version>2.15.3</jackson.version>
<jackson.jsonschema.version>1.0.39</jackson.jsonschema.version>
<lombok.version>1.18.26</lombok.version>
<lombok.version>1.18.32</lombok.version>
<retrofit.version>2.9.0</retrofit.version>
<tika.version>2.9.0</tika.version>
<djl.tokenizers.version>0.26.0</djl.tokenizers.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static OkHttpClient getDefaultHttpClient(int readTimeoutMillis, int maxRe
if (readTimeoutMillis < 0)
throw new IllegalArgumentException("Read time out must be >= 0");
if (keepAliveDurationMillis < 0)
throw new IllegalArgumentException("Keep alive druaation out be >= 0");
throw new IllegalArgumentException("Keep alive duration must be >= 0");
if (maxIdleConnectionsMillis < 0)
throw new IllegalArgumentException("Max idel connections must must be >= 0");

Expand All @@ -99,9 +99,11 @@ public Response intercept(Chain chain) throws IOException {
// System.out.println("SERVER BUSY check: " + (retries < maxRetries) + " timeOut:" + readTimeoutMillis
// + " elapsed: " + elapsed + " " + (readTimeoutMillis <= elapsed));

// TODO URGENT check list of OpenAI, Anthropic and Hugging face errors and let client customize accordingly.

while ((retries < maxRetries) && ((readTimeoutMillis == 0) || (elapsed < readTimeoutMillis))
&& ((response.code() == 429) || (response.code() == 500) || (response.code() == 503)
|| (response.code() == 504))) {
|| (response.code() == 504)|| (response.code() == 529))) {

// Waits and retries as server is temporarily unavailable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,7 @@ public void setMaxNewTokens(Integer maxNewTokens) {
defaultReq.setMaxTokens(maxNewTokens);
}

/**
* This method counts number of tokens that are consumed at each request to
* provide bot instructions (personality). This is the minimum size each request
* to the API will take.
*/
@Override
public int getBaseTokens() {
// Instructions tokens
String cmd = getPersonality();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ public ToolCallResult invoke(@NonNull ToolCall call) throws Exception {
}
}

// TODO URGENT Below code is to test the tokenizer; remove it.

// Capability providing the functions to the agent
private final static Capability DEFAULT_CAPABILITY = new Toolset();
static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public void setMaxNewTokens(Integer maxNewTokens) {
defaultReq.getParameters().setMaxLength(maxNewTokens);
}

@Override
public int getBaseTokens() {
return 0;
}

@Override
public ChatCompletion chat(String msg) {
return chat(msg, defaultReq);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,7 @@ public void setMaxNewTokens(Integer maxNewTokens) {
defaultReq.setMaxTokens(maxNewTokens);
}

/**
* This method counts number of tokens that are consumed at each request to
* provide bot instructions (personality) and list tools it can use. This is the
* minimum size each request to the API will take. In addition, each request
* will consume the tokens needed to encode messages, which include tool calls
* and their corresponding replies.
*
* @return Number of tokens in the request including bot personality and tools
* (functions) descriptions, but excluding any other message.
*/
@Override
public int getBaseTokens() {
List<OpenAiChatMessage> old = defaultReq.getMessages();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ public interface ChatService extends AiService {
*/
void setMaxNewTokens(Integer maxNewTokens);

/**
* This method returns number of tokens that are consumed at each request to
* provide directions (e.g. personality) to this service. This is the minimum
* token size of each request to the API, in addition to token consumed by
* messages.
*/
public int getBaseTokens();

/**
* Starts a new chat, clearing current conversation.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
*
*/
package io.github.mzattera.util;

import java.util.concurrent.atomic.AtomicLong;

/**
* Generates unique long IDs.
* IDs are guaranteed to be unique inside the JVM.ight not be unique over subsequent runs.
*/
public final class IdUtil {

private static final AtomicLong counter = new AtomicLong(System.nanoTime());

private IdUtil() {
}

public static long getLongId() {
return counter.getAndIncrement();
}

public static String getStringId() {
return Long.toString(getLongId());
}
}

0 comments on commit e6c9cae

Please sign in to comment.