MCPcopy Create free account
hub / github.com/PromtEngineer/localGPT / sendMessage

Method sendMessage

src/lib/api.ts:98–122  ·  view source on GitHub ↗
(request: ChatRequest)

Source from the content-addressed store, hash-verified

96 }
97
98 async sendMessage(request: ChatRequest): Promise<ChatResponse> {
99 try {
100 const response = await fetch(`${API_BASE_URL}/chat`, {
101 method: 'POST',
102 headers: {
103 'Content-Type': 'application/json',
104 },
105 body: JSON.stringify({
106 message: request.message,
107 model: request.model || 'llama3.2:latest',
108 conversation_history: request.conversation_history || [],
109 }),
110 });
111
112 if (!response.ok) {
113 const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
114 throw new Error(`Chat API error: ${errorData.error || response.statusText}`);
115 }
116
117 return await response.json();
118 } catch (error) {
119 console.error('Chat API failed:', error);
120 throw error;
121 }
122 }
123
124 // Convert ChatMessage array to conversation history format
125 messagesToHistory(messages: ChatMessage[]): Array<{ role: 'user' | 'assistant'; content: string }> {

Callers 1

sendMessageFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected