import got from 'got';
import { repairJSON } from '../utils/repairJSON.js';
import { getProxyAgent } from '../utils/proxy.js';
import { toStream } from '../utils/stream.js';

const jsonmode_prompt = 
`ALWAYS RESPOND IN VALID JSON FORMAT, THE SCHEMA MUST BE WHAT THE USER REQUESTED OR IS APPROPRIATE FOR THE REQUEST
`;

const modelMapping = {
   
};

const cabService = {
  async request(e, options) {
    const { messages, tools = [], tool_choice, response_format, model } = options;
    const finalmodel = modelMapping[model];
    
   
    if (response_format?.type === 'json_object') {
      const systemMessageIndex = messages.findIndex((message) => message.role === 'system');
      if (systemMessageIndex !== -1) {
        messages[systemMessageIndex].content = jsonmode_prompt + messages[systemMessageIndex].content;
      } else {
        messages.unshift({ role: 'system', content: jsonmode_prompt });
      }
    }
  //  const proxyAgent = await getProxyAgent();

    try {
      options.messages = messages;
      options.model = finalmodel || options.model;
      const response = await got.post('https://', {
        json: options,
        
      });
      if (options.stream) {
        return toStream(response....);
      } else {
         const body = response.body;
      const message = body.choices[0].message;
      if (response_format?.type === 'json_object') return {"role": "assistant", "content": repairJSON(message.content)};
      return message;
      }
     
    } catch (error) {
    console.log(error.message);
      throw error;
    }
  },
};

export default hfllmService;

Modify the given script to do the following:
first make a request like this, with random hash and the prompt formatted correctly with ai and assistant messages in proper places and current latest message in proper places as given in the following format.
curl 'https://yuntian-deng-o1mini.hf.space/queue/join?__theme=light' \
  -H 'authority: yuntian-deng-o1mini.hf.space' \
  -H 'accept: */*' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'content-type: application/json' \
  -H 'origin: https://yuntian-deng-o1mini.hf.space' \
  -H 'referer: https://yuntian-deng-o1mini.hf.space/?__theme=light' \
  -H 'sec-ch-ua: "Not-A.Brand";v="99", "Chromium";v="124"' \
  -H 'sec-ch-ua-mobile: ?1' \
  -H 'sec-ch-ua-platform: "Android"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: same-origin' \
  -H 'user-agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36' \
  --data-raw $'{"data":["no",1,1,2,[["giiii","Hey there\u0021 😊 How can I help you today?"],["im fine","I\'m glad to hear that\u0021 If you need anything or have any questions, feel free to let me know."]],null],"event_data":null,"fn_index":5,"trigger_id":9,"session_hash":"9u6mfv9y9u"}' \
  --compressed

after that make a request like this to get the ai response from an sse.
curl 'https://yuntian-deng-o1mini.hf.space/queue/data?session_hash=9tu6mfv9y9u' \
  -H 'authority: yuntian-deng-o1mini.hf.space' \
  -H 'accept: text/event-stream' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'content-type: application/json' \
  -H 'referer: https://yuntian-deng-o1mini.hf.space/?__theme=light' \
  -H 'sec-ch-ua: "Not-A.Brand";v="99", "Chromium";v="124"' \
  -H 'sec-ch-ua-mobile: ?1' \
  -H 'sec-ch-ua-platform: "Android"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: same-origin' \
  -H 'user-agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36' \
  --compressed

response format.
data: {"msg":"estimation","event_id":"a53592ce44b04dad8750c5d7c2ee173e","rank":0,"queue_size":1,"rank_eta":18.770373557033754}

data: {"msg":"process_starts","event_id":"a53592ce44b04dad8750c5d7c2ee173e","eta":18.770373557033754}

data: {"msg":"process_generating","event_id":"a53592ce44b04dad8750c5d7c2ee173e","output":{"data":[[["giiii","Hello! 😊 How can I help you today?"]],null,1,"<Response [200]>",{"interactive":false,"__type__":"update"},{"interactive":false,"__type__":"update"}],"is_generating":true,"duration":2.2337851524353027,"average_duration":6.368912881908619,"render_config":null,"changed_state_ids":[]},"success":true}

data: {"msg":"process_generating","event_id":"a53592ce44b04dad8750c5d7c2ee173e","output":{"data":[[],[],[],[],[["replace",["interactive"],true]],[["replace",["interactive"],true]]],"is_generating":true,"duration":0.017965316772460938,"average_duration":6.367190824542801,"render_config":null,"changed_state_ids":[]},"success":true}

data: {"msg":"process_completed","event_id":"a53592ce44b04dad8750c5d7c2ee173e","output":{"data":[[["giiii","Hello! 😊 How can I help you today?"]],null,1,"<Response [200]>",{"interactive":true,"__type__":"update"},{"interactive":true,"__type__":"update"}],"is_generating":false,"duration":0.0005033016204833984,"average_duration":6.365464967258192,"render_config":null,"changed_state_ids":[]},"success":true}

data: {"msg":"close_stream","event_id":null}


parse and get the message from the response if process completed.
 
no is current message, others are message history, get these from the messages array in openai format.