Add better types for `responses`
This commit is contained in:
		
							parent
							
								
									840851a35b
								
							
						
					
					
						commit
						1ca762bcc0
					
				| 
						 | 
				
			
			@ -91,7 +91,7 @@
 | 
			
		|||
        })
 | 
			
		||||
      ).json();
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      response = { error: { message: e.message } };
 | 
			
		||||
      response = { status: "error", error: { message: e.message } };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Hide updating bar
 | 
			
		||||
| 
						 | 
				
			
			@ -113,7 +113,7 @@
 | 
			
		|||
 | 
			
		||||
    const response = await sendRequest(chat.messages);
 | 
			
		||||
 | 
			
		||||
    if (response.error) {
 | 
			
		||||
    if (response.status === "error") {
 | 
			
		||||
      addMessage(chatId, {
 | 
			
		||||
        role: "system",
 | 
			
		||||
        content: `Error: ${response.error.message}`,
 | 
			
		||||
| 
						 | 
				
			
			@ -135,7 +135,7 @@
 | 
			
		|||
 | 
			
		||||
    const response = await sendRequest(chat.messages);
 | 
			
		||||
 | 
			
		||||
    if (response.error) {
 | 
			
		||||
    if (response.status === "error") {
 | 
			
		||||
      addMessage(chatId, {
 | 
			
		||||
        role: "system",
 | 
			
		||||
        content: `Error: ${response.error.message}`,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,28 @@
 | 
			
		|||
    total_tokens: number;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  // TODO: add better type here, for now a generic JSON type
 | 
			
		||||
  export type Response = Record<string, any>;
 | 
			
		||||
  type ResponseOK = {
 | 
			
		||||
    status: "ok";
 | 
			
		||||
    id: string;
 | 
			
		||||
    object: string;
 | 
			
		||||
    created: number;
 | 
			
		||||
    choices: {
 | 
			
		||||
      index: number;
 | 
			
		||||
      message: Message;
 | 
			
		||||
      finish_reason: string;
 | 
			
		||||
    }[];
 | 
			
		||||
    usage: Usage;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  type ResponseError = {
 | 
			
		||||
    status: "error";
 | 
			
		||||
    error: {
 | 
			
		||||
      message: string;
 | 
			
		||||
      type?: string;
 | 
			
		||||
      param?: string | null;
 | 
			
		||||
      code?: string | null;
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  export type Response = ResponseOK | ResponseError;
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue