parent
118d66e842
commit
abeac7d4e6
@ -0,0 +1,62 @@ |
||||
import { ChatHistory } from '../prompts/chat'; |
||||
import { JsonStreamParser} from '../types/types' |
||||
|
||||
export const HandleSimpleResponse = async (response,
|
||||
cb?: (streamText: string) => void) => { |
||||
let resultText = '' |
||||
const parser = new JsonStreamParser(); |
||||
|
||||
const chunk = parser.safeJsonParse<{ generatedText: string; isGenerating: boolean }>(response); |
||||
for (const parsedData of chunk) { |
||||
if (parsedData.isGenerating) { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} else { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} |
||||
} |
||||
} |
||||
|
||||
export const HandleStreamResponse = async (streamResponse,
|
||||
cb?: (streamText: string) => void, |
||||
done_cb?: (result: string) => void) => { |
||||
try { |
||||
console.log("streamResponse handler", streamResponse) |
||||
let resultText = '' |
||||
const parser = new JsonStreamParser(); |
||||
const reader = streamResponse.body!.getReader(); |
||||
const decoder = new TextDecoder(); |
||||
|
||||
while (true) { |
||||
const { done, value } = await reader.read(); |
||||
if (done) break; |
||||
|
||||
try { |
||||
const chunk = parser.safeJsonParse<{ generatedText: string; isGenerating: boolean }>(decoder.decode(value, { stream: true })); |
||||
for (const parsedData of chunk) { |
||||
if (parsedData.isGenerating) { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} else { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} |
||||
} |
||||
} |
||||
catch (error) { |
||||
console.error('Error parsing JSON:', error); |
||||
} |
||||
} |
||||
if (done_cb) { |
||||
done_cb(resultText) |
||||
} |
||||
} |
||||
catch (error) { |
||||
console.error('Error parsing JSON:', error); |
||||
} |
||||
} |
||||
|
||||
export const UpdtateChatHistory = (userPromptprompt: string, AIAnswer: string) => { |
||||
ChatHistory.pushHistory(userPromptprompt, AIAnswer) |
||||
} |
@ -0,0 +1,16 @@ |
||||
import { StatusEvents } from "@remixproject/plugin-utils"; |
||||
|
||||
export interface IRemixAIDesktop { |
||||
events: { |
||||
onStreamResult(streamText: string): Promise<void>, |
||||
} & StatusEvents, |
||||
methods: { |
||||
code_completion(context: string): Promise<string>
|
||||
code_insertion(msg_pfx: string, msg_sfx: string): Promise<string>, |
||||
code_generation(prompt: string): Promise<string>, |
||||
code_explaining(code: string, context?: string): Promise<string>, |
||||
error_explaining(prompt: string): Promise<string>, |
||||
solidity_answer(prompt: string): Promise<string>, |
||||
initializeModelBackend(local: boolean, generalModel?, completionModel?): Promise<void>, |
||||
} |
||||
} |
@ -1 +1 @@ |
||||
export { RemixAITab } from './lib/components/RemixAI' |
||||
export { RemixAITab, ChatApi } from './lib/components/RemixAI' |
Loading…
Reference in new issue