Update docs/ARCHITECTURE.md
Browse files- docs/ARCHITECTURE.md +0 -97
docs/ARCHITECTURE.md
CHANGED
@@ -95,100 +95,3 @@ Edit
|
|
95 |
- Chat history pane
|
96 |
|
97 |
---
|
98 |
-
|
99 |
-
```markdown
|
100 |
-
<!-- API_REFERENCE.md -->
|
101 |
-
|
102 |
-
# Shasha AI — API Reference
|
103 |
-
|
104 |
-
This document describes the public interfaces provided by each module.
|
105 |
-
|
106 |
-
---
|
107 |
-
|
108 |
-
## `hf_client.py`
|
109 |
-
|
110 |
-
### `get_inference_client(model_id: str, provider: str = "auto") → InferenceClient`
|
111 |
-
Creates and configures a Hugging Face Hub client for chat completions.
|
112 |
-
|
113 |
-
- **model_id**: HF model ID or external provider prefix (e.g. `"openai/gpt-4"`, `"gemini/pro"`, `"moonshotai/Kimi-K2-Instruct"`).
|
114 |
-
- **provider**: Override provider; one of `auto`, `groq`, `openai`, `gemini`, `fireworks`.
|
115 |
-
- **Returns**: `InferenceClient` instance with proper API key & billing target.
|
116 |
-
|
117 |
-
---
|
118 |
-
|
119 |
-
## `models.py`
|
120 |
-
|
121 |
-
### `ModelInfo`
|
122 |
-
Dataclass representing model metadata.
|
123 |
-
|
124 |
-
- **name**: Human‑readable model name.
|
125 |
-
- **id**: Model identifier for API calls.
|
126 |
-
- **description**: Short description.
|
127 |
-
- **default_provider**: Preferred inference provider.
|
128 |
-
|
129 |
-
### `AVAILABLE_MODELS: List[ModelInfo]`
|
130 |
-
Registry of all supported models.
|
131 |
-
|
132 |
-
### `find_model(identifier: str) → Optional[ModelInfo]`
|
133 |
-
Lookup model by name (case‑insensitive) or ID.
|
134 |
-
|
135 |
-
---
|
136 |
-
|
137 |
-
## `inference.py`
|
138 |
-
|
139 |
-
### `chat_completion(model_id: str, messages: List[Dict[str, str]], provider: str = None, max_tokens: int = 4096) → str`
|
140 |
-
Synchronously sends a chat completion request.
|
141 |
-
|
142 |
-
- **messages**: List of `{"role": "...", "content": "..."}`
|
143 |
-
- **provider**: Optional override; defaults to model’s `default_provider`.
|
144 |
-
- **Returns**: Response content string.
|
145 |
-
|
146 |
-
### `stream_chat_completion(model_id: str, messages: List[Dict[str, str]], provider: str = None, max_tokens: int = 4096) → Generator[str]`
|
147 |
-
Streams a chat completion, yielding incremental content chunks.
|
148 |
-
|
149 |
-
---
|
150 |
-
|
151 |
-
## `utils.py`
|
152 |
-
|
153 |
-
### `history_to_messages(history: History, system: str) → List[Dict]`
|
154 |
-
Converts internal history list to OpenAI‑style messages.
|
155 |
-
|
156 |
-
### `remove_code_block(text: str) → str`
|
157 |
-
Strips markdown code fences from AI output and returns raw code.
|
158 |
-
|
159 |
-
### `parse_transformers_js_output(text: str) → Dict[str, str]`
|
160 |
-
Extracts `index.html`, `index.js`, `style.css` from a multi‑file markdown output.
|
161 |
-
|
162 |
-
### `format_transformers_js_output(files: Dict[str, str]) → str`
|
163 |
-
Formats a dict of file contents into a single combined string with section headers.
|
164 |
-
|
165 |
-
*(Other utilities: multimodal image processing, search/replace, history rendering)*
|
166 |
-
|
167 |
-
---
|
168 |
-
|
169 |
-
## `deploy.py`
|
170 |
-
|
171 |
-
### `send_to_sandbox(code: str) → str`
|
172 |
-
Wraps HTML code in a base64 data‑URI iframe for live preview.
|
173 |
-
|
174 |
-
### `load_project_from_url(url: str) → Tuple[str, str]`
|
175 |
-
Fetches `app.py` or `index.html` from a public HF Space URL.
|
176 |
-
|
177 |
-
*(Also: HF Spaces deploy helpers: `deploy_to_spaces()`, `deploy_to_spaces_static()`, `deploy_to_user_space()`)*
|
178 |
-
|
179 |
-
---
|
180 |
-
|
181 |
-
## `app.py`
|
182 |
-
|
183 |
-
### `generation_code(query, image, file, website_url, _setting, _history, _current_model, enable_search, language, provider) → Tuple[str, History, str, List[Dict]]`
|
184 |
-
Main generation handler bound to the “Generate” button.
|
185 |
-
|
186 |
-
- **Returns**:
|
187 |
-
1. `code_str`: Generated (or edited) source code
|
188 |
-
2. `new_history`: Updated prompt/response history
|
189 |
-
3. `sandbox_html`: Live preview HTML iframe string
|
190 |
-
4. `chat_msgs`: Chatbot‑style history for the UI
|
191 |
-
|
192 |
-
---
|
193 |
-
|
194 |
-
_For more examples, see the Jupyter notebooks in_ `notebooks/` and the quick‑start guide in `QUICKSTA
|
|
|
95 |
- Chat history pane
|
96 |
|
97 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|