Skip to content

Commit

Permalink
fix: stom s
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Jan 9, 2025
1 parent 56d2340 commit 3d6a27c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/plugin/views/assistant/ai-chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const ChatComponent: React.FC<ChatComponentProps> = ({
enableScreenpipe: plugin.settings.enableScreenpipe,
newUnifiedContext: contextString,
model: plugin.settings.selectedModel, // Pass selected model to server
enableSearchGrounding: plugin.settings.enableSearchGrounding,
};

const [groundingMetadata, setGroundingMetadata] =
Expand Down Expand Up @@ -501,7 +502,7 @@ export const ChatComponent: React.FC<ChatComponentProps> = ({
maxContextSize={maxContextSize}
/>
<div className="flex items-center space-x-2">
<SearchToggle />
<SearchToggle selectedModel={selectedModel} />
<ModelSelector
selectedModel={selectedModel}
onModelSelect={setSelectedModel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function SourcesSection({ groundingMetadata }: SourcesSectionProps) {
const displayedSources = showAll ? sources : sources.slice(0, 3);

return (
<div className="mt-6 space-y-4">
<div className="mt-6 space-y-4 m-2 z-50">
<div className="flex justify-between items-center">
<h3 className="text-base font-medium text-gray-900 dark:text-gray-100">Sources</h3>
{sources.length > 3 && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import React from 'react';
import React, { useState } from 'react';
import { usePlugin } from '../../provider';
import { ModelType } from '../types';

export function SearchToggle() {
interface SearchToggleProps {
selectedModel: ModelType;
}

export function SearchToggle({ selectedModel }: SearchToggleProps) {
const plugin = usePlugin();
const isEnabled = plugin.settings.enableSearchGrounding;
const [isEnabled, setIsEnabled] = useState(plugin.settings.enableSearchGrounding);

const handleToggle = async () => {
plugin.settings.enableSearchGrounding = !plugin.settings.enableSearchGrounding;
await plugin.saveSettings();
setIsEnabled(!isEnabled);
};

if (selectedModel !== 'gpt-4o') {
return null;
}

return (
<button
onClick={handleToggle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ export const SearchAnnotationHandler: React.FC<SearchAnnotationProps> = ({
if (!groundingMetadata?.groundingSupports?.length) return null;

return (
<div className="flex flex-col gap-2 p-2 rounded-md bg-[--background-primary-alt]">
<div className="flex flex-col gap-2 p-4 rounded-md bg-[--background-primary-alt] m-2">
<div className="text-[--text-muted] text-sm">Search Results:</div>
{groundingMetadata.groundingSupports.map((result, index) => {
const sources = result.groundingChunkIndices.map(
idx => groundingMetadata.groundingChunks[idx]?.web.title
).filter(Boolean);
const sources = result.groundingChunkIndices.map(idx => {
const chunk = groundingMetadata.groundingChunks[idx]?.web;
return chunk ? { title: chunk.title, uri: chunk.uri } : null;
}).filter(Boolean);

const maxScore = Math.max(...result.confidenceScores);

Expand All @@ -54,7 +55,19 @@ export const SearchAnnotationHandler: React.FC<SearchAnnotationProps> = ({
>
<div className="flex justify-between items-center">
<span className="text-[--text-accent] text-sm">
{sources.join(', ')}
{sources.map((source, i) => (
<React.Fragment key={i}>
{i > 0 && ', '}
<a
href={source.uri}
target="_blank"
rel="noopener noreferrer"
className="hover:underline"
>
{source.title}
</a>
</React.Fragment>
))}
</span>
<span className="text-[--text-muted] text-xs">
Score: {(maxScore * 100).toFixed(1)}%
Expand Down
5 changes: 5 additions & 0 deletions packages/web/app/api/(newai)/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ export async function POST(req: NextRequest) {

let chosenModelName;
if (enableSearchGrounding) {
console.log("Enabling search grounding");
console.log("GOOGLE_API_KEY:", process.env.GOOGLE_API_KEY);
console.log("GOOGLE_GENERATIVE_AI_API_KEY:", process.env.GOOGLE_GENERATIVE_AI_API_KEY);
if (process.env.GOOGLE_API_KEY || process.env.GOOGLE_GENERATIVE_AI_API_KEY) {
console.log("Using Gemini model");
chosenModelName = "gemini-2.0-flash-exp";
} else {
console.log("Using GPT-4o model");
chosenModelName = "gpt-4o";
}
} else {
Expand Down

0 comments on commit 3d6a27c

Please sign in to comment.