MCPcopy Create free account
hub / github.com/SKaplanOfficial/Raycast-PromptLab / useModel

Function useModel

src/hooks/useModel.ts:25–289  ·  view source on GitHub ↗
(
  basePrompt: string,
  prompt: string,
  input: string,
  temperature: string,
  execute: boolean,
  modelOverride?: Model,
)

Source from the content-addressed store, hash-verified

23 * @returns The string output received from the model endpoint.
24 */
25export default function useModel(
26 basePrompt: string,
27 prompt: string,
28 input: string,
29 temperature: string,
30 execute: boolean,
31 modelOverride?: Model,
32) {
33 const preferences = getPreferenceValues<ExtensionPreferences>();
34 const [data, setData] = useState<string>("");
35 const [error] = useState<string>();
36 const [dataTag, setDataTag] = useState<string>("");
37 const [isLoading, setIsLoading] = useState<boolean>(execute);
38 const [attempt, setAttempt] = useState<number>(0);
39 const models = useModels();
40 const AIRef = useRef<{ fetch: Promise<Response>; tag: string; forceStop: () => void }>();
41
42 const preferenceModel: Model = {
43 endpoint: preferences.modelEndpoint,
44 authType: preferences.authType,
45 apiKey: preferences.apiKey,
46 inputSchema: preferences.inputSchema,
47 outputKeyPath: preferences.outputKeyPath,
48 outputTiming: preferences.outputTiming,
49 lengthLimit: preferences.lengthLimit,
50 temperature: "1.0",
51 name: "",
52 description: "",
53 favorited: false,
54 id: "",
55 icon: "",
56 iconColor: "",
57 notes: "",
58 isDefault: false,
59 };
60 const defaultModel = models.models.find((model) => model.isDefault);
61 const targetModel =
62 modelOverride || defaultModel || (preferenceModel.endpoint == "" ? RAYCAST_AI_FALLBACK_MODEL : preferenceModel);
63 const raycastModel =
64 RAYCAST_AI_REPRESENTATIONS.includes(targetModel.endpoint.toLowerCase() as RaycastAIRepresentation) ||
65 targetModel.endpoint == "" ||
66 targetModel.apiKey == "N/A";
67 models.isLoading && !modelOverride && preferenceModel.endpoint == "";
68
69 const temp = preferences.includeTemperature
70 ? parseFloat(temperature) == undefined
71 ? 1.0
72 : parseFloat(temperature)
73 : 1.0;
74
75 // If the endpoint is a URL, use the fetch hook
76 const headers: { [key: string]: string } = {
77 method: "POST",
78 "Content-Type": "application/json",
79 };
80
81 // Add the authentication header if necessary
82 if (targetModel.apiKey.length != 0) {

Callers 2

CommandResponseFunction · 0.85
CommandChatViewFunction · 0.85

Calls 4

useModelsFunction · 0.90
getFinalSchemaFunction · 0.90
valueForKeyPathFunction · 0.90
filterStringFunction · 0.90

Tested by

no test coverage detected