Jacek Zadrożny commited on
Commit
f9779bd
·
1 Parent(s): 68287f9

Zamiana OPENAI_API_KEY na GITHUB_TOKEN w kodzie, dokumentacji i konfiguracji

Browse files
.env.example CHANGED
@@ -1,5 +1,5 @@
1
- # OpenAI API Configuration (Required)
2
- OPENAI_API_KEY=your_api_key_here
3
 
4
  # LLM Configuration
5
  LLM_MODEL=gpt-4o
 
1
+ # GitHub Token Configuration (Required)
2
+ GITHUB_TOKEN=your_token_here
3
 
4
  # LLM Configuration
5
  LLM_MODEL=gpt-4o
CLAUDE.md CHANGED
@@ -25,7 +25,7 @@ pip install -r requirements.txt
25
 
26
  # Configure environment
27
  cp .env.example .env
28
- # Then edit .env and add your OPENAI_API_KEY
29
  ```
30
 
31
  ### Database Management
@@ -90,7 +90,7 @@ python -c "import lancedb; db = lancedb.connect('./lancedb'); print(len(db.open_
90
  - `demo.queue()` must be called explicitly (see app.py:238-243)
91
  - Do NOT use `atexit.register()` for cleanup (causes premature shutdown)
92
  - LanceDB is read-only; must be tracked with Git LFS
93
- - API key stored as HF Spaces Secret: `OPENAI_API_KEY`
94
  - The `if __name__ == "__main__"` block handles both local and HF deployments
95
 
96
  ### LanceDB Database
@@ -112,7 +112,7 @@ The agent has **strict language enforcement**:
112
  ### Configuration
113
 
114
  All settings in `config.py` are loaded from environment variables:
115
- - `OPENAI_API_KEY` (required)
116
  - `LLM_MODEL` (default: gpt-4o)
117
  - `LLM_BASE_URL` (optional, supports GitHub Models)
118
  - `EMBEDDING_MODEL` (default: text-embedding-3-large)
 
25
 
26
  # Configure environment
27
  cp .env.example .env
28
+ # Then edit .env and add your GITHUB_TOKEN
29
  ```
30
 
31
  ### Database Management
 
90
  - `demo.queue()` must be called explicitly (see app.py:238-243)
91
  - Do NOT use `atexit.register()` for cleanup (causes premature shutdown)
92
  - LanceDB is read-only; must be tracked with Git LFS
93
+ - Token stored as HF Spaces Secret: `GITHUB_TOKEN`
94
  - The `if __name__ == "__main__"` block handles both local and HF deployments
95
 
96
  ### LanceDB Database
 
112
  ### Configuration
113
 
114
  All settings in `config.py` are loaded from environment variables:
115
+ - `GITHUB_TOKEN` (required)
116
  - `LLM_MODEL` (default: gpt-4o)
117
  - `LLM_BASE_URL` (optional, supports GitHub Models)
118
  - `EMBEDDING_MODEL` (default: text-embedding-3-large)
HF_SPACES_GUIDE.md CHANGED
@@ -36,7 +36,7 @@
36
  W ustawieniach Space → Settings → Repository secrets:
37
 
38
  ```
39
- Name: OPENAI_API_KEY
40
  Value: sk-proj-... (twój klucz)
41
  ```
42
 
@@ -105,7 +105,7 @@ Running on public URL: https://...
105
 
106
  ### ❌ Jeśli widzisz błędy:
107
 
108
- #### Error: "OPENAI_API_KEY is required"
109
  **Rozwiązanie:** Dodaj klucz w Secrets (Krok 2B)
110
 
111
  #### Error: "Table 'a11y_expert' doesn't exist"
@@ -194,7 +194,7 @@ Przed ogłoszeniem Space jako "Production Ready":
194
  - [ ] Język jest wykrywany prawidłowo
195
  - [ ] Przykładowe pytania działają
196
  - [ ] Brak ostrzeżeń w logach
197
- - [ ] OPENAI_API_KEY jest w Secrets (NIE w kodzie!)
198
  - [ ] README.md jest czytelny i informacyjny
199
  - [ ] Space ma odpowiedni tytuł i opis
200
 
 
36
  W ustawieniach Space → Settings → Repository secrets:
37
 
38
  ```
39
+ Name: GITHUB_TOKEN
40
  Value: sk-proj-... (twój klucz)
41
  ```
42
 
 
105
 
106
  ### ❌ Jeśli widzisz błędy:
107
 
108
+ #### Error: "GITHUB_TOKEN is required"
109
  **Rozwiązanie:** Dodaj klucz w Secrets (Krok 2B)
110
 
111
  #### Error: "Table 'a11y_expert' doesn't exist"
 
194
  - [ ] Język jest wykrywany prawidłowo
195
  - [ ] Przykładowe pytania działają
196
  - [ ] Brak ostrzeżeń w logach
197
+ - [ ] GITHUB_TOKEN jest w Secrets (NIE w kodzie!)
198
  - [ ] README.md jest czytelny i informacyjny
199
  - [ ] Space ma odpowiedni tytuł i opis
200
 
QUICK_REFERENCE.md CHANGED
@@ -58,7 +58,7 @@ python app.py
58
  ### 1. Secrets (KRYTYCZNE!)
59
  ```
60
  Settings → Repository secrets
61
- Name: OPENAI_API_KEY
62
  Value: sk-proj-...
63
  ```
64
 
@@ -91,7 +91,7 @@ app_file: app.py
91
  | Błąd | Rozwiązanie |
92
  |------|-------------|
93
  | "Event loop is closed" | Użyj zaktualizowanego `app.py` |
94
- | "OPENAI_API_KEY is required" | Dodaj klucz w HF Secrets |
95
  | "Table doesn't exist" | Upload folder `lancedb/` |
96
  | Pydantic validation error | Sprawdź `.env` lub HF Secrets |
97
 
@@ -99,7 +99,7 @@ app_file: app.py
99
 
100
  - [ ] `python test_startup.py` - wszystkie testy ✅
101
  - [ ] Wszystkie pliki skommitowane (oprócz `.env`, `cache/`)
102
- - [ ] OPENAI_API_KEY w HF Secrets
103
  - [ ] README.md ma poprawny YAML header
104
  - [ ] Folder `lancedb/` jest w repo (Git LFS dla >10MB)
105
 
 
58
  ### 1. Secrets (KRYTYCZNE!)
59
  ```
60
  Settings → Repository secrets
61
+ Name: GITHUB_TOKEN
62
  Value: sk-proj-...
63
  ```
64
 
 
91
  | Błąd | Rozwiązanie |
92
  |------|-------------|
93
  | "Event loop is closed" | Użyj zaktualizowanego `app.py` |
94
+ | "GITHUB_TOKEN is required" | Dodaj token w HF Secrets |
95
  | "Table doesn't exist" | Upload folder `lancedb/` |
96
  | Pydantic validation error | Sprawdź `.env` lub HF Secrets |
97
 
 
99
 
100
  - [ ] `python test_startup.py` - wszystkie testy ✅
101
  - [ ] Wszystkie pliki skommitowane (oprócz `.env`, `cache/`)
102
+ - [ ] GITHUB_TOKEN w HF Secrets
103
  - [ ] README.md ma poprawny YAML header
104
  - [ ] Folder `lancedb/` jest w repo (Git LFS dla >10MB)
105
 
README.md CHANGED
@@ -36,7 +36,7 @@ Inteligentny agent AI wyspecjalizowany w dostępności cyfrowej (a11y), wykorzys
36
  ### 1. Wymagania wstępne
37
 
38
  - Python 3.10+
39
- - Klucz API OpenAI
40
 
41
  ### 2. Instalacja lokalna
42
 
@@ -56,10 +56,10 @@ Inteligentny agent AI wyspecjalizowany w dostępności cyfrowej (a11y), wykorzys
56
  ```bash
57
  cp .env.example .env
58
  ```
59
- - Otwórz plik `.env` i wklej swój klucz API OpenAI:
60
- ```
61
- OPENAI_API_KEY="sk-..."
62
- ```
63
 
64
  4. **Uruchom aplikację:**
65
  ```bash
@@ -82,7 +82,7 @@ Aplikacja jest skonfigurowana do wdrożenia jako Gradio App na Hugging Face Spac
82
 
83
  ### 1. Konfiguracja w Hugging Face
84
 
85
- - W ustawieniach swojego Space, w sekcji **Secrets**, dodaj sekret o nazwie `OPENAI_API_KEY` i wklej swój klucz API.
86
 
87
  ### 2. Kluczowe aspekty wdrożenia
88
 
 
36
  ### 1. Wymagania wstępne
37
 
38
  - Python 3.10+
39
+ - Token GitHub (GITHUB_TOKEN)
40
 
41
  ### 2. Instalacja lokalna
42
 
 
56
  ```bash
57
  cp .env.example .env
58
  ```
59
+ - Otwórz plik `.env` i wklej swój token GitHub:
60
+ ```
61
+ GITHUB_TOKEN="ghp_..."
62
+ ```
63
 
64
  4. **Uruchom aplikację:**
65
  ```bash
 
82
 
83
  ### 1. Konfiguracja w Hugging Face
84
 
85
+ - W ustawieniach swojego Space, w sekcji **Secrets**, dodaj sekret o nazwie `GITHUB_TOKEN` i wklej swój token GitHub.
86
 
87
  ### 2. Kluczowe aspekty wdrożenia
88
 
TODO_DEPLOYMENT.md CHANGED
@@ -85,7 +85,7 @@ Fixes #[issue_number] - App closing on Hugging Face Spaces"
85
  ### 2. Dodaj Secret (NAJWAŻNIEJSZE!)
86
  - [ ] Przejdź do Settings → Repository secrets
87
  - [ ] Kliknij "Add a secret"
88
- - [ ] Nazwa: `OPENAI_API_KEY`
89
  - [ ] Wartość: Twój klucz OpenAI (sk-proj-...)
90
  - [ ] Zapisz
91
 
@@ -142,7 +142,7 @@ Running on public URL: https://...hf.space
142
  ```
143
 
144
  - [ ] Sprawdź czy NIE MA błędów:
145
- - ❌ "OPENAI_API_KEY is required" → Dodaj Secret!
146
  - ❌ "RuntimeError: Event loop is closed" → Użyj zaktualizowanego app.py
147
  - ❌ "Table doesn't exist" → Upload lancedb/ folder
148
 
@@ -206,7 +206,7 @@ Running on public URL: https://...hf.space
206
 
207
  Jeśli coś nie działa, sprawdź:
208
 
209
- 1. **OPENAI_API_KEY** - czy jest dodany w Secrets?
210
  2. **Logi** - jakie błędy są w logach?
211
  3. **requirements.txt** - czy wszystkie biblioteki są zainstalowane?
212
  4. **Python version** - czy w README.md jest `python_version: 3.10`?
@@ -216,7 +216,7 @@ Jeśli coś nie działa, sprawdź:
216
 
217
  | Problem | Fix |
218
  |---------|-----|
219
- | "API key required" | Dodaj OPENAI_API_KEY w Secrets |
220
  | "Event loop closed" | Re-upload app.py z tego repo |
221
  | "Table doesn't exist" | Upload lancedb/ folder |
222
  | Space crashes | Sprawdź logi, może brak pamięci |
 
85
  ### 2. Dodaj Secret (NAJWAŻNIEJSZE!)
86
  - [ ] Przejdź do Settings → Repository secrets
87
  - [ ] Kliknij "Add a secret"
88
+ - [ ] Nazwa: `GITHUB_TOKEN`
89
  - [ ] Wartość: Twój klucz OpenAI (sk-proj-...)
90
  - [ ] Zapisz
91
 
 
142
  ```
143
 
144
  - [ ] Sprawdź czy NIE MA błędów:
145
+ - ❌ "GITHUB_TOKEN is required" → Dodaj Secret!
146
  - ❌ "RuntimeError: Event loop is closed" → Użyj zaktualizowanego app.py
147
  - ❌ "Table doesn't exist" → Upload lancedb/ folder
148
 
 
206
 
207
  Jeśli coś nie działa, sprawdź:
208
 
209
+ 1. **GITHUB_TOKEN** - czy jest dodany w Secrets?
210
  2. **Logi** - jakie błędy są w logach?
211
  3. **requirements.txt** - czy wszystkie biblioteki są zainstalowane?
212
  4. **Python version** - czy w README.md jest `python_version: 3.10`?
 
216
 
217
  | Problem | Fix |
218
  |---------|-----|
219
+ | "Token required" | Dodaj GITHUB_TOKEN w Secrets |
220
  | "Event loop closed" | Re-upload app.py z tego repo |
221
  | "Table doesn't exist" | Upload lancedb/ folder |
222
  | Space crashes | Sprawdź logi, może brak pamięci |
agent/__pycache__/__init__.cpython-312.pyc CHANGED
Binary files a/agent/__pycache__/__init__.cpython-312.pyc and b/agent/__pycache__/__init__.cpython-312.pyc differ
 
agent/__pycache__/a11y_agent.cpython-312.pyc CHANGED
Binary files a/agent/__pycache__/a11y_agent.cpython-312.pyc and b/agent/__pycache__/a11y_agent.cpython-312.pyc differ
 
agent/__pycache__/prompts.cpython-312.pyc CHANGED
Binary files a/agent/__pycache__/prompts.cpython-312.pyc and b/agent/__pycache__/prompts.cpython-312.pyc differ
 
agent/__pycache__/tools.cpython-312.pyc CHANGED
Binary files a/agent/__pycache__/tools.cpython-312.pyc and b/agent/__pycache__/tools.cpython-312.pyc differ
 
agent/a11y_agent.py CHANGED
@@ -256,13 +256,12 @@ def create_agent(language: Optional[str] = None) -> A11yExpertAgent:
256
  logger.info("Initializing vector store client...")
257
  vector_store = VectorStoreClient(uri=settings.lancedb_uri)
258
 
259
- api_key = settings.openai_api_key
260
-
261
  logger.info("Initializing OpenAI client...")
262
- client_args = {"api_key": api_key}
263
  if settings.llm_base_url:
264
  client_args["base_url"] = settings.llm_base_url
265
-
266
  llm_client = OpenAI(**client_args)
267
 
268
  logger.info("Creating A11yExpertAgent instance...")
 
256
  logger.info("Initializing vector store client...")
257
  vector_store = VectorStoreClient(uri=settings.lancedb_uri)
258
 
259
+ github_token = settings.github_token
260
+
261
  logger.info("Initializing OpenAI client...")
262
+ client_args = {"api_key": github_token}
263
  if settings.llm_base_url:
264
  client_args["base_url"] = settings.llm_base_url
 
265
  llm_client = OpenAI(**client_args)
266
 
267
  logger.info("Creating A11yExpertAgent instance...")
config.py CHANGED
@@ -16,8 +16,8 @@ class Settings(BaseSettings):
16
  """
17
  Application settings loaded from environment variables or .env file.
18
 
19
- All settings have sensible defaults except for the OpenAI API key,
20
- which must be provided via the OPENAI_API_KEY environment variable.
21
 
22
  Attributes:
23
  openai_api_key: OpenAI API key (required)
@@ -39,10 +39,10 @@ class Settings(BaseSettings):
39
  """
40
 
41
  # API Configuration (required)
42
- openai_api_key: str = Field(
43
  default="",
44
- description="OpenAI API key - required for LLM and embeddings",
45
- validation_alias="OPEN_API_KEY" # Also accept OPEN_API_KEY (common typo)
46
  )
47
 
48
  # LLM Configuration
@@ -107,17 +107,17 @@ class Settings(BaseSettings):
107
  description="Public URL for social media sharing"
108
  )
109
 
110
- @field_validator("openai_api_key")
111
  @classmethod
112
- def validate_api_key(cls, v):
113
- """Ensure API key is provided and not empty."""
114
  v = v or ""
115
  v = v.strip()
116
  if not v:
117
  import os
118
  if not os.getenv("SPACE_ID"):
119
  raise ValueError(
120
- "OPENAI_API_KEY is required. "
121
  "Set it in your .env file or environment variables."
122
  )
123
  return v
 
16
  """
17
  Application settings loaded from environment variables or .env file.
18
 
19
+ All settings have sensible defaults except for the GitHub token,
20
+ which must be provided via the GITHUB_TOKEN environment variable.
21
 
22
  Attributes:
23
  openai_api_key: OpenAI API key (required)
 
39
  """
40
 
41
  # API Configuration (required)
42
+ github_token: str = Field(
43
  default="",
44
+ description="GitHub token - required for LLM and embeddings",
45
+ validation_alias="GITHUB_TOKEN"
46
  )
47
 
48
  # LLM Configuration
 
107
  description="Public URL for social media sharing"
108
  )
109
 
110
+ @field_validator("github_token")
111
  @classmethod
112
+ def validate_github_token(cls, v):
113
+ """Ensure GitHub token is provided and not empty."""
114
  v = v or ""
115
  v = v.strip()
116
  if not v:
117
  import os
118
  if not os.getenv("SPACE_ID"):
119
  raise ValueError(
120
+ "GITHUB_TOKEN is required. "
121
  "Set it in your .env file or environment variables."
122
  )
123
  return v
database/__pycache__/__init__.cpython-312.pyc CHANGED
Binary files a/database/__pycache__/__init__.cpython-312.pyc and b/database/__pycache__/__init__.cpython-312.pyc differ
 
database/__pycache__/vector_store_client.cpython-312.pyc CHANGED
Binary files a/database/__pycache__/vector_store_client.cpython-312.pyc and b/database/__pycache__/vector_store_client.cpython-312.pyc differ
 
models/__pycache__/__init__.cpython-312.pyc CHANGED
Binary files a/models/__pycache__/__init__.cpython-312.pyc and b/models/__pycache__/__init__.cpython-312.pyc differ
 
models/__pycache__/embeddings.cpython-312.pyc CHANGED
Binary files a/models/__pycache__/embeddings.cpython-312.pyc and b/models/__pycache__/embeddings.cpython-312.pyc differ
 
models/embeddings.py CHANGED
@@ -60,7 +60,7 @@ class EmbeddingsClient:
60
 
61
  logger.info(f"Initializing EmbeddingsClient with {self.settings.llm_base_url}")
62
  self.client = OpenAI(
63
- api_key=self.settings.openai_api_key,
64
  base_url=self.settings.llm_base_url
65
  )
66
 
 
60
 
61
  logger.info(f"Initializing EmbeddingsClient with {self.settings.llm_base_url}")
62
  self.client = OpenAI(
63
+ api_key=self.settings.github_token,
64
  base_url=self.settings.llm_base_url
65
  )
66
 
test_startup.py CHANGED
@@ -32,7 +32,7 @@ def test_config():
32
  from config import get_settings
33
  import os
34
 
35
- os.environ.setdefault("OPENAI_API_KEY", "test-key-for-validation")
36
 
37
  settings = get_settings()
38
  logger.info(f"LLM Model: {settings.llm_model}")
@@ -52,7 +52,7 @@ def test_vector_store():
52
  from database.vector_store_client import VectorStoreClient
53
  import os
54
 
55
- os.environ.setdefault("OPENAI_API_KEY", "test-key-for-validation")
56
 
57
  settings = get_settings()
58
  client = VectorStoreClient(uri=settings.lancedb_uri)
@@ -90,7 +90,7 @@ def test_agent():
90
  from agent.a11y_agent import create_agent
91
  import os
92
 
93
- os.environ.setdefault("OPENAI_API_KEY", "test-key-for-validation")
94
 
95
  agent = create_agent()
96
  logger.info(f"Agent language: {agent.language}")
 
32
  from config import get_settings
33
  import os
34
 
35
+ os.environ.setdefault("GITHUB_TOKEN", "test-token-for-validation")
36
 
37
  settings = get_settings()
38
  logger.info(f"LLM Model: {settings.llm_model}")
 
52
  from database.vector_store_client import VectorStoreClient
53
  import os
54
 
55
+ os.environ.setdefault("GITHUB_TOKEN", "test-token-for-validation")
56
 
57
  settings = get_settings()
58
  client = VectorStoreClient(uri=settings.lancedb_uri)
 
90
  from agent.a11y_agent import create_agent
91
  import os
92
 
93
+ os.environ.setdefault("GITHUB_TOKEN", "test-token-for-validation")
94
 
95
  agent = create_agent()
96
  logger.info(f"Agent language: {agent.language}")