Skip to content

Commit

Permalink
Merge remote-tracking branch origin/main into migrate-from-streamlit-…
Browse files Browse the repository at this point in the history
…to-sveltekit
  • Loading branch information
nwaughachukwuma committed Nov 7, 2024
2 parents 303b59e + c25390b commit c30cad8
Show file tree
Hide file tree
Showing 27 changed files with 142 additions and 745 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ __pycache__
.env.*
!.env.example

reference_code

keys/
.ruff_cache/
.ruff_cache/
node_modules/
.DS_Store
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ repos:
types: [python]
- id: ruff-format
types: [python]
- id: ruff-format
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ANTHROPIC_API_KEY="your-anthropic-api-key"
GEMINI_API_KEY="your-gemini-api-key"
ELEVENLABS_API_KEY="your-elevenlabs-api-key"
APP_URL="http://localhost:8080"
API_URL="http://localhost:8585"
```

4. Launch the application:
Expand Down
1 change: 0 additions & 1 deletion streamlit_app/.dockerignore → app/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.streamlit/
.vscode/
api/
tests/
Expand Down
1 change: 0 additions & 1 deletion streamlit_app/.gcloudignore → app/.gcloudignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.streamlit/
.vscode/
api/
tests/
Expand Down
4 changes: 4 additions & 0 deletions streamlit_app/Dockerfile → app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ RUN apt-get -yqq update && apt-get -yqq install \

COPY . ./
# RUN rm -rf ./api
<<<<<<<< HEAD:streamlit_app/Dockerfile

========

>>>>>>>> origin/main:app/Dockerfile
# Install production dependencies.
RUN pip install --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
Expand Down
129 changes: 129 additions & 0 deletions app/src/lib/components/ChatInterface.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<script lang="ts">
import { onMount } from 'svelte';
import { Button } from '$lib/components/ui/button';
import { Textarea } from '$lib/components/ui/textarea';
import { toast } from 'svelte-sonner';
import { sessionStore, type Message } from '$lib/stores/session';
import { contentCategories, type ContentCategory } from '$lib/types';
import { nanoid } from 'nanoid';
import { debounce } from 'throttle-debounce';
let messageInput = '';
let isLoading = false;
let selectedCategory: ContentCategory | null = null;
const examplePrompts = {
'professional-development': 'I want to learn about effective leadership',
'self-improvement': 'Help me understand mindfulness meditation',
'knowledge-synthesis': 'Explain quantum computing basics',
'creative-writing': 'Create a story about space exploration'
};
const debouncedSendMessage = debounce(500, async (content: string) => {
if (!selectedCategory) {
toast.error('Please select a content category first');
return;
}
try {
isLoading = true;
const response = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionId: $sessionStore.id,
message: content,
contentCategory: selectedCategory
})
});
if (!response.ok) throw new Error('Failed to send message');
const aiResponse = await response.text();
sessionStore.update((state) => ({
...state,
messages: [...state.messages, { role: 'assistant', content: aiResponse }]
}));
} catch (error) {
toast.error('Failed to send message');
console.error(error);
} finally {
isLoading = false;
}
});
async function handleSubmit() {
if (!messageInput.trim()) return;
const message: Message = {
role: 'user',
content: messageInput
};
sessionStore.update((state) => ({
...state,
messages: [...state.messages, message]
}));
const content = messageInput;
messageInput = '';
await debouncedSendMessage(content);
}
function setExamplePrompt(category: ContentCategory) {
selectedCategory = category;
messageInput = examplePrompts[category] || '';
}
</script>

<div class="flex flex-col gap-4">
<div class="flex gap-2 flex-wrap">
{#each contentCategories as category}
<Button
variant={selectedCategory === category ? 'default' : 'outline'}
on:click={() => setExamplePrompt(category)}
>
{category}
</Button>
{/each}
</div>

<div class="h-[400px] overflow-y-auto border rounded-lg p-4 bg-card">
{#if $sessionStore.messages.length === 0}
<p class="text-muted-foreground text-center">
Start a conversation by selecting a category and sending a message
</p>
{/if}

{#each $sessionStore.messages as message}
<div class="mb-4 last:mb-0">
<div class="font-semibold mb-1">
{message.role === 'user' ? 'You' : 'Assistant'}:
</div>
<div class="pl-4">
{message.content}
</div>
</div>
{/each}

{#if isLoading}
<div class="flex items-center gap-2 text-muted-foreground">
<div class="animate-spin">⌛</div>
Thinking...
</div>
{/if}
</div>

<form class="flex gap-2" on:submit|preventDefault={handleSubmit}>
<Textarea
bind:value={messageInput}
placeholder="Type your message..."
rows="3"
class="flex-1"
/>
<Button type="submit" disabled={isLoading || !messageInput.trim()}>Send</Button>
</form>
</div>
6 changes: 3 additions & 3 deletions services/admin_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def init_admin_sdk():
try:
app = firebase_admin.get_app()
print(f"Firebase Admin SDK already initialized ~> {app.name}")
print(f"Firebase Admin SDK already initialized ~> {app.project_id}")
except ValueError:
firebase_admin.initialize_app()
print("Firebase Admin SDK initialized")
app = firebase_admin.initialize_app()
print(f"Firebase Admin SDK initialized ~> {app.project_id}")
3 changes: 1 addition & 2 deletions shared_utils_pkg/session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def on_snapshot(doc_snapshot, _changes, _read_time):
for doc in doc_snapshot:
if doc.exists and doc.id == self.doc_id:
data = doc.to_dict()
info = data.get("metadata", {}).get("info")
print(f"Document metadata info: {info}")
info = (data.get("metadata", {}) or {}).get("info")
callback(info)

return doc_ref.on_snapshot(on_snapshot)
Empty file removed streamlit_app/__init__.py
Empty file.
32 changes: 0 additions & 32 deletions streamlit_app/_init_project.py

This file was deleted.

39 changes: 0 additions & 39 deletions streamlit_app/index.py

This file was deleted.

61 changes: 0 additions & 61 deletions streamlit_app/pages/audiocast.py

This file was deleted.

Empty file removed streamlit_app/src/__init__.py
Empty file.
Empty file.
Loading

0 comments on commit c30cad8

Please sign in to comment.