Skip to content

Commit

Permalink
Merge pull request #39 from mithril-security/openai_implementation
Browse files Browse the repository at this point in the history
update worker
  • Loading branch information
gemini-15 authored Oct 8, 2024
2 parents 6be81a5 + 7a14335 commit 323e1d5
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/routes/conversation/[id]/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ self.addEventListener("message", async (event) => {

const t = compileTemplate2(event.data.model_obj.chatPromptTemplate, m);
const res = t({ messages: event.data.messages, preprompt: m.preprompt });
// const re

controller = new AbortController();
const context = buildContext(event.data);
Expand All @@ -183,24 +184,40 @@ self.addEventListener("message", async (event) => {
truncate: event.data.model_obj.parameters?.truncate ?? 2048,
return_full_text: false,
};
// let body = JSON.stringify({
// inputs: res,
// parameters: newParameters,
// });
let body = JSON.stringify({
inputs: res,
parameters: newParameters,
model: event.data.model,
prompt: res,
max_tokens: 2048,
temperature: 0.8
});
console.log(body);
let text_output = "";
const server_addr = event.data.model_obj.server_addr ?? "";

console.log(server_addr);
try {
let resp = await fetch(server_addr + "/generate_stream", {
// let resp = await fetch(server_addr + "/generate_stream", {
// headers: {
// "Content-Type": "application/json",
// accesstoken: event.data.jwt,
// },
// method: "POST",
// body: body,
// signal: controller.signal,
// });
let resp = await fetch(server_addr + "/v1/completions", {
headers: {
"Content-Type": "application/json",
accesstoken: event.data.jwt,
// accesstoken: event.data.jwt,
},
method: "POST",
body: body,
signal: controller.signal,
// signal: controller.signal,
});

console.log("response is : ", resp);
if (resp.ok) {
let stream1 = resp.body;
for await (const input of streamToAsyncIterable(stream1)) {
Expand Down

0 comments on commit 323e1d5

Please sign in to comment.