Skip to content

Commit 25f9d64

Browse files
authored
Merge pull request #157 from rostilos/1.5.3-rc
feat: Add configurable timeout for OpenRouter embedding model
2 parents 0a44dc4 + 0fe1094 commit 25f9d64

4 files changed

Lines changed: 85 additions & 6 deletions

File tree

deployment/config/rag-pipeline/.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ REDIS_URL=redis://redis:6379/1
5050
#OLLAMA_BATCH_SIZE=100
5151

5252
## Request timeout in seconds (increase for slow CPU)
53+
#OPENROUTER_TIMEOUT=300
5354
#OLLAMA_TIMEOUT=120
5455

5556
## CPU Threading Optimization (set based on your CPU cores)

java-ecosystem/libs/vcs-client/src/main/java/org/rostilos/codecrow/vcsclient/gitlab/GitLabClient.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.net.URLEncoder;
1515
import java.nio.charset.StandardCharsets;
1616
import java.nio.file.Path;
17+
import java.time.OffsetDateTime;
18+
import java.time.format.DateTimeFormatter;
1719
import java.util.ArrayList;
1820
import java.util.List;
1921

@@ -498,6 +500,78 @@ public String getLatestCommitHash(String workspaceId, String repoIdOrSlug, Strin
498500
}
499501
}
500502

503+
@Override
504+
public List<VcsCommit> getCommitHistory(String workspaceId, String repoIdOrSlug, String branchOrCommit, int limit) throws IOException {
505+
String projectPath = workspaceId + "/" + repoIdOrSlug;
506+
String encodedPath = URLEncoder.encode(projectPath, StandardCharsets.UTF_8);
507+
String encodedRef = URLEncoder.encode(branchOrCommit, StandardCharsets.UTF_8);
508+
int perPage = Math.min(limit, 100); // GitLab max per_page is 100
509+
510+
String url = baseUrl + "/projects/" + encodedPath + "/repository/commits?ref_name=" + encodedRef + "&per_page=" + perPage;
511+
512+
List<VcsCommit> commits = new ArrayList<>();
513+
514+
while (url != null && commits.size() < limit) {
515+
Request request = createGetRequest(url);
516+
try (Response response = httpClient.newCall(request).execute()) {
517+
if (!response.isSuccessful()) {
518+
throw createException("get commit history", response);
519+
}
520+
521+
JsonNode root = objectMapper.readTree(response.body().string());
522+
if (root == null || !root.isArray()) break;
523+
524+
for (JsonNode commitNode : root) {
525+
if (commits.size() >= limit) break;
526+
527+
String hash = getTextOrNull(commitNode, "id");
528+
if (hash == null) continue;
529+
530+
String message = getTextOrNull(commitNode, "message");
531+
String authorName = getTextOrNull(commitNode, "author_name");
532+
String authorEmail = getTextOrNull(commitNode, "author_email");
533+
OffsetDateTime timestamp = null;
534+
535+
String dateStr = getTextOrNull(commitNode, "authored_date");
536+
if (dateStr != null) {
537+
try {
538+
timestamp = OffsetDateTime.parse(dateStr, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
539+
} catch (Exception e) {
540+
log.debug("Could not parse commit date '{}': {}", dateStr, e.getMessage());
541+
}
542+
}
543+
544+
List<String> parentHashes = new ArrayList<>();
545+
JsonNode parentsArray = commitNode.get("parent_ids");
546+
if (parentsArray != null && parentsArray.isArray()) {
547+
for (JsonNode parentId : parentsArray) {
548+
if (!parentId.isNull()) {
549+
parentHashes.add(parentId.asText());
550+
}
551+
}
552+
}
553+
554+
commits.add(new VcsCommit(hash, message, authorName, authorEmail, timestamp, parentHashes));
555+
}
556+
557+
// Follow pagination via Link header or X-Next-Page
558+
if (commits.size() < limit) {
559+
String nextPage = response.header("X-Next-Page");
560+
if (nextPage != null && !nextPage.isEmpty()) {
561+
url = baseUrl + "/projects/" + encodedPath + "/repository/commits?ref_name=" + encodedRef
562+
+ "&per_page=" + perPage + "&page=" + nextPage;
563+
} else {
564+
url = null;
565+
}
566+
} else {
567+
url = null;
568+
}
569+
}
570+
}
571+
572+
return commits;
573+
}
574+
501575
@Override
502576
public String getBranchDiff(String workspaceId, String repoIdOrSlug, String baseBranch, String compareBranch) throws IOException {
503577
// GitLab: GET /projects/:id/repository/compare

python-ecosystem/rag-pipeline/src/rag_pipeline/core/embedding_factory.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
import logging
7+
import os
78
from typing import Union
89

910
from llama_index.core.base.embeddings.base import BaseEmbedding
@@ -28,31 +29,34 @@ def create_embedding_model(config: RAGConfig) -> BaseEmbedding:
2829
provider = config.embedding_provider.lower()
2930

3031
if provider == "ollama":
31-
logger.info(f"Creating Ollama embedding model: {config.ollama_model}")
32+
timeout = float(os.getenv("OLLAMA_TIMEOUT", "120"))
33+
logger.info(f"Creating Ollama embedding model: {config.ollama_model} (timeout={timeout}s)")
3234
return OllamaEmbedding(
3335
model=config.ollama_model,
3436
base_url=config.ollama_base_url,
35-
timeout=120.0,
37+
timeout=timeout,
3638
expected_dim=config.embedding_dim
3739
)
3840

3941
elif provider == "openrouter":
40-
logger.info(f"Creating OpenRouter embedding model: {config.openrouter_model}")
42+
timeout = float(os.getenv("OPENROUTER_TIMEOUT", "300"))
43+
logger.info(f"Creating OpenRouter embedding model: {config.openrouter_model} (timeout={timeout}s)")
4144
return OpenRouterEmbedding(
4245
api_key=config.openrouter_api_key,
4346
model=config.openrouter_model,
4447
api_base=config.openrouter_base_url,
45-
timeout=60.0,
48+
timeout=timeout,
4649
max_retries=3,
4750
expected_dim=config.embedding_dim
4851
)
4952

5053
else:
5154
logger.warning(f"Unknown embedding provider '{provider}', defaulting to Ollama")
55+
timeout = float(os.getenv("OLLAMA_TIMEOUT", "120"))
5256
return OllamaEmbedding(
5357
model=config.ollama_model,
5458
base_url=config.ollama_base_url,
55-
timeout=120.0,
59+
timeout=timeout,
5660
expected_dim=config.embedding_dim
5761
)
5862

python-ecosystem/rag-pipeline/src/rag_pipeline/core/openrouter_embedding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(
3636
api_key: str,
3737
model: str = "openai/text-embedding-3-small",
3838
api_base: str = "https://openrouter.ai/api/v1",
39-
timeout: float = 60.0,
39+
timeout: float = float(os.getenv("OPENROUTER_TIMEOUT", "300")),
4040
max_retries: int = 3,
4141
embed_batch_size: int = EMBEDDING_BATCH_SIZE,
4242
expected_dim: Optional[int] = None,

0 commit comments

Comments
 (0)