Skip to content

Commit

Permalink
Fix lint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
dragos199993 committed Oct 22, 2024
1 parent 6ada17a commit cb58ba2
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 75 deletions.
Binary file modified extensions/not-diamond/metadata/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extensions/not-diamond/metadata/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extensions/not-diamond/metadata/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extensions/not-diamond/metadata/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions extensions/not-diamond/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"author": "dragos_nedelcu",
"categories": [
"Developer Tools",
"Productivity",
"AI",
"Chat"
"Productivity"
],
"license": "MIT",
"commands": [
Expand Down Expand Up @@ -56,25 +54,29 @@
"name": "googleApiKey",
"title": "Google API Key",
"description": "API Key from Google. Generate your own key at https://ai.google.dev/gemini-api/docs/api-key",
"type": "textfield"
"type": "textfield",
"required": false
},
{
"name": "mistralApiKey",
"title": "Mistral API Key",
"description": "API Key from Mistral.ai. Generate your own key at https://console.mistral.ai/api-keys/",
"type": "textfield"
"type": "textfield",
"required": false
},
{
"name": "cohereApiKey",
"title": "Cohere API Key",
"description": "API Key from Cohere.ai. Generate your own key at https://dashboard.cohere.com/",
"type": "textfield"
"type": "textfield",
"required": false
},
{
"name": "togetherApiKey",
"title": "Together API Key",
"description": "API Key from Together.ai. Generate your own key at https://docs.together.ai/docs/quickstart",
"type": "textfield"
"type": "textfield",
"required": false
},
{
"name": "tradeoff",
Expand Down
6 changes: 1 addition & 5 deletions extensions/not-diamond/src/actions/select-model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ export const SelectModel = ({ preferences }: { preferences: Preferences }) => {
actions={
<ActionPanel>
<Action title="Toggle Selection" onAction={() => toggleModel(model)} />
<Action.Push
title="Start Chat"
icon={Icon.Box}
target={<NotDiamond />}
/>
<Action.Push title="Start Chat" icon={Icon.Box} target={<NotDiamond />} />
</ActionPanel>
}
/>
Expand Down
34 changes: 21 additions & 13 deletions extensions/not-diamond/src/actions/send-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ import { PrimaryAction } from "../components/primary-action";
import { PreferencesActionSection } from "../components/preferences-action-section";
import { getSelectModelActionPanel } from "./select-model";

export const getSendMessageActionPanel = ({ onAction, preferences, currentQuestion, answer }: { onAction: () => void, preferences: Preferences, currentQuestion: string, answer: string }) => (
<ActionPanel>
{
currentQuestion ? (
<PrimaryAction title="Send Message" onAction={onAction} />
) : (
<Action.CopyToClipboard content={answer} title="Copy Response" />
)
}
<PreferencesActionSection />
{getSelectModelActionPanel(preferences)}
</ActionPanel>
);
export const getSendMessageActionPanel = ({
onAction,
preferences,
currentQuestion,
answer,
}: {
onAction: () => void;
preferences: Preferences;
currentQuestion: string;
answer: string;
}) => (
<ActionPanel>
{currentQuestion ? (
<PrimaryAction title="Send Message" onAction={onAction} />
) : (
<Action.CopyToClipboard content={answer} title="Copy Response" />
)}
<PreferencesActionSection />
{getSelectModelActionPanel(preferences)}
</ActionPanel>
);
4 changes: 1 addition & 3 deletions extensions/not-diamond/src/components/empty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ export const EmptyView = ({ preferences }: { preferences: Preferences }) => {
<List.EmptyView
title={selectedModels.length === 0 ? "No model selected" : "Ask Not Diamond"}
description={
selectedModels.length === 0
? "Select a model to use Not Diamond"
: "Write a message to use Not Diamond"
selectedModels.length === 0 ? "Select a model to use Not Diamond" : "Write a message to use Not Diamond"
}
icon={selectedModels.length === 0 ? Icon.Warning : Icon.QuestionMark}
actions={
Expand Down
1 change: 0 additions & 1 deletion extensions/not-diamond/src/components/primary-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ import { Action, Icon } from "@raycast/api";
export const PrimaryAction = ({ title, onAction }: { title: string; onAction: () => void }) => (
<Action title={title} icon={Icon.ArrowRight} onAction={onAction} />
);

78 changes: 39 additions & 39 deletions extensions/not-diamond/src/hooks/useQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@ import { useCallback, useEffect, useMemo, useState } from "react";
import { QuestionHook } from "../types/question";

export function useQuestion(props: { initialQuestion: string; disableAutoLoad?: boolean }): QuestionHook {
const { initialQuestion, disableAutoLoad } = props;
const [data, setData] = useState<string>(initialQuestion);
const [isLoading, setLoading] = useState<boolean>(false);
const [isAutoLoad] = useState<boolean>(() => {
return getPreferenceValues<{
isAutoLoad: boolean;
}>().isAutoLoad;
});

useEffect(() => {
(async () => {
if (isAutoLoad && !disableAutoLoad) {
setLoading(true);
try {
const selectedText = await getSelectedText();
if (selectedText.length > 1) {
setData(selectedText.trim());
await showToast({
style: Toast.Style.Success,
title: "Selected text loaded!",
});
}
} catch (error) {
const { initialQuestion, disableAutoLoad } = props;
const [data, setData] = useState<string>(initialQuestion);
const [isLoading, setLoading] = useState<boolean>(false);
const [isAutoLoad] = useState<boolean>(() => {
return getPreferenceValues<{
isAutoLoad: boolean;
}>().isAutoLoad;
});

useEffect(() => {
(async () => {
if (isAutoLoad && !disableAutoLoad) {
setLoading(true);
try {
const selectedText = await getSelectedText();
if (selectedText.length > 1) {
setData(selectedText.trim());
await showToast({
style: Toast.Style.Failure,
title: "Selected text couldn't load",
message: String(error),
style: Toast.Style.Success,
title: "Selected text loaded!",
});
}
setLoading(false);
} catch (error) {
await showToast({
style: Toast.Style.Failure,
title: "Selected text couldn't load",
message: String(error),
});
}
})();
}, []);

const update = useCallback(
async (question: string) => {
setData(question);
},
[setData, data]
);

return useMemo(() => ({ data, isLoading, update }), [data, isLoading, update]);
}
setLoading(false);
}
})();
}, []);

const update = useCallback(
async (question: string) => {
setData(question);
},
[setData, data],
);

return useMemo(() => ({ data, isLoading, update }), [data, isLoading, update]);
}
14 changes: 7 additions & 7 deletions extensions/not-diamond/src/types/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ type ProviderModelMapType = typeof ProviderModelMap;
type SupportedProviderType = keyof ProviderModelMapType;
type ModelForProvider<T extends SupportedProviderType> = ProviderModelMapType[T][number];
export interface Provider<T extends SupportedProviderType = SupportedProviderType> {
provider: T;
model: ModelForProvider<T>;
contextLength?: number;
inputPrice?: number;
outputPrice?: number;
latency?: number;
isCustom?: boolean;
provider: T;
model: ModelForProvider<T>;
contextLength?: number;
inputPrice?: number;
outputPrice?: number;
latency?: number;
isCustom?: boolean;
}

0 comments on commit cb58ba2

Please sign in to comment.