Skip to content

Commit ac71ea7

Browse files
authored
Merge pull request #42 from GYFX35/add-document-specialist-role-6497180777360688900
Add Document Specialist role
2 parents fccfbbd + 61228cc commit ac71ea7

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

app.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,17 @@ def cartography_assistance_endpoint():
922922
return jsonify({"status": "success", "message": message})
923923

924924

925+
@app.route('/api/v1/assistance/document', methods=['POST'])
926+
@require_api_key
927+
def document_assistance_endpoint():
928+
data = request.get_json()
929+
prompt = data.get('prompt')
930+
if not prompt:
931+
return jsonify({"error": _("Prompt is required")}), 400
932+
message = google_ai.provide_document_assistance(prompt)
933+
return jsonify({"status": "success", "message": message})
934+
935+
925936
@app.route('/api/register', methods=['POST'])
926937
def register():
927938
data = request.get_json()

frontend/static/js/script.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,44 @@ document.addEventListener('DOMContentLoaded', () => {
249249
});
250250
}
251251

252+
// --- Document Specialist ---
253+
const documentSpecialistBtn = document.getElementById('document-specialist-btn');
254+
if (documentSpecialistBtn) {
255+
documentSpecialistBtn.addEventListener('click', async () => {
256+
const input = document.getElementById('document-specialist-input');
257+
const responseContainer = document.getElementById('document-specialist-response');
258+
const apiKey = prompt("Please enter your API key to use the Document Specialist:");
259+
260+
if (!apiKey) {
261+
responseContainer.textContent = 'API key is required.';
262+
return;
263+
}
264+
265+
try {
266+
const response = await fetch('/api/v1/assistance/document', {
267+
method: 'POST',
268+
headers: {
269+
'Content-Type': 'application/json',
270+
'X-API-Key': apiKey
271+
},
272+
body: JSON.stringify({
273+
prompt: input.value
274+
})
275+
});
276+
277+
if (!response.ok) {
278+
const error = await response.json();
279+
throw new Error(error.error || 'Failed to get a response from the document specialist');
280+
}
281+
282+
const result = await response.json();
283+
responseContainer.textContent = result.message;
284+
} catch (error) {
285+
responseContainer.textContent = `Error: ${error.message}`;
286+
}
287+
});
288+
}
289+
252290
// --- Promote Startup ---
253291
const promoteStartupBtn = document.getElementById('promote-startup-btn');
254292
if (promoteStartupBtn) {

frontend/templates/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ <h3>{{ _('Music Instrumentalist Player') }}</h3>
7777
</div>
7878
</section>
7979

80+
<!-- Document Specialist Section -->
81+
<section id="document-specialist" class="services">
82+
<h2>{{ _('Document Specialist') }}</h2>
83+
<div class="service-cards">
84+
<div class="card">
85+
<h3>{{ _('Write, scan, and build documents') }}</h3>
86+
<p>{{ _('Enter your request for ebooks, articles, PDFs, or DOCs below.') }}</p>
87+
<textarea id="document-specialist-input" placeholder="{{ _('Your document request') }}" class="styled-textarea" rows="4"></textarea>
88+
<button id="document-specialist-btn" class="btn">{{ _('Submit') }}</button>
89+
<div class="response-container" id="document-specialist-response-container">
90+
<pre id="document-specialist-response"></pre>
91+
</div>
92+
</div>
93+
</div>
94+
</section>
95+
8096
<!-- Geometry Assistant Section -->
8197
<section id="geometry-assistant" class="services">
8298
<h2>{{ _('Geometry Assistant') }}</h2>

google_ai.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,33 @@ def provide_cartography_assistance(prompt: str) -> str:
531531
except Exception as e:
532532
print(f"Error providing cartography assistance with Vertex AI: {e}")
533533
return f"Error: {e}"
534+
535+
536+
def provide_document_assistance(prompt: str) -> str:
537+
"""
538+
Provides assistance with writing, scanning, and building ebooks, articles, PDFs, and DOCs using Vertex AI.
539+
"""
540+
model = GenerativeModel("gemini-1.5-flash")
541+
542+
generation_prompt = f"""
543+
You are an expert document specialist. Your task is to provide assistance with writing, scanning, and building ebooks, articles, PDFs, DOCs, and other file formats.
544+
Your expertise includes:
545+
- Writing: Generating high-quality content for ebooks, articles, and reports.
546+
- Scanning: Summarizing, extracting key information, and analyzing document content.
547+
- Building: Advising on document structure, formatting, and conversion between different formats.
548+
549+
User Request:
550+
---
551+
{prompt}
552+
---
553+
554+
Provide a professional, detailed, and helpful response based on the user's request.
555+
"""
556+
557+
try:
558+
response = model.generate_content(generation_prompt)
559+
return response.text.strip()
560+
561+
except Exception as e:
562+
print(f"Error providing document assistance with Vertex AI: {e}")
563+
return f"Error: {e}"

0 commit comments

Comments
 (0)