Skip to content

Commit 4ee7ece

Browse files
STetsingAniket-Engg
authored andcommitted
moved to chat completion on mistral ai
1 parent 558e3f0 commit 4ee7ece

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

apps/remix-ide/src/app/components/bottom-bar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
6060
await plugin.call('menuicons', 'select', 'remixaiassistant')
6161
await new Promise(resolve => setTimeout(resolve, 500))
6262
const content = await plugin.call('fileManager', 'readFile', currentFilePath)
63-
await plugin.call('remixAI', 'chatPipe', 'code_explaining', content)
63+
await plugin.call('remixAI', 'chatPipe', 'code_explaining', content + "\n\nExplain briefly the snipped above!")
6464

6565
} catch (err) {
6666
console.error("Explain failed:", err)

apps/remix-ide/src/app/tabs/locales/en/editor.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"editor.explainFunction2": "Explain the function \"{name}\"",
2828
"editor.explainFunctionByAI": "```\n{content}\n```\nExplain the function {currentFunction}",
2929
"editor.explainFunctionByAISol": "```\n{content}\n```\nExplain the function {currentFunction}",
30-
"editor.ExplainPipeMessage": "```\n {content}\n```\nExplain the snipped above",
30+
"editor.ExplainPipeMessage": "```\n {content}\n```\nExplain briefly the snipped above",
3131
"editor.PastedCodeSafety": "```\n {content}\n```\n\nReply in a short manner: Does this code contain major security vulnerabilities leading to a scam or loss of funds?",
3232
"editor.executeFreeFunction": "Run a free function",
3333
"editor.executeFreeFunction2": "Run the free function \"{name}\"",

libs/remix-ai-core/src/helpers/streamHandler.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,21 @@ export const HandleMistralAIResponse = async (streamResponse, cb: (streamText: s
139139
buffer = decoder.decode(value, { stream: true });
140140

141141
const lines = buffer.split("\n");
142-
buffer = lines.pop() ?? ""; // Keep the unfinished line for next chunk
143142
for (const line of lines) {
144143
if (line.startsWith("data: ")) {
145144
const jsonStr = line.replace(/^data: /, "").trim();
145+
if (jsonStr === "[DONE]") {
146+
done_cb?.(resultText, threadId);
147+
return;
148+
}
149+
146150
try {
147151
const json = JSON.parse(jsonStr);
148-
threadId = json?.conversation_id || threadId;
152+
threadId = json?.id || threadId;
149153

150-
if (json.type === 'conversation.response.done') {
151-
done_cb?.(resultText, threadId);
152-
return;
153-
}
154-
155-
if (typeof json.content === "string") {
156-
cb(json.content);
157-
resultText += json.content;
158-
}
154+
const content = json.choices[0].delta.content
155+
cb(content);
156+
resultText += content;
159157
} catch (e) {
160158
console.error("⚠️ MistralAI Stream parse error:", e);
161159
}

libs/remix-ai-core/src/inferencers/remote/remoteInference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class RemoteInferencer implements ICompletions, IGeneration {
131131
}
132132

133133
async answer(prompt, options:IParams=GenerationParams): Promise<any> {
134-
options.chatHistory = options.provider === 'anthropic' ? buildChatPrompt(prompt) : []
134+
options.chatHistory = options.provider === 'anthropic' || options.provider === 'mistralai' ? buildChatPrompt() : []
135135
const payload = { 'prompt': prompt, "endpoint":"answer", ...options }
136136
if (options.stream_result) return this._streamInferenceRequest(payload, AIRequestType.GENERAL)
137137
else return this._makeRequest(payload, AIRequestType.GENERAL)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { ChatHistory } from "./chat"
22

3-
export const buildChatPrompt = (userPrompt) => {
3+
export const buildChatPrompt = () => {
44
const history = []
55
for (const [question, answer] of ChatHistory.getHistory()) {
66
history.push({ role:'user', content: question })
77
history.push({ role:'assistant' , content: answer })
88
}
9-
history.push({ role: 'user', content: userPrompt })
109
return history
1110
}

0 commit comments

Comments
 (0)