MCPcopy Create free account
hub / github.com/Roy3838/Observer / sendPrompt

Method sendPrompt

app/src/utils/ModelManager.ts:680–754  ·  view source on GitHub ↗

* Send a prompt through the appropriate backend for the given model. * - Local models (browser_local, llama_cpp_local): routed directly, no inference params * - Remote models: fetches per-model params and delegates to sendApi.fetchResponse

(
    modelName: string,
    preprocessResult: PreProcessorResult,
    token?: string,
    enableStreaming: boolean = false,
    onStreamChunk?: (chunk: string) => void,
    onReasoningChunk?: (chunk: string) => void
  )

Source from the content-addressed store, hash-verified

678 * - Remote models: fetches per-model params and delegates to sendApi.fetchResponse
679 */
680 public async sendPrompt(
681 modelName: string,
682 preprocessResult: PreProcessorResult,
683 token?: string,
684 enableStreaming: boolean = false,
685 onStreamChunk?: (chunk: string) => void,
686 onReasoningChunk?: (chunk: string) => void
687 ): Promise<ModelOutput> {
688 // Resolve model → server
689 let modelsResponse = this.listModels();
690 let model = modelsResponse.models.find(m => m.name === modelName);
691 if (!model) {
692 modelsResponse = await this.fetchModels();
693 model = modelsResponse.models.find(m => m.name === modelName);
694 }
695 if (!model) throw new Error(`Model '${modelName}' not found in available models`);
696
697 const serverAddress = model.server;
698
699 // Decision models: the prompt is a System One question/request, the images are the state
700 if (model.decision && !this.isLocalModel(serverAddress)) {
701 // Hosted decision model (cloud Jev): the server answers; images ride inside the state
702 if (serverAddress.includes('api.observer-ai.com') && token) {
703 this.optimisticUpdateQuota(1); // a decision costs 1 credit, an LLM call 4
704 }
705 const images = (preprocessResult.images ?? []).map(imageDataUrl);
706 const request = buildCloudRequest(modelName, preprocessResult.modifiedPrompt, images);
707 const { fetchDecision } = await import('./sendApi');
708 const answers = await fetchDecision(serverAddress, request, token);
709 return { response: null, decision: cloudDecision(answers, request.single) };
710 }
711 if (model.decision) {
712 if (model.status !== 'loaded') {
713 throw new Error('Local model not loaded. Please load it from the Add Model panel.');
714 }
715 const images = (preprocessResult.images ?? []).map(imageDataUrl);
716 const prepared = prepareDecision(preprocessResult.modifiedPrompt, images);
717 const logits = serverAddress === ModelManager.LLAMA_CPP_LOCAL
718 ? await NativeLlmManager.getInstance().decide(prepared.branches)
719 : await GemmaModelManager.getInstance().decide(prepared.branches);
720 return { response: null, decision: assembleDecision(prepared, logits) };
721 }
722
723 // Build messages from preprocessResult
724 const hasImages = preprocessResult.images && preprocessResult.images.length > 0;
725 let content: any = preprocessResult.modifiedPrompt;
726 if (hasImages) {
727 content = [
728 { type: 'text', text: preprocessResult.modifiedPrompt },
729 ...preprocessResult.images!.map(img => ({
730 type: 'image',
731 image: imageDataUrl(img),
732 })),
733 ];
734 }
735 const messages = [{ role: 'user', content }];
736
737 // Local models: route directly, they manage their own settings

Callers 3

executeAgentIterationFunction · 0.80
executeTestIterationFunction · 0.80
createApiFunction · 0.80

Calls 15

listModelsMethod · 0.95
fetchModelsMethod · 0.95
isLocalModelMethod · 0.95
optimisticUpdateQuotaMethod · 0.95
isLocalModelReadyMethod · 0.95
getModelParamsMethod · 0.95
buildCloudRequestFunction · 0.90
cloudDecisionFunction · 0.90
prepareDecisionFunction · 0.90
assembleDecisionFunction · 0.90
imageDataUrlFunction · 0.90

Tested by

no test coverage detected