Khrisna commited on
Commit
dcd36fb
·
verified ·
1 Parent(s): c215cc3

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +42 -15
index.js CHANGED
@@ -2,6 +2,7 @@ import express from "express";
2
  import os from "os";
3
  import morgan from "morgan";
4
  import bytes from "bytes";
 
5
  import { FormData, Blob } from "formdata-node";
6
  import { fileTypeFromBuffer } from "file-type";
7
  import { Client } from "@gradio/client";
@@ -134,21 +135,47 @@ async function processImage2Img(imgBuffer, prompt) {
134
 
135
  async function askOpenGPT4o(prompt) {
136
  try {
137
- process.env.GRADIO_CLIENT_DEBUG = 'true';
138
-
139
- const client = await Client.connect("KingNish/OpenGPT-4o");
140
- const result = await client.predict("/chat", {
141
- user_prompt: { text: prompt },
142
- decoding_strategy: "Greedy",
143
- temperature: 0,
144
- max_new_tokens: 2048,
145
- repetition_penalty: 0.01,
146
- top_p: 0.01,
147
- web_search: true,
148
  });
149
- return result.data;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  } catch (error) {
151
- console.error(error);
152
- throw error; // Rethrow the error to allow for better error handling
153
  }
154
- }
 
 
2
  import os from "os";
3
  import morgan from "morgan";
4
  import bytes from "bytes";
5
+ import axios from "axios";
6
  import { FormData, Blob } from "formdata-node";
7
  import { fileTypeFromBuffer } from "file-type";
8
  import { Client } from "@gradio/client";
 
135
 
136
  async function askOpenGPT4o(prompt) {
137
  try {
138
+ const session_hash = Math.random().toString(36).substring(2).slice(1);
139
+
140
+ const resPrompt = await axios.post('https://kingnish-opengpt-4o.hf.space/run/predict?__theme=light', {
141
+ data: [{ text: prompt, files: [] }],
142
+ event_data: null,
143
+ fn_index: 3,
144
+ trigger_id: 34,
145
+ session_hash,
 
 
 
146
  });
147
+
148
+ const res = await axios.post('https://kingnish-opengpt-4o.hf.space/queue/join?__theme=light', {
149
+ data: [
150
+ null,
151
+ null,
152
+ 'idefics2-8b-chatty',
153
+ 'Top P Sampling',
154
+ 0.5,
155
+ 4096,
156
+ 1,
157
+ 0.9,
158
+ true,
159
+ ],
160
+ event_data: null,
161
+ fn_index: 5,
162
+ trigger_id: 34,
163
+ session_hash,
164
+ });
165
+
166
+ const event_ID = res.data.event_id;
167
+
168
+ const anu = await axios.get(`https://kingnish-opengpt-4o.hf.space/queue/data?session_hash=${session_hash}`);
169
+ const lines = anu.data.split('\n');
170
+ const processStartsLine = lines.find(line => line.includes('process_completed'));
171
+
172
+ if (processStartsLine) {
173
+ const processStartsData = JSON.parse(processStartsLine.replace('data: ', ''));
174
+ return processStartsData.output.data[0][0][1];
175
+ }
176
  } catch (error) {
177
+ console.error('Error occurred:', error);
178
+ return `Error: ${error.message}`;
179
  }
180
+ }
181
+