Skip to content

Commit

Permalink
Bugfix: "Continue in Chat" not working. + Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
XInTheDark committed May 3, 2024
1 parent 2c46aa4 commit ea0aada
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 91 deletions.
29 changes: 13 additions & 16 deletions src/aiChat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getPreferenceValues,
} from "@raycast/api";
import { useState, useEffect } from "react";
import { getChatResponse, formatResponse, providers, processChunks } from "./api/gpt";
import { defaultProvider, getChatResponse, formatResponse, providers, processChunks } from "./api/gpt";
import { LocalStorage, Clipboard } from "@raycast/api";

export default function Chat({ launchContext }) {
Expand All @@ -30,7 +30,7 @@ export default function Chat({ launchContext }) {
{
name: "New Chat",
creationDate: new Date(),
provider: "GPT",
provider: defaultProvider(),
systemPrompt: "",
messages: [],
},
Expand Down Expand Up @@ -438,15 +438,18 @@ export default function Chat({ launchContext }) {
if (launchContext?.query) {
setChatData((oldData) => {
let newChatData = structuredClone(oldData);
let newChatName = `From Quick AI at ${new Date().toLocaleString("en-US", {
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
})}`;
newChatData.chats.push({
name: `From Quick AI at ${new Date().toLocaleString("en-US", {
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
})}`,
name: newChatName,
creationDate: new Date(),
provider: defaultProvider(), // if called from an AI action, the provider used must be the default
systemPrompt: "",
messages: [
{
prompt: launchContext.query,
Expand All @@ -456,13 +459,7 @@ export default function Chat({ launchContext }) {
},
],
});
newChatData.currentChat = `From Quick AI at ${new Date().toLocaleString("en-US", {
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
})}`;
newChatData.currentChat = newChatName;
return newChatData;
});
}
Expand Down
4 changes: 4 additions & 0 deletions src/api/gpt.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export const providers = {
GoogleGemini: [GeminiProvider, "", false],
};

export const defaultProvider = () => {
return getPreferenceValues()["gptProvider"];
};

export default (props, { context = undefined, allowPaste = false, useSelected = false, buffer = [] }) => {
const Pages = {
Form: 0,
Expand Down
123 changes: 48 additions & 75 deletions src/genImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,53 @@ import fs from "fs";

const g4f = new G4F.G4F();

export default function genImage({ launchContext }) {
export const _NegativePrompt =
"low quality, normal quality, bad quality, disfigured, bad, ugly, poorly drawn face," +
" extra limb, missing limb, floating limbs, disconnected limbs, malformed limbs, oversaturated, duplicate," +
" low-res, blurry, out of focus, out of frame, extra, missing";

// Image Providers
export const image_providers = {
Prodia: [
g4f.providers.Prodia,
{
// list of available models: https://rentry.co/b6i53fnm
model: "neverendingDream_v122.safetensors [f964ceeb]",
cfgScale: 10,
negativePrompt: _NegativePrompt,
samplingMethod: "Heun",
},
],
ProdiaStableDiffusion: [
g4f.providers.ProdiaStableDiffusion,
{
// list of available models: https://rentry.co/pfwmx6y5
model: "ICantBelieveItsNotPhotography_seco.safetensors [4e7a3dfd]",
cfgScale: 10,
negativePrompt: _NegativePrompt,
samplingMethod: "Heun",
},
],
ProdiaStableDiffusionXL: [
g4f.providers.ProdiaStableDiffusionXL,
{
// list of available models: https://rentry.co/wfhsk8sv
model: "dreamshaperXL10_alpha2.safetensors [c8afe2ef]",
height: 1024,
width: 1024,
cfgScale: 10,
negativePrompt: _NegativePrompt,
samplingMethod: "Heun",
},
],
Dalle: [g4f.providers.Dalle, {}],
};

const defaultImageProvider = () => {
return "Prodia";
};

export default function genImage() {
let toast = async (style, title, message) => {
await showToast({
style,
Expand All @@ -34,7 +80,7 @@ export default function genImage({ launchContext }) {
{
name: "New Image Chat",
creationDate: new Date(),
provider: "Prodia",
provider: defaultImageProvider(),
imageQuality: "High",
messages: [],
},
Expand Down Expand Up @@ -391,38 +437,6 @@ export default function genImage({ launchContext }) {
await LocalStorage.setItem("imageChatData", JSON.stringify(newChatData));
setChatData(newChatData);
}

if (launchContext?.query) {
setChatData((oldData) => {
let newChatData = structuredClone(oldData);
newChatData.chats.push({
name: `From Quick AI at ${new Date().toLocaleString("en-US", {
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
})}`,
creationDate: new Date(),
messages: [
{
prompt: launchContext.query,
answer: launchContext.response,
creationDate: new Date().toISOString(),
finished: true,
},
],
});
newChatData.currentChat = `From Quick AI at ${new Date().toLocaleString("en-US", {
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
})}`;
return newChatData;
});
}
})();
}, []);

Expand Down Expand Up @@ -496,47 +510,6 @@ export default function genImage({ launchContext }) {
);
}

export const _NegativePrompt =
"low quality, normal quality, bad quality, disfigured, bad, ugly, poorly drawn face," +
" extra limb, missing limb, floating limbs, disconnected limbs, malformed limbs, oversaturated, duplicate," +
" low-res, blurry, out of focus, out of frame, extra, missing";

export const image_providers = {
Prodia: [
g4f.providers.Prodia,
{
// list of available models: https://rentry.co/b6i53fnm
model: "neverendingDream_v122.safetensors [f964ceeb]",
cfgScale: 10,
negativePrompt: _NegativePrompt,
samplingMethod: "Heun",
},
],
ProdiaStableDiffusion: [
g4f.providers.ProdiaStableDiffusion,
{
// list of available models: https://rentry.co/pfwmx6y5
model: "ICantBelieveItsNotPhotography_seco.safetensors [4e7a3dfd]",
cfgScale: 10,
negativePrompt: _NegativePrompt,
samplingMethod: "Heun",
},
],
ProdiaStableDiffusionXL: [
g4f.providers.ProdiaStableDiffusionXL,
{
// list of available models: https://rentry.co/wfhsk8sv
model: "dreamshaperXL10_alpha2.safetensors [c8afe2ef]",
height: 1024,
width: 1024,
cfgScale: 10,
negativePrompt: _NegativePrompt,
samplingMethod: "Heun",
},
],
Dalle: [g4f.providers.Dalle, {}],
};

export const loadImageOptions = (currentChat) => {
// load provider and options
const providerString = currentChat.provider,
Expand Down

0 comments on commit ea0aada

Please sign in to comment.