Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
7d80695
feat: devcontainer, timestamp, relatedToEPFL
caviri Oct 1, 2025
6d69d3f
feat: expanding repository with API, Models, and Datasets
caviri Oct 1, 2025
f17465a
bug: correcting typo
caviri Oct 1, 2025
a5c9fe8
feat: version and new prompts
caviri Oct 3, 2025
ab62e9e
chore: new dockerfile location
caviri Oct 3, 2025
d68f3b2
Merge pull request #13 from Imaging-Plaza/repository-related-to-organ…
caviri Oct 3, 2025
5bf95b6
feat: cache implementation
caviri Oct 3, 2025
f3d97cf
feat: just file
caviri Oct 3, 2025
9302306
feat: Orcid attachment
caviri Oct 3, 2025
530ec82
bug: Problem in python version parsing
caviri Oct 3, 2025
792d9af
chore: simplified coroutine
caviri Oct 4, 2025
78ef91f
Merge pull request #14 from Imaging-Plaza/cache
caviri Oct 4, 2025
38362c2
feat: organization enrichment
caviri Oct 4, 2025
79b2270
feat: enrich_orgs available for organizations and users
caviri Oct 4, 2025
e58e743
feat: Optmized docker
caviri Oct 4, 2025
81ca6ce
feat: commits date, orcid fix
caviri Oct 4, 2025
cbaa066
bug: corrected issue with special tokens
caviri Oct 4, 2025
9d8c282
bug: max tokens & orcid ID
caviri Oct 5, 2025
fd354bb
bug: max_tokens compatibility and search issue
caviri Oct 6, 2025
9fb75f5
feat: Google search engine
caviri Oct 6, 2025
955d81e
feat: Better logging & API expansion
caviri Oct 6, 2025
defccbb
feat: memory optimization
caviri Oct 6, 2025
ff9beea
Merge pull request #16 from Imaging-Plaza/linter
caviri Oct 6, 2025
16e91b6
feat: Updated pydantic version and debug loging
caviri Oct 7, 2025
2426ce5
feat: folder structure refactor
caviri Oct 7, 2025
2c9820f
feat: new api architecture
caviri Oct 7, 2025
46a7e59
feat: stable /v1/repository/llm/json
caviri Oct 8, 2025
f72d434
bug: confidence score mis attributed
caviri Oct 8, 2025
0d4101d
feat: half llm request refactoring
caviri Oct 10, 2025
59ae3c2
refactor: repository llm json endpoint
caviri Oct 11, 2025
3a052e4
feat: rules, and functional repositories
caviri Oct 13, 2025
1aa026f
feat: repository new data model
caviri Oct 28, 2025
66240a4
feat: new repo 2 text strategy
caviri Oct 28, 2025
4259cb1
feat: infoscience integration
caviri Oct 28, 2025
4d4a551
feat: Token stats in api response
caviri Oct 29, 2025
fb70f31
docs: rules updated
caviri Oct 29, 2025
4547c5c
feat: Person data model refactor
caviri Oct 29, 2025
f6aecf5
feat: organization data model
caviri Oct 29, 2025
36cc248
feat: user llm
caviri Oct 30, 2025
68f19e6
feat: user and organization llm endpoints
caviri Oct 30, 2025
e5228ed
feat: user and repositories data models with proper justification of …
caviri Oct 31, 2025
7908100
feat: better epfl assignment prompts
caviri Oct 31, 2025
7a2f964
feat: json-ld
caviri Oct 31, 2025
744c1b9
Merge pull request #18 from Imaging-Plaza/pydantic-ai-update
caviri Nov 2, 2025
dc1f7c7
feat: academicCatalogsRelations
caviri Nov 2, 2025
c69405f
feat: add academic catalog enrichment and epfl assessment
caviri Nov 2, 2025
fcf183b
Merge pull request #19 from Imaging-Plaza/feat-infoscience-entities
caviri Nov 2, 2025
2c252ee
Refactor repository public access check and enhance API responses wit…
caviri Nov 5, 2025
d1061eb
Merge pull request #20 from Imaging-Plaza/bug-self-name
caviri Nov 5, 2025
f341fb6
bug: solved ROR validation
caviri Nov 5, 2025
2225544
feat: enhanced datamodel
caviri Nov 6, 2025
061263a
feat: removing deprecated affiliation field
caviri Nov 6, 2025
7fd9d48
feat: enforce uuid in infoscience entities
caviri Nov 6, 2025
dd5c611
feat: RCP EPFL model
caviri Nov 6, 2025
c80db19
Merge pull request #21 from Imaging-Plaza/feat/epfl-rcp
caviri Nov 6, 2025
f944e6f
Merge branch 'develop' into feat-links-validator
caviri Nov 6, 2025
370e63f
Merge pull request #22 from Imaging-Plaza/feat-links-validator
caviri Nov 6, 2025
999d59a
bug: hot fix for undefined type
caviri Nov 7, 2025
906f32b
feat: add vibecoded but working convert_json_jsonld.py
rmfranken Nov 11, 2025
404bc59
bug solved
caviri Nov 12, 2025
cb23439
Merge pull request #24 from Imaging-Plaza/bug/affiliation-hallucination
caviri Nov 12, 2025
187aa55
fix: support reverse mapping orgs and people too
rmfranken Nov 12, 2025
0923241
Merge branch 'develop' into json-to-rdf
rmfranken Nov 12, 2025
7bf27a7
feat: markdown only as context
caviri Nov 13, 2025
0145065
feat: add uploading and conversion scripting + readme. Update convers…
rmfranken Nov 13, 2025
aa7b79b
feat: large repositories
caviri Nov 13, 2025
e369a30
feat: pre-commit + gemini on devcontainer
caviri Nov 13, 2025
21cedb0
feat: cache storage based on workspace
caviri Nov 13, 2025
760f63e
feat: encrypted hash & gemini conf
caviri Nov 13, 2025
a96eb5e
feat: EPFL RCP and simplified agents workflow
caviri Nov 14, 2025
ba6cf2a
feat: simplify pydantic conversion
caviri Nov 14, 2025
803512a
feat: simple data model & affiliation object
caviri Nov 17, 2025
4559123
feat: source in Person and Organization
caviri Nov 17, 2025
979bf9d
feat: repository pipeline simplified
caviri Nov 17, 2025
74fff65
docs: rules updated
caviri Nov 17, 2025
c8e5155
feat: Improved token estimation
caviri Nov 17, 2025
44a5578
feat: organization endpoint refactor
caviri Nov 17, 2025
55a7c5b
Merge branch 'feat--optimizing-repo-files' into json-to-rdf
caviri Nov 18, 2025
de3b501
feat: update data directory path and enhance JSON-LD conversion handling
rmfranken Nov 19, 2025
0df57dc
bug: fix for users id & devcontainer
caviri Nov 24, 2025
380f25f
fix: deleting unused env var.
caviri Feb 16, 2026
6a5c186
feat: add agent operating guide and ORCID normalization utilities
caviri Feb 16, 2026
2a8dcc8
chore: remove Python 3.9 classifier from pyproject.toml
caviri Feb 16, 2026
0b4e035
Merge pull request #23 from Imaging-Plaza/json-to-rdf
caviri Feb 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions .cursor/plans/model-configuration-system-a15c577b.plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<!-- a15c577b-8dc6-4d03-8ff3-b6c4e48d5b84 d0755526-dc77-4303-8417-173bae94142e -->
# Model Configuration and Multi-Provider Support

## Overview

Implement a centralized model configuration system that allows configuring different providers and models for each analysis step (`run_llm_analysis`, `run_user_enrichment`, `run_organization_enrichment`) with automatic retry/fallback logic.

## Key Files to Modify

- **New file**: `src/llm/model_config.py` - Centralized configuration
- **New file**: `src/llm/repo_context.py` - Repository cloning and context generation logic
- **Modify**: `src/analysis/repositories.py` - Update analysis methods to use new config
- **Modify**: `src/llm/genai_model.py` - Refactor to PydanticAI with multi-provider support
- **Modify**: `src/agents/user_enrichment.py` - Use configurable models
- **Modify**: `src/agents/organization_enrichment.py` - Use configurable models

## Implementation Details

### 1. Create `src/llm/model_config.py`

Dictionary-based configuration structure:

```python
MODEL_CONFIGS = {
"run_llm_analysis": [
{
"provider": "openai",
"model": "gpt-4o",
"max_retries": 3,
"temperature": 0.2,
"max_tokens": 16000,
"timeout": 600.0,
},
{
"provider": "openrouter",
"model": "google/gemini-2.5-flash",
"max_retries": 3,
"temperature": 0.2,
"max_tokens": 16000,
"timeout": 300.0,
},
{
"provider": "ollama",
"model": "llama3.2",
"base_url": "http://localhost:11434",
"max_retries": 2,
"temperature": 0.3,
"timeout": 600.0,
},
],
"run_user_enrichment": [
{
"provider": "openai",
"model": "gpt-4o-mini",
"max_retries": 2,
"temperature": 0.1,
"max_tokens": 8000,
"timeout": 300.0,
},
],
"run_organization_enrichment": [
{
"provider": "openai",
"model": "gpt-4o-mini",
"max_retries": 2,
"temperature": 0.1,
"max_tokens": 8000,
"timeout": 300.0,
},
],
}
```

Supported parameters per provider:

- **All providers**: `model`, `max_retries`, `temperature`, `timeout`
- **OpenAI/OpenRouter/OpenAI-compatible**: `max_tokens`, `top_p`, `frequency_penalty`, `presence_penalty`
- **Ollama**: `num_predict` (equivalent to max_tokens), `top_k`, `top_p`
- **OpenAI reasoning models (o3, o4)**: `max_completion_tokens` (instead of max_tokens), no temperature
- **OpenAI-compatible**: `base_url`, `api_key_env` (name of env var containing API key)
- **Ollama**: `base_url` (defaults to http://localhost:11434)

Environment variable override support:

- `LLM_ANALYSIS_MODELS` - JSON array for run_llm_analysis models
- `USER_ENRICHMENT_MODELS` - JSON array for run_user_enrichment models
- `ORG_ENRICHMENT_MODELS` - JSON array for run_organization_enrichment models

Provider configurations:

- **OpenAI**: Standard OpenAI API
- **OpenRouter**: Via openrouter.ai endpoint
- **OpenAI-compatible**: Custom base_url endpoint
- **Ollama**: Support both local (localhost:11434) and remote URLs

### 2. Refactor `src/llm/genai_model.py`

Convert `llm_request_repo_infos` to use PydanticAI Agent pattern:

- Create PydanticAI agent for repository analysis
- Implement multi-provider model initialization
- Add retry logic with exponential backoff (2s, 4s, 8s)
- Fallback to next model in list after max retries exceeded
- Keep existing helper functions (clone_repo, extract_git_authors, etc.)

### 3. Initialize Agents at Module Load Time

**`src/llm/genai_model.py`**:

- Read "run_llm_analysis" config at module initialization
- Create PydanticAI agent with first model from config
- Implement retry/fallback wrapper that tries models in sequence
- No changes needed to `repositories.py` - just calls the same function

**`src/agents/user_enrichment.py`**:

- Read "run_user_enrichment" config at module initialization
- Replace hardcoded `agent = Agent(model=f"openai:{os.getenv('MODEL')}")` with config-driven initialization
- Wrap agent.run() with retry/fallback logic
- `enrich_users()` and `enrich_users_from_dict()` remain unchanged

**`src/agents/organization_enrichment.py`**:

- Read "run_organization_enrichment" config at module initialization
- Replace hardcoded `agent = Agent(model=f"openai:{os.getenv('MODEL')}")` with config-driven initialization
- Wrap agent.run() with retry/fallback logic
- `enrich_organizations()` and `enrich_organizations_from_dict()` remain unchanged

This approach means:

- Configuration is loaded once when modules are imported
- No changes needed to `repositories.py` or function signatures
- Agents are automatically configured based on model_config.py or env vars
- Retry/fallback logic is transparent to callers

## Retry Strategy

For each model in the list:

1. Try up to `max_retries` times (default: 3)
2. Use exponential backoff between retries: 2^attempt seconds (2s, 4s, 8s)
3. On max retries exceeded, move to next model in list
4. If all models fail, raise exception with detailed error info

## Provider Support Details

### OpenAI

- Use `pydantic_ai` with model string: `openai:gpt-4o`
- API key from `OPENAI_API_KEY` env var

### OpenRouter

- Use `pydantic_ai` with custom HTTP client pointing to openrouter.ai
- API key from `OPENROUTER_API_KEY` env var

### OpenAI-compatible

- Use `pydantic_ai` with custom base_url
- Config: `{"provider": "openai-compatible", "base_url": "...", "api_key_env": "..."}`

### Ollama

- Support local: `http://localhost:11434`
- Support remote: custom URL from config
- Use `pydantic_ai` with model string: `ollama:llama3.2`
- Config: `{"provider": "ollama", "model": "llama3.2", "base_url": "http://localhost:11434"}`

## Clean Break from Old Approach

- Remove support for old `MODEL` and `PROVIDER` env vars (except for backwards compatibility during transition)
- All configuration comes from `model_config.py` or the new env var format (JSON arrays)
- Simplify code by removing old OpenAI client initialization logic
- Remove deprecated functions: `get_openrouter_response()`, `get_openai_response()` (sync versions)
- Clean up `genai_model.py` by removing old pattern code

### To-dos

- [ ] Create src/llm/model_config.py with dictionary-based configuration structure and env var override support
- [ ] Implement provider-specific helper functions for OpenAI, OpenRouter, OpenAI-compatible, and Ollama (local and remote) in model_config.py
- [ ] Refactor llm_request_repo_infos in genai_model.py to use PydanticAI Agent with multi-provider support and retry/fallback logic
- [ ] Update user_enrichment.py to support dynamic model configuration with retry/fallback logic
- [ ] Update organization_enrichment.py to support dynamic model configuration with retry/fallback logic
- [ ] Update repositories.py analysis methods to load and pass model configurations from model_config.py
Loading